From 4616c2830541629ac04dc9f54ed9f0ba57332b69 Mon Sep 17 00:00:00 2001 From: chutingy Date: Fri, 6 Dec 2024 12:28:36 -0600 Subject: [PATCH] Add cypress test for cart event --- .../events/shopping-cart-view.spec.js | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 cypress/src/tests/e2eTests/events/shopping-cart-view.spec.js diff --git a/cypress/src/tests/e2eTests/events/shopping-cart-view.spec.js b/cypress/src/tests/e2eTests/events/shopping-cart-view.spec.js new file mode 100644 index 0000000000..008901552e --- /dev/null +++ b/cypress/src/tests/e2eTests/events/shopping-cart-view.spec.js @@ -0,0 +1,33 @@ +import { products } from "../../../fixtures"; +import { expectsEventWithContext } from "../../../assertions"; +/** + * https://github.com/adobe/commerce-events/blob/main/examples/events/shopping-cart-view.md + * + * Required Contexts: page, storefront, shoppingCart + */ + +it("is sent on view cart button click", () => { + cy.visit(products.configurable.urlPathWithOptions); + // add to cart + cy.get(".product-details__buttons__add-to-cart button") + .should("be.visible") + .click(); + // click the minicart toggle + cy.get('button[data-count="1"]').should("be.visible").click(); + // click the view cart button + cy.get('#nav div.cart-mini-cart a[href="/cart"]') + .should("be.visible") + .click(); + + cy.waitForResource("commerce-events-collector.js").then(() => { + cy.window() + .its("adobeDataLayer") + .then((adobeDataLayer) => { + expectsEventWithContext( + "shopping-cart-view", + ["pageContext", "storefrontInstanceContext", "shoppingCartContext"], + adobeDataLayer + ); + }); + }); +});