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

Ensure that each <CheckboxControl> component has a unique ID #45655

Merged
merged 4 commits into from
Mar 29, 2024

Conversation

nielslange
Copy link
Member

@nielslange nielslange commented Mar 18, 2024

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:

Checkbox: ID:

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:

Checkbox: ID:

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:

  1. Create an account?
  2. Use same address for billing
  3. Add a note to your order
  4. 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:

  • Allow guests to place an order → allSettings.checkoutAllowsGuest = true;
  • Allow account creation during the checkout → allSettings.checkoutAllowsSignup = true;
  • Set the customer ID to 0 → 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:

  1. Verify that all JS tests are passing.

Changelog entry

  • Automatically create a changelog entry from the details below.

Significance

  • Patch
  • Minor
  • Major

Type

  • Fix - Fixes an existing bug
  • Add - Adds functionality
  • Update - Update existing functionality
  • Dev - Development related task
  • Tweak - A minor adjustment to the codebase
  • Performance - Address performance issues
  • Enhancement - Improvement to existing functionality

Message

Add an e2e test to ensure that each component has a unique ID.

Comment

@nielslange nielslange added the team: Rubik Store API checkout endpoints, Mini-Cart, Cart and Checkout related issues label Mar 18, 2024
@nielslange nielslange self-assigned this Mar 18, 2024
Copy link
Contributor

github-actions bot commented Mar 18, 2024

Test Results Summary

Commit SHA: f9dc91b

Test 🧪Passed ✅Failed 🚨Broken 🚧Skipped ⏭️Unknown ❔Total 📊Duration ⏱️
API Tests25900202610m 38s
E2E Tests332005903918m 7s

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.

@nielslange nielslange closed this Mar 18, 2024
@nielslange nielslange reopened this Mar 18, 2024
@github-actions github-actions bot added the plugin: woocommerce Issues related to the WooCommerce Core plugin. label Mar 20, 2024
@nielslange nielslange requested review from WunderBart, a team and senadir and removed request for a team March 21, 2024 06:25
Copy link
Contributor

github-actions bot commented Mar 21, 2024

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:
https://github.com/woocommerce/woocommerce/wiki/Writing-high-quality-testing-instructions

@nielslange nielslange removed the request for review from WunderBart March 21, 2024 06:27
@nielslange nielslange marked this pull request as ready for review March 21, 2024 06:27
@woocommercebot woocommercebot requested a review from a team March 21, 2024 06:27
@nielslange
Copy link
Member Author

@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.

Copy link
Contributor

@wavvves wavvves left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@senadir
Copy link
Member

senadir commented Mar 21, 2024

This can also be done via an integration test instead of an E2E.

@nielslange
Copy link
Member Author

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. 🤔

@senadir
Copy link
Member

senadir commented Mar 21, 2024

There isn't any so far, only for Cart. I'm creating one for Checkout that we can use.

@nielslange nielslange marked this pull request as draft March 21, 2024 14:29
@nielslange
Copy link
Member Author

nielslange commented Mar 21, 2024

I'm changing this back to draft to implement integration tests instead of e2e tests.
cc: @senadir and @wavvves

@nielslange nielslange force-pushed the add/42046-CheckboxControl-e2e-tests branch from c7f5392 to ed144e9 Compare March 27, 2024 15:05
@github-actions github-actions bot removed the plugin: woocommerce Issues related to the WooCommerce Core plugin. label Mar 27, 2024
@nielslange nielslange closed this Mar 27, 2024
@nielslange nielslange reopened this Mar 27, 2024
@github-actions github-actions bot added the plugin: woocommerce Issues related to the WooCommerce Core plugin. label Mar 27, 2024
it( 'Ensures checkbox labels have unique IDs', async () => {
allSettings.checkoutAllowsGuest = true;
allSettings.checkoutAllowsSignup = true;
dispatch( CHECKOUT_STORE_KEY ).__internalSetCustomerId( 0 );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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).

Copy link
Member Author

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;.

Copy link
Member

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?

Copy link
Member Author

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.

Comment on lines 168 to 170
allSettings.checkoutAllowsGuest = true;
allSettings.checkoutAllowsSignup = true;
dispatch( CHECKOUT_STORE_KEY ).__internalSetCustomerId( 0 );
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at

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?

Copy link
Member

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.

Copy link
Member Author

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;

@nielslange nielslange requested a review from senadir March 27, 2024 16:01
@nielslange nielslange marked this pull request as ready for review March 27, 2024 17:17
@nielslange nielslange requested a review from wavvves March 27, 2024 17:17
@woocommercebot woocommercebot requested a review from a team March 27, 2024 17:17
@senadir senadir merged commit cad1aa6 into trunk Mar 29, 2024
48 checks passed
@senadir senadir deleted the add/42046-CheckboxControl-e2e-tests branch March 29, 2024 11:46
@github-actions github-actions bot added this to the 8.9.0 milestone Mar 29, 2024
@github-actions github-actions bot added the needs: analysis Indicates if the PR requires a PR testing scrub session. label Mar 29, 2024
@veljkho veljkho added status: analysis complete Indicates if a PR has been analysed by Solaris and removed needs: analysis Indicates if the PR requires a PR testing scrub session. labels Mar 29, 2024
moon0326 pushed a commit that referenced this pull request Mar 29, 2024
* 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>
moon0326 pushed a commit that referenced this pull request Mar 29, 2024
* 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>
@nielslange
Copy link
Member Author

Thanks for reviewing and approving this PR, @senadir. 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin: woocommerce Issues related to the WooCommerce Core plugin. status: analysis complete Indicates if a PR has been analysed by Solaris team: Rubik Store API checkout endpoints, Mini-Cart, Cart and Checkout related issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create integration test to ensure that <CheckboxControl> component label links to correct element
5 participants