Skip to content

Add E2E coverage for admin, consent, and event flows - #639

Merged
eason9487 merged 7 commits into
trunkfrom
dev/add-e2e-admin-consent-and-event-coverage
Jul 24, 2026
Merged

Add E2E coverage for admin, consent, and event flows#639
eason9487 merged 7 commits into
trunkfrom
dev/add-e2e-admin-consent-and-event-coverage

Conversation

@eason9487

@eason9487 eason9487 commented Jul 24, 2026

Copy link
Copy Markdown
Member

Changes proposed in this Pull Request:

This PR adds E2E coverage for admin flows, consent mode delivery, and the remaining event tracking surfaces, so manual testing can focus on what automation cannot observe.

  • Plugin activation: a new spec deactivates and reactivates the plugin through the plugins screen and asserts each action completes with its success notice and no visible error notice. REST calls pin the plugin to active before and after, so a failure cannot leave the rest of the suite running without the plugin. The row is located through its data-plugin attribute because the action links' id attributes depend on data from the wp.org updates API and change when the environment is offline.
  • Settings saving: a new test fills every control with non-default values, saves through WooCommerce's settings handler, and asserts the values re-render from the database on a fresh GET.
  • Consent mode delivery: new tests assert the EEA default consent entry reaches the browser's dataLayer, and that a consent mode appended through the woocommerce_ga_gtag_consent_modes filter is delivered as well. A new test additionally asserts the gcs parameter on event hits reflects wp_set_consent() updates in both directions for both ad_storage and analytics_storage, which is the wire-level data Tag Assistant decodes. One empirical constraint is documented in the test: the plugin's defaults are region-scoped to the EEA, so every stage sets both categories explicitly. Hits sent while a category is denied still arrive as consent-restricted pings.
  • Select content: new tests cover the default shop page and opening a related product by its name, completing the click-through coverage across the storefront pages.
  • Disabled tracking journey: a new test walks a product click-through, the product page, cart mutations, checkout, and the order confirmation with every event toggle off and asserts none of the plugin's events reach GA, extending the disabled coverage to every event surface, including the server-side purchase capture.
  • Test infrastructure: the test snippets plugin gains a query-gated filter that appends a consent mode for a given region, mirroring the documented customization contract.

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/30073401752/job/89418847214

Changelog entry

No issues found.

Drive the plugins screen as admin and assert both actions complete with
their success notice and no visible error notice, which is where a fatal
during (de)activation would surface. REST calls pin the plugin to active
before and after the test so a failure cannot leave the rest of the
suite running without the plugin.
Fill every control on the integration settings form, save through
WooCommerce's settings handler, and assert the values are repopulated
from the database after the reload, covering the save round-trip the
render test deliberately left out.
Assert the EEA default consent entry (regions, denied statuses, and the
wait_for_update window) lands in the browser's dataLayer, and that a
consent mode appended through the woocommerce_ga_gtag_consent_modes
filter is delivered as well, exercising the documented customization
contract end to end.

Add a query-gated test snippet that appends a consent mode for a given
region, running after the existing grant-all snippet.
The select content event was covered for the All Products block and the
classic shortcode page, but not for the default shop page nor for
opening a related product by its name; both complete the click-through
coverage of the manual testing checklist.
Walk a product click-through from the shop, the product page, cart
mutations, checkout, and the order confirmation with every event toggle
off and assert none of the plugin's events reach GA, extending the
disabled coverage beyond shop page interactions to every event surface
including the server-side purchase capture.
Assert the gcs parameter on add_to_cart hits reflects wp_set_consent
updates in both directions for both ad_storage and analytics_storage,
which is the wire-level data Tag Assistant decodes, so the consent state
carried by the events is verified without a manual Tag Assistant
session.

Every stage sets both categories explicitly because the plugin's
defaults are region-scoped to the EEA and would leave the digits unset
elsewhere; hits sent while a category is denied still arrive as
consent-restricted pings.
@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: 77056b07-9c59-44f5-af1f-1e586318d8aa

📥 Commits

Reviewing files that changed from the base of the PR and between 7795757 and 6a157ad.

📒 Files selected for processing (1)
  • tests/e2e/test-snippets/test-snippets.php

📝 Walkthrough

Walkthrough

The e2e test snippets add a later consent-mode filter callback for a sanitized regional URL parameter and switch the script dependency array to PHP short syntax without changing its contents.

Changes

Consent-mode testing

