-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2609 from woocommerce/update/add-and-edit-shippin…
…g-time-inputs Update Add/Edit Shipping Time Modals to support minimum and maximum shipping times stepper
- Loading branch information
Showing
13 changed files
with
330 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
...duct-listings/shipping-time/shipping-time-setup/add-time-button/add-time-modal/index.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.gla-add-time-modal .gla-countries-time-stepper .components-input-control { | ||
margin-bottom: 0; | ||
} |
76 changes: 76 additions & 0 deletions
76
...t-listings/shipping-time/shipping-time-setup/add-time-button/add-time-modal/index.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import '@testing-library/jest-dom'; | ||
import { render, fireEvent, waitFor } from '@testing-library/react'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import AddTimeModal from './index'; | ||
import useMCCountryTreeOptions from '.~/components/supported-country-select/useMCCountryTreeOptions'; | ||
|
||
jest.mock( '.~/components/supported-country-select/useMCCountryTreeOptions' ); | ||
|
||
describe( 'Add time Modal', () => { | ||
it( 'The min and max shipping time inputs should be displayed, and both values should be submitted', async () => { | ||
const onSubmit = jest.fn(); | ||
|
||
useMCCountryTreeOptions.mockImplementation( () => { | ||
return [ | ||
{ | ||
value: 'EU', | ||
label: 'Europe', | ||
children: [ | ||
{ | ||
value: 'ES', | ||
label: 'Spain', | ||
parent: 'EU', | ||
}, | ||
], | ||
}, | ||
]; | ||
} ); | ||
|
||
const { getByRole, getAllByRole } = render( | ||
<AddTimeModal | ||
countries={ [ 'ES' ] } | ||
onRequestClose={ jest.fn() } | ||
onSubmit={ onSubmit } | ||
/> | ||
); | ||
|
||
const inputs = getAllByRole( 'textbox' ); | ||
// it should render 2 inputs ( the min and max shipping time inputs ) | ||
expect( inputs ).toHaveLength( 2 ); | ||
|
||
const [ minInput, maxInput ] = inputs; | ||
|
||
expect( minInput ).toHaveValue( '' ); | ||
expect( maxInput ).toHaveValue( '' ); | ||
|
||
fireEvent.blur( minInput, { target: { value: '2' } } ); | ||
expect( minInput ).toHaveValue( '2' ); | ||
|
||
fireEvent.blur( maxInput, { target: { value: '11' } } ); | ||
expect( maxInput ).toHaveValue( '11' ); | ||
|
||
const submitButton = getByRole( 'button', { | ||
name: 'Add shipping time', | ||
} ); | ||
|
||
expect( submitButton ).toBeEnabled(); | ||
|
||
fireEvent.click( submitButton ); | ||
|
||
await waitFor( () => { | ||
expect( onSubmit ).toHaveBeenCalledTimes( 1 ); | ||
} ); | ||
|
||
expect( onSubmit ).toHaveBeenCalledWith( { | ||
countries: [ 'ES' ], | ||
time: 2, | ||
maxTime: 11, | ||
} ); | ||
} ); | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
...e/shipping-time-setup/countries-time-input/edit-time-button/edit-time-modal/index.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import '@testing-library/jest-dom'; | ||
import { render, fireEvent, waitFor } from '@testing-library/react'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import EditTimeModal from './index'; | ||
import useMCCountryTreeOptions from '.~/components/supported-country-select/useMCCountryTreeOptions'; | ||
|
||
jest.mock( '.~/components/supported-country-select/useMCCountryTreeOptions' ); | ||
|
||
describe( 'Edit time Modal', () => { | ||
it( 'The min and max shipping time inputs should be displayed, and both values should be submitted', async () => { | ||
const onSubmit = jest.fn(); | ||
|
||
useMCCountryTreeOptions.mockImplementation( () => { | ||
return [ | ||
{ | ||
value: 'EU', | ||
label: 'Europe', | ||
children: [ | ||
{ | ||
value: 'ES', | ||
label: 'Spain', | ||
parent: 'EU', | ||
}, | ||
], | ||
}, | ||
]; | ||
} ); | ||
|
||
const { getByRole, getAllByRole } = render( | ||
<EditTimeModal | ||
audienceCountries={ [ 'ES' ] } | ||
time={ { countries: [ 'ES' ], time: 1, maxTime: 9 } } | ||
onRequestClose={ jest.fn() } | ||
onSubmit={ onSubmit } | ||
onDelete={ jest.fn() } | ||
/> | ||
); | ||
|
||
const inputs = getAllByRole( 'textbox' ); | ||
// it should render 2 inputs ( the min and max shipping time inputs ) | ||
expect( inputs ).toHaveLength( 2 ); | ||
|
||
const [ minInput, maxInput ] = inputs; | ||
|
||
expect( minInput ).toHaveValue( '1' ); | ||
expect( maxInput ).toHaveValue( '9' ); | ||
|
||
fireEvent.blur( minInput, { target: { value: '2' } } ); | ||
expect( minInput ).toHaveValue( '2' ); | ||
|
||
fireEvent.blur( maxInput, { target: { value: '11' } } ); | ||
expect( maxInput ).toHaveValue( '11' ); | ||
|
||
const submitButton = getByRole( 'button', { | ||
name: 'Update shipping time', | ||
} ); | ||
|
||
expect( submitButton ).toBeEnabled(); | ||
|
||
fireEvent.click( submitButton ); | ||
|
||
await waitFor( () => { | ||
expect( onSubmit ).toHaveBeenCalledTimes( 1 ); | ||
} ); | ||
|
||
expect( onSubmit ).toHaveBeenCalledWith( | ||
{ countries: [ 'ES' ], time: 2, maxTime: 11 }, | ||
[] | ||
); | ||
} ); | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,7 @@ | |
padding: 0; | ||
} | ||
} | ||
|
||
.gla-edit-time-modal .gla-countries-time-stepper .components-input-control { | ||
margin-bottom: 0; | ||
} |
Oops, something went wrong.