-
Notifications
You must be signed in to change notification settings - Fork 21
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
Adjust auto-sync shipping option #2526
Merged
jorgemd24
merged 9 commits into
update/shippings-settings-phase-1
from
tweak/shipping-adjustments
Sep 3, 2024
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4ef12ec
Add shipping_rates_count to the settings endpoint
jorgemd24 c73ccf9
Hide automatic method during onboarding and if shipping methods are 0
jorgemd24 7702c35
Add default shipping rate flat
jorgemd24 5b6b038
Add tests for ShippingRateSection
jorgemd24 3c17297
Add tests for Settings Controller
jorgemd24 4d90755
Add tests for shipping rates count
jorgemd24 53d8f4a
Adjust e2e tests
jorgemd24 c238ba1
Simplify logic condition
jorgemd24 8f3231f
Remove unsused createInterpolateElement
jorgemd24 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
211 changes: 211 additions & 0 deletions
211
js/src/components/shipping-rate-section/shipping-rate-section.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,211 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import '@testing-library/jest-dom'; | ||
import { render } from '@testing-library/react'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import useSettings from '.~/components/free-listings/configure-product-listings/useSettings'; | ||
import useMCSetup from '.~/hooks/useMCSetup'; | ||
import ShippingRateSection from './shipping-rate-section'; | ||
//import FlatShippingRatesInputCards from './flat-shipping-rates-input-cards'; | ||
|
||
jest.mock( './flat-shipping-rates-input-cards', () => () => <></> ); | ||
|
||
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, | ||
}, | ||
}; | ||
} ), | ||
} ) ); | ||
|
||
jest.mock( | ||
'.~/components/free-listings/configure-product-listings/useSettings' | ||
); | ||
jest.mock( '.~/hooks/useMCSetup' ); | ||
|
||
describe( 'ShippingRateSection', () => { | ||
it( 'shouldnt render automatic rates if there are not shipping rates and it is onboarding', () => { | ||
useMCSetup.mockImplementation( () => { | ||
return { | ||
hasFinishedResolution: true, | ||
data: { | ||
status: 'incomplete', | ||
}, | ||
}; | ||
} ); | ||
|
||
useSettings.mockImplementation( () => { | ||
return { | ||
settings: { | ||
shipping_rates_count: 0, | ||
}, | ||
}; | ||
} ); | ||
|
||
const { getByText, queryByRole } = render( <ShippingRateSection /> ); | ||
|
||
expect( | ||
getByText( | ||
'My shipping settings are simple. I can manually estimate flat shipping rates.' | ||
) | ||
).toBeInTheDocument(); | ||
|
||
expect( | ||
getByText( | ||
'My shipping settings are complex. I will enter my shipping rates and times manually in Google Merchant Center.' | ||
) | ||
).toBeInTheDocument(); | ||
|
||
expect( | ||
queryByRole( | ||
'Automatically sync my store’s shipping settings to Google.' | ||
) | ||
).not.toBeInTheDocument(); | ||
} ); | ||
|
||
it( 'should render automatic rates if there are shipping rates and it is onboarding', () => { | ||
useMCSetup.mockImplementation( () => { | ||
return { | ||
hasFinishedResolution: true, | ||
data: { | ||
status: 'incomplete', | ||
}, | ||
}; | ||
} ); | ||
|
||
useSettings.mockImplementation( () => { | ||
return { | ||
settings: { | ||
shipping_rates_count: 1, | ||
}, | ||
}; | ||
} ); | ||
|
||
const { getByText } = render( <ShippingRateSection /> ); | ||
|
||
expect( | ||
getByText( | ||
'My shipping settings are simple. I can manually estimate flat shipping rates.' | ||
) | ||
).toBeInTheDocument(); | ||
|
||
expect( | ||
getByText( | ||
'My shipping settings are complex. I will enter my shipping rates and times manually in Google Merchant Center.' | ||
) | ||
).toBeInTheDocument(); | ||
|
||
expect( | ||
getByText( | ||
'Automatically sync my store’s shipping settings to Google.' | ||
) | ||
).toBeInTheDocument(); | ||
} ); | ||
|
||
it( 'should render automatic rates if there are not shipping rates and it is not onboarding', () => { | ||
useMCSetup.mockImplementation( () => { | ||
return { | ||
hasFinishedResolution: true, | ||
data: { | ||
status: 'completed', | ||
}, | ||
}; | ||
} ); | ||
|
||
useSettings.mockImplementation( () => { | ||
return { | ||
settings: { | ||
shipping_rates_count: 0, | ||
}, | ||
}; | ||
} ); | ||
|
||
const { getByText } = render( <ShippingRateSection /> ); | ||
|
||
expect( | ||
getByText( | ||
'My shipping settings are simple. I can manually estimate flat shipping rates.' | ||
) | ||
).toBeInTheDocument(); | ||
|
||
expect( | ||
getByText( | ||
'My shipping settings are complex. I will enter my shipping rates and times manually in Google Merchant Center.' | ||
) | ||
).toBeInTheDocument(); | ||
|
||
expect( | ||
getByText( | ||
'Automatically sync my store’s shipping settings to Google.' | ||
) | ||
).toBeInTheDocument(); | ||
} ); | ||
|
||
it( 'should render automatic rates if there are shipping rates and it is not onboarding', () => { | ||
useMCSetup.mockImplementation( () => { | ||
return { | ||
hasFinishedResolution: true, | ||
data: { | ||
status: 'completed', | ||
}, | ||
}; | ||
} ); | ||
|
||
useSettings.mockImplementation( () => { | ||
return { | ||
settings: { | ||
shipping_rates_count: 1, | ||
}, | ||
}; | ||
} ); | ||
|
||
const { getByText } = render( <ShippingRateSection /> ); | ||
|
||
expect( | ||
getByText( | ||
'My shipping settings are simple. I can manually estimate flat shipping rates.' | ||
) | ||
).toBeInTheDocument(); | ||
|
||
expect( | ||
getByText( | ||
'My shipping settings are complex. I will enter my shipping rates and times manually in Google Merchant Center.' | ||
) | ||
).toBeInTheDocument(); | ||
|
||
expect( | ||
getByText( | ||
'Automatically sync my store’s shipping settings to Google.' | ||
) | ||
).toBeInTheDocument(); | ||
} ); | ||
} ); |
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
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
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added this so it skips only view properties; otherwise, it would save them as options, like the
shipping_rates_count
property.