-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Improve billing information loading state #99149
base: trunk
Are you sure you want to change the base?
Conversation
Jetpack Cloud live (direct link)
Automattic for Agencies live (direct link)
|
Here is how your PR affects size of JS and CSS bundles shipped to the user's browser: Sections (~66 bytes added 📈 [gzipped])
Sections contain code specific for a given set of routes. Is downloaded and parsed only when a particular route is navigated to. Async-loaded Components (~66 bytes added 📈 [gzipped])
React components that are loaded lazily, when a certain part of UI is displayed for the first time. Legend What is parsed and gzip size?Parsed Size: Uncompressed size of the JS and CSS files. This much code needs to be parsed and stored in memory. Generated by performance advisor bot at iscalypsofastyet.com. |
@sirbrillig What do you think about this approach? Additionally, I was able to fix many of the tests by mocking I didn't have much success figuring out why but it appears to be something wrong with the mock. You may have more experience here, so wondering if you can think of anything relevant. |
03fba43
to
7f9b167
Compare
This PR modifies the release build for the following Calypso Apps: For info about this notification, see here: PCYsg-OT6-p2
To test WordPress.com changes, run |
I'll take a look tomorrow. 👍 |
Thanks! Looking at the broken tests, mocking The alternative would be to update all the tests that don't properly wait for |
@@ -39,6 +39,9 @@ jest.mock( 'calypso/my-sites/checkout/use-cart-key' ); | |||
jest.mock( 'calypso/lib/analytics/utils/refresh-country-code-cookie-gdpr' ); | |||
jest.mock( 'calypso/state/products-list/selectors/is-marketplace-product' ); | |||
jest.mock( 'calypso/lib/navigate' ); | |||
jest.mock( '../hooks/use-prefill-checkout-contact-form', () => ( { |
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 think rather than mocking the hook's behavior, you can just let the hook do its normal job and rely on mocking the endpoint that returns the cached contact details (and the countries list) like we do here:
wp-calypso/client/my-sites/checkout/src/test/use-prefill-checkout-contact-form.tsx
Lines 133 to 137 in 7f9b167
mockGetSupportedCountriesEndpoint( countryList ); | |
mockCachedContactDetailsEndpoint( { | |
country_code: countryCode, | |
postal_code: postalCode, | |
} ); |
As long as your expectations await or use findBy...
methods, then the contact form should show when the data has arrived and the form is populated.
In fact, we already do that in some of these tests like here:
wp-calypso/client/my-sites/checkout/src/test/checkout-vat-form.tsx
Lines 167 to 180 in 7f9b167
nock.cleanAll(); | |
mockGetSupportedCountriesEndpoint( countryList ); | |
mockGetPaymentMethodsEndpoint( [] ); | |
mockCachedContactDetailsEndpoint( { | |
country_code: 'GB', | |
postal_code: '', | |
} ); | |
mockContactDetailsValidationEndpoint( 'tax', { success: false, messages: [ 'Invalid' ] } ); | |
mockGetVatInfoEndpoint( { | |
id: '12345', | |
name: 'Test company', | |
address: '123 Main Street', | |
country: 'GB', | |
} ); |
If I do the following, then the first VAT test passes (I don't know if all this is required; I just copied and pasted from below):
--- a/client/my-sites/checkout/src/test/checkout-vat-form.tsx
+++ b/client/my-sites/checkout/src/test/checkout-vat-form.tsx
@@ -40,10 +40,6 @@ jest.mock( 'calypso/my-sites/checkout/use-cart-key' );
jest.mock( 'calypso/lib/analytics/utils/refresh-country-code-cookie-gdpr' );
jest.mock( 'calypso/state/products-list/selectors/is-marketplace-product' );
jest.mock( 'calypso/lib/navigate' );
-jest.mock( '../hooks/use-prefill-checkout-contact-form', () => ( {
- ...jest.requireActual( '../hooks/use-prefill-checkout-contact-form' ), // Spread the real module to keep other functions intact
- usePrefillCheckoutContactForm: jest.fn().mockReturnValue( true ),
-} ) );
// These tests seem to be particularly slow (it might be because of using
// it.each; it's not clear but the timeout might apply to the whole loop
@@ -86,6 +82,21 @@ describe( 'Checkout contact step VAT form', () => {
} );
it( 'does not render the VAT field checkbox if the selected country does not support VAT', async () => {
+ nock.cleanAll();
+ mockGetSupportedCountriesEndpoint( countryList );
+ mockGetPaymentMethodsEndpoint( [] );
+ mockCachedContactDetailsEndpoint( {
+ country_code: 'GB',
+ postal_code: '',
+ } );
+ mockContactDetailsValidationEndpoint( 'tax', { success: false, messages: [ 'Invalid' ] } );
+ mockGetVatInfoEndpoint( {
+ id: '12345',
+ name: 'Test company',
+ address: '123 Main Street',
+ country: 'GB',
+ } );
+
const user = userEvent.setup();
const cartChanges = { products: [ planWithoutDomain ] };
render( <MockCheckout { ...defaultPropsForMockCheckout } cartChanges={ cartChanges } />, {
The above technique should also allow you to write a test to prove that this change works.
This reverts commit 7f9b167.
Related to #98527
Proposed Changes
This PR updates the "Billing Information" loading state to reduce the number of visual changes that occur on cart load.
It does so by doing two things:
useCachedContactDetailsForCheckoutForm
to determine when the prefill action has been completed and display a loading string in the meantime.<button>
element .Before
(Throttling Chrome Slow 4G)
trim_0F6j2M.mp4
After
(Throttling Chrome Slow 4G)
trim_I0sXHB.mp4
Why are these changes being made?
As described in #98527, there are multiple different loading states on cart load. This is a distracting experience.
Considerations
I go into more detail about things I tried in the original issue. I tried a few other things, like calling the domain contact endpoint earlier on page load. That didn't have much of an effect. The visual state was more or less unchanged.
Loading it synchronously is the most logical way to remove these intermediate states or maybe have a lazy load system for users who don't start their session on the checkout page. Regardless, I agree with @sirbrillig that keeping it simple is probably the win.
Testing Instructions
Pre-merge Checklist