-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
Ensure that each <CheckboxControl> component has a unique ID #45655
Conversation
Test Results SummaryCommit SHA: f9dc91b
To view the full API test report, click here. To view the full E2E test report, click here. To view all test reports, visit the WooCommerce Test Reports Dashboard. |
...erce-blocks/tests/e2e/tests/checkout/checkout-block.shopper.block_theme.side_effects.spec.ts
Outdated
Show resolved
Hide resolved
Hi @senadir, @wavvves, @woocommerce/rubik Apart from reviewing the code changes, please make sure to review the testing instructions as well. You can follow this guide to find out what good testing instructions should look like: |
@senadir I've opened up this PR for review, even though there's one failing test. The test is flaky and not related to this PR, as it tests the Filter Products by Price block when using the All Products block. |
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.
LGTM!
This can also be done via an integration test instead of an E2E. |
Thanks for your review, @senadir. Could you share a starting point on this? I'm asking as I could only find integration tests of individual components. I could not find any integration tests where we're testing the entire checkout form. 🤔 |
There isn't any so far, only for Cart. I'm creating one for Checkout that we can use. |
c7f5392
to
ed144e9
Compare
it( 'Ensures checkbox labels have unique IDs', async () => { | ||
allSettings.checkoutAllowsGuest = true; | ||
allSettings.checkoutAllowsSignup = true; | ||
dispatch( CHECKOUT_STORE_KEY ).__internalSetCustomerId( 0 ); |
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.
dispatch( CHECKOUT_STORE_KEY ).__internalSetCustomerId( 0 ); | |
allSettings.checkoutData.customer_id = 1; |
Using this works as well and reduces the risk of depending on data store and reflect actual use case (of the value coming from the server).
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 tried allSettings.checkoutData.customer_id = 0;
, but this results in the following checkbox label IDs:
[["checkbox-control-6", "checkbox-control-7", "terms-and-conditions"]]
While using dispatch( CHECKOUT_STORE_KEY ).__internalSetCustomerId( 0 );
, provides these checkbox label IDs:
[["checkbox-control-6", "checkbox-control-7", "checkbox-control-8", "terms-and-conditions"]]
For allSettings.checkoutData.customer_id = 0;
, I'm also seeing this error:
'allSettings.checkoutData' is of type 'unknown'.ts(18046)
I do not see any TS errors for allSettings.checkoutAllowsGuest = true;
and allSettings.checkoutAllowsSignup = true;
.
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.
Switching to allSettings.checkoutData.customer_id = 1;
did pass the test for me, should the test have failed?
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.
The test passed as there are still three checkboxes visible. Setting the customer ID to 0 then shows a fourth checkbox.
allSettings.checkoutAllowsGuest = true; | ||
allSettings.checkoutAllowsSignup = true; | ||
dispatch( CHECKOUT_STORE_KEY ).__internalSetCustomerId( 0 ); |
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.
You must reset those values to their original values at the end of the your test to not pollute other tests. Each test should leave the global state like it was found.
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.
Looking at
customer_id: 1, |
the customer_id
is set to 1
by default. Given that allSettings.checkoutData.customer_id = 0;
does not lead to the expected result, as one of the checkboxes is not visible then, I'd place the following line at the end of the test, to reset the global state:
dispatch( CHECKOUT_STORE_KEY ).__internalSetCustomerId( 1 );
Would you agree that this is the way forward in this case, @senadir?
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.
Also reset allSettings.checkoutAllowsGuest , allSettings.checkoutAllowsSignup
to their default values.
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.
For allSettings.checkoutAllowsGuest
and allSettings.checkoutAllowsSignup
, I'm seeing that they're undefined by default. So, I'd add the following lines at the end of the test:
allSettings.checkoutAllowsGuest = undefined;
allSettings.checkoutAllowsSignup = undefined;
* Ensure that each <CheckboxControl> component has a unique id * Add changefile(s) from automation for the following project(s): woocommerce-blocks * Optimise setup and teardown settings * Wrapping setup and teardown in act() --------- Co-authored-by: github-actions <github-actions@github.com>
* Ensure that each <CheckboxControl> component has a unique id * Add changefile(s) from automation for the following project(s): woocommerce-blocks * Optimise setup and teardown settings * Wrapping setup and teardown in act() --------- Co-authored-by: github-actions <github-actions@github.com>
Thanks for reviewing and approving this PR, @senadir. 🙌 |
Changes proposed in this Pull Request:
Closes #42046.
A while ago, we noticed that not all checkbox labels in the Checkout block had unique IDs. This led to the fact that when clicking one checkbox label, another section was triggered. In #42046, I shared the following observation:
These are the checkboxes and their IDs in incognito mode:
Create an account?
checkbox-control-0
Use same address for billing
checkbox-control-1
Add a note to your order
checkbox-control-0
These are the checkboxes and their IDs in logged-in mode:
Use same address for billing
checkbox-control-0
Add a note to your order
checkbox-control-0
@senadir addressed this issue in woocommerce/woocommerce-blocks#12015. In this issue, I've added e2e tests, which allow us to detect potential problems in an early stage. By default, the Checkout block can show the following four checkboxes:
Create an account?
Use same address for billing
Add a note to your order
You must accept our Terms and Conditions and Privacy Policy to continue with your purchase.
Our e2e test environment already shows the second, third, and fourth checkbox by default. To fully test all checkboxes, I ensured that the first checkbox
Create an account?
is also visible. To do that, this PR introduced the following changes:allSettings.checkoutAllowsGuest = true;
allSettings.checkoutAllowsSignup = true;
dispatch( CHECKOUT_STORE_KEY ).__internalSetCustomerId( 0 );
Only if all three conditions are met, the
Create an account?
checkbox becomes visible. The PR also restores the initial values after executing the test.How to test the changes in this Pull Request:
Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:
Changelog entry
Significance
Type
Message
Add an e2e test to ensure that each component has a unique ID.
Comment