From a81ba3c6c4fe68c78bb195097f355713ca8bd49f Mon Sep 17 00:00:00 2001 From: "Chuting (Christina) Yan" <59424839+cctina516@users.noreply.github.com> Date: Fri, 6 Dec 2024 16:49:09 -0600 Subject: [PATCH 1/2] Add cypress test for cart event - part of USF 1654 (#227) * Add add-to-cart event test * update * Add all required context --- .../tests/e2eTests/events/add-to-cart.spec.js | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 cypress/src/tests/e2eTests/events/add-to-cart.spec.js diff --git a/cypress/src/tests/e2eTests/events/add-to-cart.spec.js b/cypress/src/tests/e2eTests/events/add-to-cart.spec.js new file mode 100644 index 0000000000..47cccc2b2a --- /dev/null +++ b/cypress/src/tests/e2eTests/events/add-to-cart.spec.js @@ -0,0 +1,33 @@ +import { products } from "../../../fixtures"; +import { expectsEventWithContext } from "../../../assertions"; +/** + * https://github.com/adobe/commerce-events/blob/main/examples/events/add-to-cart.md + * + * Required Contexts: page, storefront, product, shoppingCart, changedProducts + */ + +it("is sent on add to cart button click", () => { + cy.visit(products.configurable.urlPathWithOptions); + // add to cart + cy.get(".product-details__buttons__add-to-cart button") + .should("be.visible") + .click(); + + cy.waitForResource("commerce-events-collector.js").then(() => { + cy.window() + .its("adobeDataLayer") + .then((adobeDataLayer) => { + expectsEventWithContext( + "add-to-cart", + [ + "pageContext", + "storefrontInstanceContext", + "productContext", + "shoppingCartContext", + "changedProductsContext", + ], + adobeDataLayer + ); + }); + }); +}); From 2fc5bb1ec0e4b9b070f49d2f58471bbf40eb2c14 Mon Sep 17 00:00:00 2001 From: Stephen Date: Mon, 9 Dec 2024 08:47:22 -0600 Subject: [PATCH 2/2] chore: recs test against /gear not product (#239) Signed-off-by: Stephen Rugh --- cypress/src/tests/e2eTests/events/recs.spec.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cypress/src/tests/e2eTests/events/recs.spec.js b/cypress/src/tests/e2eTests/events/recs.spec.js index 383f73f6a7..26de88ec79 100644 --- a/cypress/src/tests/e2eTests/events/recs.spec.js +++ b/cypress/src/tests/e2eTests/events/recs.spec.js @@ -13,7 +13,7 @@ import { expectsEventWithContext } from "../../../assertions"; */ it('api-request-sent, api-response-received, unit-impression-render', () => { - cy.visit('/products/crown-summit-backpack/24-MB03'); + cy.visit('/gear'); cy.waitForResource('commerce-events-collector.js').then(() => { cy.window().its('adobeDataLayer').then((adobeDataLayer) => { expectsEventWithContext( @@ -36,7 +36,7 @@ it('api-request-sent, api-response-received, unit-impression-render', () => { }); it('recs-unit-view', () => { - cy.visit('/products/crown-summit-backpack/24-MB03'); + cy.visit('/gear'); cy.waitForResource('commerce-events-collector.js').then(() => { cy.get('.product-recommendations-wrapper').scrollIntoView({ duration: 1000 }); cy.window().its('adobeDataLayer').then((adobeDataLayer) => { @@ -49,7 +49,7 @@ it('recs-unit-view', () => { return adobeDataLayer; }).then(adobeDataLayer => { // triggers a second view when scrolled again - cy.get('.pdp-header__title').scrollIntoView({ duration: 50 }).then(() => { + cy.get('#gear').scrollIntoView({ duration: 50 }).then(() => { cy.get('.product-recommendations-wrapper').scrollIntoView({ duration: 50 }).then(() => { const eventCount = adobeDataLayer.filter(data => data?.event === 'recs-unit-view'); expect(eventCount).to.have.lengthOf(2); @@ -60,7 +60,7 @@ it('recs-unit-view', () => { }); it('recs-item-click', () => { - cy.visit('/products/crown-summit-backpack/24-MB03'); + cy.visit('/gear'); cy.waitForResource("commerce-events-collector.js").then(() => { cy.window().then((win) => { cy.spy(win.adobeDataLayer, "push").as("adl"); @@ -92,7 +92,7 @@ it('recs-item-click', () => { }); it('reqs-item-add-to-cart', () => { - cy.visit('/products/crown-summit-backpack/24-MB03'); + cy.visit('/gear'); cy.waitForResource("commerce-events-collector.js").then(() => { cy.window().then((win) => { cy.spy(win.adobeDataLayer, "push").as("adl");