Layer / File(s) Summary
Regional consent entry
tests/e2e/test-snippets/test-snippets.php
Adds a later woocommerce_ga_gtag_consent_modes callback that appends analytics and advertising storage consent for the requested region.
Enqueue dependency syntax
tests/e2e/test-snippets/test-snippets.php
Replaces long array syntax with short syntax while preserving the dependency list.

Estimated code review effort: 2 (Simple) | ~5 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 clearly matches the PR’s main addition of end-to-end coverage for admin, consent, and event-related flows.
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-admin-consent-and-event-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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
tests/e2e/test-snippets/test-snippets.php (1)

50-54: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Suggestion: use short array syntax.

Replace array() with [] for both arrays in this PHP file.

As per coding guidelines, PHP must use short array syntax [] instead of array().

Proposed fix
-			$modes[] = array(
+			$modes[] = [
				'analytics_storage' => 'granted',
				'ad_storage'        => 'granted',
-				'region'            => array( $region ),
-			);
+				'region'            => [ $region ],
+			];
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/e2e/test-snippets/test-snippets.php` around lines 50 - 54, Update the
array declarations in the test snippet around the $modes assignment to use PHP
short array syntax [] instead of array() for both the outer and nested arrays,
preserving the existing keys and values.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@tests/e2e/test-snippets/test-snippets.php`:
- Around line 50-54: Update the array declarations in the test snippet around
the $modes assignment to use PHP short array syntax [] instead of array() for
both the outer and nested arrays, preserving the existing keys and values.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 5a769e3a-1569-4a26-88da-1f11f144b2ff

📥 Commits

Reviewing files that changed from the base of the PR and between f16f837 and 7795757.

⛔ Files ignored due to path filters (6)
  • tests/e2e/specs/gtag-events/blocks-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/installation.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/specs/js-scripts/consent-defaults.test.js is excluded by none and included by none
  • tests/e2e/specs/js-scripts/wp-consent-api.test.js is excluded by none and included by none
📒 Files selected for processing (1)
  • tests/e2e/test-snippets/test-snippets.php

The coding guidelines prefer [] over array(), and PHPCS does not
enforce it, so these were not caught by lint.

Address: #639 (review)

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR expands the Playwright E2E suite to cover key admin flows (activation + settings persistence), consent-mode delivery/updates, and additional GA4 event surfaces—reducing reliance on manual verification for behaviors that can be observed via browser/network assertions.

Changes:

  • Add E2E specs for plugin (de)activation and WooCommerce integration settings save/reload persistence.
  • Add consent-mode E2E coverage for dataLayer default delivery, filter-appended modes, and wire-level gcs consent state on event hits.
  • Extend storefront event coverage (e.g., select_content) and add an end-to-end “all tracking disabled” purchase journey assertion.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/e2e/test-snippets/test-snippets.php Adds a query-gated consent-mode appender snippet and adjusts script dependency array syntax for E2E flexibility.
tests/e2e/specs/js-scripts/wp-consent-api.test.js Adds assertions that GA collect hits include updated consent state via the gcs parameter.
tests/e2e/specs/js-scripts/consent-defaults.test.js New spec asserting consent defaults (EEA + filter-appended) reach the browser dataLayer.
tests/e2e/specs/integration-settings.test.js Adds a settings save-and-reload persistence test and clears settings after the spec.
tests/e2e/specs/installation.test.js New spec exercising plugin deactivate/reactivate flows via wp-admin with REST state pinning.
tests/e2e/specs/gtag-events/disabled-events.test.js Adds a full shopper-journey assertion that no plugin events fire when all tracking is disabled.
tests/e2e/specs/gtag-events/blocks-pages.test.js Adds select_content coverage from the shop page and related-product title clicks.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

test.use( { storageState: process.env.ADMINSTATE } );

const PLUGIN_SLUG = 'woocommerce-google-analytics-integration';
const PLUGIN_REST_ROUTE = `plugins/${ PLUGIN_SLUG }/${ PLUGIN_SLUG }`;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

That's incorrect. Adding it actually causes a 404 error. Verified via Console and a script:

wp.apiFetch({ path:'/wp/v2/plugins/woocommerce-google-analytics-integration/woocommerce-google-analytics-integration.php' })
.then(console.log)
.catch(console.log)
image

@eason9487
eason9487 merged commit f17d4a5 into trunk Jul 24, 2026
10 checks passed
@eason9487
eason9487 deleted the dev/add-e2e-admin-consent-and-event-coverage branch July 24, 2026 07:28
@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.

2 participants