forked from adobe/aem-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Cypress test to check the ACDL place-order event
- Loading branch information
Miquel Angel Coca Piza
authored and
Miquel Angel Coca Piza
committed
Dec 12, 2024
1 parent
501aa54
commit 37a01bb
Showing
1 changed file
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
); | ||
}); | ||
}); | ||
}); |