Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update shippings settings phase 1 #2699

Merged
merged 91 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from 84 commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
28fec06
Update Shipping Table
jorgemd24 Aug 13, 2024
3ea16ba
Create migration class
jorgemd24 Aug 13, 2024
9edf689
Merge pull request #2520 from woocommerce/add/max-time-column-db
jorgemd24 Aug 14, 2024
4ef12ec
Add shipping_rates_count to the settings endpoint
jorgemd24 Aug 14, 2024
c73ccf9
Hide automatic method during onboarding and if shipping methods are 0
jorgemd24 Aug 14, 2024
7702c35
Add default shipping rate flat
jorgemd24 Aug 14, 2024
5b6b038
Add tests for ShippingRateSection
jorgemd24 Aug 14, 2024
3c17297
Add tests for Settings Controller
jorgemd24 Aug 14, 2024
4d90755
Add tests for shipping rates count
jorgemd24 Aug 14, 2024
53d8f4a
Adjust e2e tests
jorgemd24 Aug 14, 2024
c238ba1
Simplify logic condition
jorgemd24 Aug 20, 2024
8f3231f
Remove unsused createInterpolateElement
jorgemd24 Aug 20, 2024
8cbbde7
Merge pull request #2526 from woocommerce/tweak/shipping-adjustments
jorgemd24 Sep 3, 2024
351bec5
Merge branch 'develop' into update/shippings-settings-phase-1
jorgemd24 Sep 5, 2024
f0c904a
Add same day delivery constant
jorgemd24 Sep 5, 2024
3592743
Create stepper button
jorgemd24 Sep 5, 2024
c34fd53
Add max and min inputs
jorgemd24 Sep 5, 2024
f929e7c
Adjust styling
jorgemd24 Sep 5, 2024
ae4c1a8
Adjust max transit time
jorgemd24 Sep 5, 2024
b1f0e58
handle max shipping time
jorgemd24 Sep 5, 2024
c90a624
Add max time to shipping time controllers
jorgemd24 Sep 5, 2024
e1a119b
Allow to update max_time in the db
jorgemd24 Sep 5, 2024
b67ade9
Add tests
jorgemd24 Sep 5, 2024
60083eb
Merge branch 'update/shipping-time-controllers-to-work-with-max-time'…
jorgemd24 Sep 8, 2024
96fb9a3
Remove unsused constant
jorgemd24 Sep 8, 2024
ba3b581
Check if min shipping time is less than max time
jorgemd24 Sep 8, 2024
a730cf8
Refactor code
jorgemd24 Sep 8, 2024
f6f318f
Update add and edit shipping time modals to work with maxTime
jorgemd24 Sep 8, 2024
9dcb9ad
Skip the incomplete shipping time when onboarding
jorgemd24 Sep 8, 2024
1abbf8d
Adjust width input
jorgemd24 Sep 8, 2024
a4ba402
Fix css linting
jorgemd24 Sep 8, 2024
95d635e
update checkError tests
jorgemd24 Sep 8, 2024
6bc62b9
Add CountriesTimeInput tests
jorgemd24 Sep 8, 2024
f61977d
Add tests for shipping stepper
jorgemd24 Sep 8, 2024
bfea9b0
Validate shippimg time args
jorgemd24 Sep 12, 2024
af40ca3
Add tests
jorgemd24 Sep 12, 2024
200358a
Merge branch 'update/shipping-time-controllers-to-work-with-max-time'…
jorgemd24 Sep 12, 2024
b72fe81
Update error description
jorgemd24 Sep 12, 2024
61d9b99
Add tests for min and max time
jorgemd24 Sep 12, 2024
0f3b1b0
fix js linting
jorgemd24 Sep 12, 2024
8ffaa67
Merge pull request #2590 from woocommerce/update/shipping-time-contro…
jorgemd24 Sep 15, 2024
e4686c5
Remove unnecessary statement as the schema already requires time and …
jorgemd24 Sep 15, 2024
f218b47
Fix issue with the orignal value
jorgemd24 Sep 15, 2024
681400c
Add stepper to add time button
jorgemd24 Sep 15, 2024
816a9d6
Add edit time stepper in appmodal
jorgemd24 Sep 15, 2024
5929800
Add css
jorgemd24 Sep 15, 2024
7502fe7
remove unused property
jorgemd24 Sep 15, 2024
6a31818
replace deprecated property with size
jorgemd24 Sep 15, 2024
e1aa24b
Merge branch 'add/min-max-time-inputs' into update/add-and-edit-shipp…
jorgemd24 Sep 16, 2024
9d3c7d9
Create MinMaxShippingTimes component
jorgemd24 Sep 16, 2024
5acf209
Refactor add and edit modals to use the min max component
jorgemd24 Sep 16, 2024
23f5a43
simplify handleblur
jorgemd24 Sep 16, 2024
d901a06
Refactor countries time input to use the MinMax shipping times
jorgemd24 Sep 16, 2024
5e53a38
Adjust styling
jorgemd24 Sep 16, 2024
6cbafed
Add tests for AddTimeModal
jorgemd24 Sep 16, 2024
f83921e
Add tests for EditTimeModal
jorgemd24 Sep 16, 2024
3b2b724
Fix linting
jorgemd24 Sep 16, 2024
cd67ca0
Merge pull request #2594 from woocommerce/add/min-max-time-inputs
jorgemd24 Sep 16, 2024
f964629
Show errors in add time modal
jorgemd24 Sep 17, 2024
3c32ea6
Show errors in edit modal
jorgemd24 Sep 17, 2024
e487f6a
Adjust validateShippingTime
jorgemd24 Sep 17, 2024
8652d24
Only update the value if the shipping time is between the min and max…
jorgemd24 Sep 17, 2024
5a9db1a
Adjust e2e tests for min and max shipping times
jorgemd24 Sep 18, 2024
2be12ab
Fix issue with variable height in edit and add modal
jorgemd24 Sep 22, 2024
57b81c6
Add delay before saving
jorgemd24 Sep 22, 2024
c5e4dc3
Adjust tests
jorgemd24 Sep 22, 2024
d23fcd9
Merge pull request #2609 from woocommerce/update/add-and-edit-shippin…
jorgemd24 Sep 24, 2024
7111c6c
Merge pull request #2619 from woocommerce/tweak/e2e-tests-for-min-max…
jorgemd24 Sep 24, 2024
c286067
Merge branch 'develop' into update/shippings-settings-phase-1
jorgemd24 Sep 25, 2024
838b881
Merge branch 'develop' into update/shippings-settings-phase-1
ianlin Nov 11, 2024
f88f989
Merge branch 'develop' into update/shippings-settings-phase-1
ianlin Nov 15, 2024
5026d48
Create order value condition section and card's structure
ianlin Nov 18, 2024
90562c8
Implement new UI for free shipping order value condition
ianlin Nov 22, 2024
b409867
Add mocks on adaptive form context functions for minumum order card
ianlin Nov 22, 2024
8daed93
Remove a mistyped `;`
ianlin Nov 22, 2024
3857f5a
Add tests for free shipping order value condition
ianlin Nov 22, 2024
5d5c8f2
Merge branch 'develop' into update/shippings-settings-phase-1
ianlin Nov 25, 2024
642ce6e
Merge branch 'update/shippings-settings-phase-1' into add/order-value…
ianlin Nov 25, 2024
5efbc56
Remove the validation on offer_free_shipping
ianlin Nov 28, 2024
bed1e5a
Return null for minimum order input component instead of changing styles
ianlin Nov 29, 2024
7c9ec43
Merge pull request #2686 from woocommerce/add/order-value-condition-f…
ianlin Nov 29, 2024
1129d1f
Merge branch 'develop' into update/shippings-settings-phase-1
ianlin Nov 29, 2024
5a21a38
Fix PHPCS
ianlin Nov 29, 2024
d58478b
Fix PHP test
ianlin Nov 29, 2024
6b64ae7
Fix e2e tests for free shipping order value condition
ianlin Dec 2, 2024
c1dffd3
Remove ".only" for a e2e test
ianlin Dec 2, 2024
e15c24e
Remove unnecessary styles
ianlin Dec 2, 2024
3e9a758
Fix identation chars in the comment
ianlin Dec 2, 2024
722190e
Add max shipping time type definiation
ianlin Dec 2, 2024
855f284
Add max shipping time type definiation
ianlin Dec 2, 2024
48fb03c
Merge branch 'develop' into update/shippings-settings-phase-1
eason9487 Dec 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions js/src/components/adaptive-form/adaptive-form-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,20 @@

