Skip to content

Add E2E coverage for purchase on both checkout forms, SKU identifier, disabled events, and settings form - #638

Merged
eason9487 merged 6 commits into
trunkfrom
dev/add-e2e-test-coverage
Jul 24, 2026
Merged

Add E2E coverage for purchase on both checkout forms, SKU identifier, disabled events, and settings form#638
eason9487 merged 6 commits into
trunkfrom
dev/add-e2e-test-coverage

Conversation

@eason9487

@eason9487 eason9487 commented Jul 24, 2026

Copy link
Copy Markdown
Member

Changes proposed in this Pull Request:

This PR extends the E2E suite to cover several happy paths that are sensitive to store settings and to WP/WC version changes, plus the test infrastructure needed to drive them.

  • Purchase coverage split by checkout form: a new test in the blocks spec places an order through the woocommerce/checkout block, and the classic spec's purchase test now drives the order through the [woocommerce_checkout] shortcode form (a wc-ajax=checkout submission rather than the Store API) via a new classicCheckout() helper, so the two purchase tests exercise the two different checkout forms instead of duplicating each other. Both assert the purchase event reports the order's items, quantities, variation, totals, shipping, and transaction ID. The order-received confirmation is rendered by the block theme's Order Confirmation template for both forms; a true classic thankyou template would require a classic theme, which the suite does not use. The now-dead classic form branch inside the checkout() helper (unreachable since the default checkout page is the block checkout) is removed, with the classic path owned by classicCheckout().
  • SKU product identifier: new tests switch the ga_product_identifier setting to SKU and assert that view_item reports the product SKU, falls back to the #id form when a product has no SKU, and that a Store API add to cart on the block storefront also reports the SKU (a separate, server-resolved identifier path).
  • Disabled event tracking: new tests assert that no ecommerce events reach GA when every event toggle is off (while the tracking scripts still load, verified through window.ga4w.settings.events), and that disabling only add to cart leaves the other events firing.
  • Settings form: a new test asserts the integration settings form renders the product identifier select with its options, the tracking ID field, and every remaining control defined by init_form_fields(), so a dropped control or a mislabeled identifier option is caught.
  • Test infrastructure: the test settings endpoint (tests/e2e/test-data) now accepts a product identifier override, and the per-event tracking toggles through the request body, and createSimpleProduct() / setSettings() accept overrides. All default to the previous behavior, so existing specs are unaffected.

Checks:

  • Does your code follow the WordPress coding standards?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully run tests with your changes locally?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?

Detailed test instructions:

  1. Start the test environment: npm run wp-env:up
  2. Run the E2E test to confirm all the tests can pass: npm run test:e2e
  3. View the E2E test run result for this PR to confirm that all tests passed.
    https://github.com/woocommerce/woocommerce-google-analytics-integration/actions/runs/30002235049/job/89189882792

Changelog entry

No issues found.

Place an order through the woocommerce/checkout block and assert the
purchase event reports the order's items, quantities, variation, totals,
shipping, and transaction id.

The purchase event is built server-side from the order, so its data does
not vary by checkout type, but the block checkout form and the block
order-confirmation page (where woocommerce_thankyou fires) can break
independently of the classic checkout across store settings and
WooCommerce versions. Verifying the block path on its own guards that
happy path.
Cover the merchant setting that switches product reporting from the
WooCommerce id to the SKU. With the identifier set to SKU, assert that the
view_item event reports the product's SKU, that it falls back to the "#id"
form when a product has no SKU, and that a Store API add to cart on the
block storefront also reports the SKU.

Let the test settings endpoint accept a product identifier override and
let createSimpleProduct() take field overrides so a product can be created
with a SKU. Both default to the previous behavior.
Assert that no ecommerce events reach GA when every event toggle is off
(while the tracking scripts still load), and that disabling only add to
cart leaves the other events firing.

Let the test settings endpoint accept per-event tracking toggles so a
test can switch individual events off.
Assert the integration settings form renders the product identifier
select with its options, the tracking id field, and every remaining
control defined by init_form_fields, so a dropped control or a
mislabeled identifier option is caught.
The classic spec's purchase test submitted the default checkout page,
which is the block checkout, so it duplicated the block purchase test in
the blocks spec. Drive it through the classic [woocommerce_checkout]
shortcode form instead (a wc-ajax=checkout submission rather than the
Store API) via a new classicCheckout() helper.

The order-received confirmation is rendered by the block theme's Order
Confirmation template for both forms, so that surface stays shared; a
true classic thankyou template would require a classic theme, which the
suite does not use.
checkout() always navigates to the default checkout page, which has been
the block checkout in this suite, so its classic form branch could never
run. The classic form path is now owned by classicCheckout().
@eason9487 eason9487 self-assigned this Jul 24, 2026
@github-actions github-actions Bot added the changelog: dev Developer-facing only change. label Jul 24, 2026
@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: b56db1cb-b557-421b-bdd5-e41395323ace

📥 Commits

Reviewing files that changed from the base of the PR and between efa939d and fada927.

⛔ Files ignored due to path filters (7)
  • tests/e2e/specs/gtag-events/blocks-pages.test.js is excluded by none and included by none
  • tests/e2e/specs/gtag-events/classic-pages.test.js is excluded by none and included by none
  • tests/e2e/specs/gtag-events/disabled-events.test.js is excluded by none and included by none
  • tests/e2e/specs/gtag-events/product-identifier.test.js is excluded by none and included by none
  • tests/e2e/specs/integration-settings.test.js is excluded by none and included by none
  • tests/e2e/utils/api.js is excluded by none and included by none
  • tests/e2e/utils/customer.js is excluded by none and included by none
📒 Files selected for processing (1)
  • tests/e2e/test-data/test-data.php

📝 Walkthrough

Walkthrough

The test-data REST handler now accepts JSON request parameters, validates supported Google Analytics product and toggle values, applies valid overrides to defaults, and persists the resulting settings.

Changes

GA test settings

Layer / File(s) Summary
Request validation and settings persistence
tests/e2e/test-data/test-data.php
set_settings reads JSON request data, conditionally overrides the product identifier and GA toggle settings when values are valid, and updates the WooCommerce Google Analytics settings option.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main E2E coverage additions across checkout forms, SKU identifiers, disabled events, and settings controls.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dev/add-e2e-test-coverage

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@eason9487
eason9487 merged commit f16f837 into trunk Jul 24, 2026
11 checks passed
@eason9487
eason9487 deleted the dev/add-e2e-test-coverage branch July 24, 2026 02:24
@costasovo costasovo mentioned this pull request Aug 6, 2026
21 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog: dev Developer-facing only change.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant