Skip to content

Commit

Permalink
Add cypress test for cart event
Browse files Browse the repository at this point in the history
  • Loading branch information
cctina516 authored and anthoula committed Dec 16, 2024
1 parent 8acdea0 commit 63646d0
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions cypress/src/tests/e2eTests/events/shopping-cart-view.spec.js
Original file line number Diff line number Diff line change
@@ -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
);
});
});
});

0 comments on commit 63646d0

Please sign in to comment.