return adaptiveFormContext;
}

/**
* AdaptiveForm's input props hook.
*
* @param {string} key Key of the form value.
* @param {string} [validationKey=key] Key of the form value to be used for validation.
*
* @return {Object} Props for an adaptive form input.
*/
export function useAdaptiveFormInputProps( key, validationKey = key ) {
const { getInputProps, adapter } = useAdaptiveFormContext();

Check warning on line 76 in js/src/components/adaptive-form/adaptive-form-context.js

View check run for this annotation

Codecov / codecov/patch

js/src/components/adaptive-form/adaptive-form-context.js#L75-L76

Added lines #L75 - L76 were not covered by tests

return {

Check warning on line 78 in js/src/components/adaptive-form/adaptive-form-context.js

View check run for this annotation

Codecov / codecov/patch

js/src/components/adaptive-form/adaptive-form-context.js#L78

Added line #L78 was not covered by tests
...getInputProps( key ),
helper: adapter.renderRequestedValidation( validationKey ),
};
}
5 changes: 4 additions & 1 deletion js/src/components/adaptive-form/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
export { default } from './adaptive-form';
export { useAdaptiveFormContext } from './adaptive-form-context';
export {
useAdaptiveFormContext,
useAdaptiveFormInputProps,
} from './adaptive-form-context';
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,15 @@ exports[`checkErrors Shipping rates When the type of shipping rate is an invalid

exports[`checkErrors Shipping rates When the type of shipping rate is an invalid value or missing, should not pass 3`] = `"Please select a shipping rate option."`;

exports[`checkErrors Shipping times For flat type When minimum max_time is < 0, should not pass 1`] = `"The minimum shipping time must not be more than the maximum shipping time."`;

exports[`checkErrors Shipping times For flat type When minimum times is < 0, should not pass 1`] = `"Please specify estimated shipping times for all the countries, and the time cannot be less than 0."`;

exports[`checkErrors Shipping times For flat type When there are any selected countries' shipping times is not set, should not pass 1`] = `"Please specify estimated shipping times for all the countries, and the time cannot be less than 0."`;

exports[`checkErrors Shipping times For flat type When there are any shipping times is < 0, should not pass 1`] = `"Please specify estimated shipping times for all the countries, and the time cannot be less than 0."`;
exports[`checkErrors Shipping times For flat type When there are any shipping times are < 0, should not pass 1`] = `"Please specify estimated shipping times for all the countries, and the time cannot be less than 0."`;

exports[`checkErrors Shipping times For flat type shouldnt pass if min time is bigger than max time 1`] = `"The minimum shipping time must not be more than the maximum shipping time."`;

exports[`checkErrors Shipping times When the type of shipping time is an invalid value or missing, should not pass 1`] = `"Please select a shipping time option."`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
*/
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import isNonFreeShippingRate from '.~/utils/isNonFreeShippingRate';

const validlocationSet = new Set( [ 'all', 'selected' ] );
const validShippingRateSet = new Set( [ 'automatic', 'flat', 'manual' ] );
const validShippingTimeSet = new Set( [ 'flat', 'manual' ] );
Expand Down Expand Up @@ -62,16 +57,6 @@ const checkErrors = (
* Check offer free shipping, only when shipping_rate is 'flat'.
*/
if ( values.shipping_rate === 'flat' ) {
if (
values.offer_free_shipping === undefined &&
values.shipping_country_rates.some( isNonFreeShippingRate )
) {
errors.offer_free_shipping = __(
'Please select an option for whether to offer free shipping.',
'google-listings-and-ads'
);
}

if (
values.offer_free_shipping === true &&
values.shipping_country_rates.every(
Expand Down Expand Up @@ -99,14 +84,24 @@ const checkErrors = (
if (
values.shipping_time === 'flat' &&
( shippingTimes.length < finalCountryCodes.length ||
shippingTimes.some( ( el ) => el.time < 0 ) )
shippingTimes.some( ( el ) => el.time < 0 || el.maxTime < 0 ) )
) {
errors.shipping_country_times = __(
'Please specify estimated shipping times for all the countries, and the time cannot be less than 0.',
'google-listings-and-ads'
);
}

if (
values.shipping_time === 'flat' &&
shippingTimes.some( ( el ) => el.time > el.maxTime )
) {
errors.shipping_country_times = __(
'The minimum shipping time must not be more than the maximum shipping time.',
'google-listings-and-ads'
);
}

/**
* Check tax rate (required for U.S. only).
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ function toRates( ...tuples ) {
}

function toTimes( ...tuples ) {
return tuples.map( ( [ countryCode, time ] ) => ( {
return tuples.map( ( [ countryCode, time, maxTime ] ) => ( {
countryCode,
time,
maxTime,
} ) );
}

Expand All @@ -44,7 +45,7 @@ describe( 'checkErrors', () => {
shipping_country_rates: toRates( [ 'US', 10 ], [ 'JP', 30, 88 ] ),
offer_free_shipping: true,
};
const times = toTimes( [ 'US', 3 ], [ 'JP', 10 ] );
const times = toTimes( [ 'US', 3, 3 ], [ 'JP', 10, 10 ] );
const codes = [ 'US', 'JP' ];

const errors = checkErrors( values, times, codes );
Expand Down Expand Up @@ -252,20 +253,6 @@ describe( 'checkErrors', () => {
expect( errors ).not.toHaveProperty( 'offer_free_shipping' );
} );

it( 'When there are some non-free shipping rates, and offer free shipping is unchecked, should not pass', () => {
const values = {
...defaultFormValues,
shipping_rate: 'flat',
shipping_country_rates: toRates( [ 'US', 0 ], [ 'JP', 1 ] ),
offer_free_shipping: undefined,
};
const codes = [ 'US', 'JP' ];

const errors = checkErrors( values, [], codes );

expect( errors ).toHaveProperty( 'offer_free_shipping' );
} );

it( 'When there are some non-free shipping rates, and offer free shipping is checked, and there is minimum order amount for non-free shipping rates, should pass', () => {
const values = {
...defaultFormValues,
Expand Down Expand Up @@ -381,7 +368,7 @@ describe( 'checkErrors', () => {

describe( 'For flat type', () => {
it( `When there are any selected countries' shipping times is not set, should not pass`, () => {
const times = toTimes( [ 'US', 7 ], [ 'FR', 16 ] );
const times = toTimes( [ 'US', 7, 7 ], [ 'FR', 16, 16 ] );
const codes = [ 'US', 'JP', 'FR' ];

const errors = checkErrors( flatShipping, times, codes );
Expand All @@ -391,16 +378,36 @@ describe( 'checkErrors', () => {
} );

it( `When all selected countries' shipping times are set, should pass`, () => {
const times = toTimes( [ 'US', 7 ], [ 'FR', 16 ] );
const times = toTimes( [ 'US', 7, 7 ], [ 'FR', 16, 16 ] );
const codes = [ 'US', 'FR' ];

const errors = checkErrors( flatShipping, times, codes );

expect( errors ).not.toHaveProperty( 'shipping_time' );
} );

it( `When there are any shipping times is < 0, should not pass`, () => {
const times = toTimes( [ 'US', 10 ], [ 'JP', -1 ] );
it( `When there are any shipping times are < 0, should not pass`, () => {
const times = toTimes( [ 'US', 10, 10 ], [ 'JP', -1, -1 ] );
const codes = [ 'US', 'JP' ];

const errors = checkErrors( flatShipping, times, codes );

expect( errors ).toHaveProperty( 'shipping_country_times' );
expect( errors.shipping_country_times ).toMatchSnapshot();
} );

it( `When minimum times is < 0, should not pass`, () => {
const times = toTimes( [ 'US', 10, 10 ], [ 'JP', -1, 10 ] );
const codes = [ 'US', 'JP' ];

const errors = checkErrors( flatShipping, times, codes );

expect( errors ).toHaveProperty( 'shipping_country_times' );
expect( errors.shipping_country_times ).toMatchSnapshot();
} );

it( `When minimum max_time is < 0, should not pass`, () => {
const times = toTimes( [ 'US', 10, 10 ], [ 'JP', 1, -10 ] );
const codes = [ 'US', 'JP' ];

const errors = checkErrors( flatShipping, times, codes );
Expand All @@ -410,13 +417,23 @@ describe( 'checkErrors', () => {
} );

it( `When all shipping times are ≥ 0, should pass`, () => {
const times = toTimes( [ 'US', 1 ], [ 'JP', 0 ] );
const times = toTimes( [ 'US', 1, 1 ], [ 'JP', 0, 0 ] );
const codes = [ 'US', 'JP' ];

const errors = checkErrors( flatShipping, times, codes );

expect( errors ).not.toHaveProperty( 'shipping_time' );
} );

it( `shouldnt pass if min time is bigger than max time`, () => {
const times = toTimes( [ 'US', 1, 0 ], [ 'JP', 1, 1 ] );
const codes = [ 'US', 'JP' ];

const errors = checkErrors( flatShipping, times, codes );

expect( errors ).toHaveProperty( 'shipping_country_times' );
expect( errors.shipping_country_times ).toMatchSnapshot();
} );
} );
} );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@
import { useState } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { Form } from '@woocommerce/components';
import { Flex, FlexItem } from '@wordpress/components';

/**
* Internal dependencies
*/
import AppButton from '.~/components/app-button';
import AppModal from '.~/components/app-modal';
import AppInputNumberControl from '.~/components/app-input-number-control';
import VerticalGapLayout from '.~/components/vertical-gap-layout';
import SupportedCountrySelect from '.~/components/supported-country-select';
import validateShippingTimeGroup from '.~/utils/validateShippingTimeGroup';
import MinMaxShippingTimes from '../../min-max-inputs';
import './index.scss';

/**
* Form to add a new time for selected country(-ies).
Expand All @@ -36,12 +38,18 @@ const AddTimeModal = ( { countries, onRequestClose, onSubmit } ) => {
initialValues={ {
countries,
time: 0,
maxTime: 0,
} }
validate={ validateShippingTimeGroup }
onSubmit={ handleSubmitCallback }
>
{ ( formProps ) => {
const { getInputProps, isValidForm, handleSubmit } = formProps;
const { getInputProps, isValidForm, handleSubmit, errors } =
formProps;

const handleIncrement = ( numberValue, field ) => {
getInputProps( field ).onChange( numberValue );
};

return (
<AppModal
Expand All @@ -66,6 +74,7 @@ const AddTimeModal = ( { countries, onRequestClose, onSubmit } ) => {
</AppButton>,
] }
onRequestClose={ onRequestClose }
className="gla-add-time-modal"
>
<VerticalGapLayout>
<SupportedCountrySelect
Expand All @@ -79,17 +88,31 @@ const AddTimeModal = ( { countries, onRequestClose, onSubmit } ) => {
}
{ ...getInputProps( 'countries' ) }
/>
<AppInputNumberControl
label={ __(
'Then the estimated shipping time displayed in the product listing is',
'google-listings-and-ads'
) }
suffix={ __(
'days',
<div className="label">
{ __(
'Then the estimated shipping times displayed in the product listing are:',
'google-listings-and-ads'
) }
{ ...getInputProps( 'time' ) }
/>
</div>
<Flex
direction="column"
className="gla-countries-time-input-container"
>
<FlexItem>
<MinMaxShippingTimes
time={ getInputProps( 'time' ).value }
maxTime={
getInputProps( 'maxTime' ).value
}
handleBlur={ handleIncrement }
handleIncrement={ handleIncrement }
/>

<ul className="gla-validation-errors">
<li>{ errors.time }</li>
</ul>
</FlexItem>
</Flex>
</VerticalGapLayout>
</AppModal>
);
Expand Down
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;
}
eason9487 marked this conversation as resolved.
Show resolved Hide resolved
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,
} );
} );
} );
Loading
Loading