Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added cypress test for place-order event - part of USF 1655 #249

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions cypress/src/tests/e2eTests/events/place-order.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import {
placeOrder,
setGuestEmail,
setGuestShippingAddress,
} from "../../../actions";
import { expectsEventWithContext } from "../../../assertions";
import { customerShippingAddress, products } from "../../../fixtures";

/**
* https://github.com/adobe/commerce-events/blob/main/examples/events/place-order.md
*
* Required Contexts:
* - page -> https://github.com/adobe/commerce-events/blob/main/packages/storefront-events-sdk/src/types/schemas/page.ts,
* - storefront -> https://github.com/adobe/commerce-events/blob/main/packages/storefront-events-sdk/src/types/schemas/storefrontInstance.ts,
* - shoppingCart -> https://github.com/adobe/commerce-events/blob/main/packages/storefront-events-sdk/src/types/schemas/shoppingCart.ts,
* - order -> https://github.com/adobe/commerce-events/blob/main/packages/storefront-events-sdk/src/types/schemas/order.ts
*/

it("is sent on place order button click", () => {
// add item to cart
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 checkout button
cy.get('#nav div.cart-mini-cart a[href="/checkout"]')
.should("be.visible")
.click();

// fill in the login form
const apiMethod = "setGuestEmailOnCart";
const urlTest = Cypress.env("graphqlEndPoint");
cy.intercept("POST", urlTest, (req) => {
let data = req.body.query;
if (data && typeof data == "string") {
if (data.includes(apiMethod)) {
req.alias = "setEmailOnCart";
}
}
});
setGuestEmail(customerShippingAddress.email);
cy.wait("@setEmailOnCart");
// fill in the shipping address form
setGuestShippingAddress(customerShippingAddress, true);
cy.wait(2000);
// click the place order button
placeOrder();
// wait until the URL includes '/order-details'
cy.url().should("include", "/order-details");

cy.waitForResource("commerce-events-collector.js").then(() => {
cy.window()
.its("adobeDataLayer")
.then((adobeDataLayer) => {
expectsEventWithContext(
"place-order",
[
"pageContext",
"storefrontInstanceContext",
"shoppingCartContext",
"orderContext",
],
adobeDataLayer
);
});
});
});
Loading