Skip to content

Commit

Permalink
Add mocks on adaptive form context functions for minumum order card
Browse files Browse the repository at this point in the history
Because we've moved minimum order card from folder

js/src/components/shipping-rate-section to
js/src/components/order-value-condition-section

Previously the mock was added in
js/src/components/shipping-rate-section/shipping-rate-section.test.js
  • Loading branch information
ianlin committed Nov 22, 2024
1 parent 90562c8 commit b409867
Showing 1 changed file with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,53 @@ jest.mock( '.~/hooks/useAppSelectDispatch' );
jest.mock( '.~/hooks/useCountryKeyNameMap' );
jest.mock( '.~/hooks/useStoreCurrency' );

jest.mock( '.~/components/adaptive-form', () => ( {
useAdaptiveFormContext: jest
.fn()
.mockName( 'useAdaptiveFormContext' )
.mockImplementation( () => {
return {
getInputProps: () => {
return {
checked: true,
className: '',
help: null,
onBlur: () => {},
onChange: () => {},
selected: 'flat',
value: 'flat',
};
},
values: {
countries: [ 'ES' ],
language: 'English',
locale: 'en_US',
location: 'selected',
offer_free_shipping: false,
shipping_country_rates: [],
shipping_country_times: [],
shipping_rate: 'flat',
shipping_time: 'flat',
tax_rate: null,
},
};
} ),
useAdaptiveFormInputProps: jest
.fn()
.mockName( 'useAdaptiveFormInputProps' )
.mockImplementation( () => {
return {
checked: true,
className: '',
help: null,
onBlur: () => {},
onChange: () => {},
selected: 'flat',
value: 'flat',
};
} ),
} ) );

describe( 'MinimumOrderCard', () => {
describe( 'onChange callback property', () => {
let value, onChange, rendered;
Expand Down Expand Up @@ -78,6 +125,7 @@ describe( 'MinimumOrderCard', () => {
expectedValue[ 0 ].options.free_shipping_threshold = 30;
expect( onChange ).toHaveBeenCalledWith( expectedValue );
} );

test( 'When a minimum order value is changed for an existing group, calls the `onChange` callback with the new value containing `shippingRate.options.free_shipping_threshold`s set to the given value', async () => {
const user = userEvent.setup();

Expand Down

0 comments on commit b409867

Please sign in to comment.