diff --git a/specs/e2e/flex-promotion-buy-x-pay-y.spec.ts b/specs/e2e/flex-promotion-buy-x-pay-y.spec.ts new file mode 100644 index 00000000..01516fd8 --- /dev/null +++ b/specs/e2e/flex-promotion-buy-x-pay-y.spec.ts @@ -0,0 +1,18 @@ +import { test, expect } from "../fixtures/tokenizedPage" + +test.describe("with coupon code", () => { + test.use({ + defaultParams: { + order: "with-items", + lineItemsAttributes: [ + { sku_code: "SWEETSMUB7B7B7E63E74LXXX", quantity: 3 }, + ], + couponCode: "flex_promotion_buy_x_pay_y", + }, + }) + + test("should execute a checkout", async ({ checkoutPage }) => { + await checkoutPage.checkOrderSummary("Order Summary") + await checkoutPage.checkDiscountAmount("-€35") + }) +}) \ No newline at end of file diff --git a/specs/e2e/flex-promotion-dynamic-bundles.spec.ts b/specs/e2e/flex-promotion-dynamic-bundles.spec.ts new file mode 100644 index 00000000..646861f5 --- /dev/null +++ b/specs/e2e/flex-promotion-dynamic-bundles.spec.ts @@ -0,0 +1,21 @@ +import { test, expect } from "../fixtures/tokenizedPage" + +test.describe("with coupon code", () => { + test.use({ + defaultParams: { + order: "with-items", + lineItemsAttributes: [ + { sku_code: "5PANECAP9D9CA1FFFFFFXXXX", quantity: 2 }, + { sku_code: "CROPTOPW000000FFFFFFLXXX", quantity: 2 }, + { sku_code: "CROPTOPWE8E8E8000000XSXX", quantity: 1 }, + { sku_code: "HOODIEWC000000FFFFFFLXXX", quantity: 1 }, + ], + couponCode: "flex_promotion_dynamic_bundles", + }, + }) + + test("should execute a checkout", async ({ checkoutPage }) => { + await checkoutPage.checkOrderSummary("Order Summary") + await checkoutPage.checkDiscountAmount("-€37,86") + }) +}) \ No newline at end of file diff --git a/specs/e2e/flex-promotion-dynamic-value.spec.ts b/specs/e2e/flex-promotion-dynamic-value.spec.ts new file mode 100644 index 00000000..bc569fb8 --- /dev/null +++ b/specs/e2e/flex-promotion-dynamic-value.spec.ts @@ -0,0 +1,26 @@ +import { test, expect } from "../fixtures/tokenizedPage" + +test.describe("with coupon code", () => { + test.use({ + defaultParams: { + order: "with-items", + lineItemsAttributes: [ + { sku_code: "SOCKXXMUFFFFFF000000MXXX", quantity: 1 }, + { sku_code: "TSHIRTMMFFFFFFE63E74MXXX", quantity: 1 }, + { sku_code: "LSLEEVMM000000E63E74LXXX", quantity: 1 }, + ], + couponCode: "flex_promotion_dynamic_value", + }, + }) + + test("should execute a checkout", async ({ checkoutPage }) => { + await checkoutPage.checkOrderSummary("Order Summary") + await checkoutPage.setCustomerMail("test@commercelayer.io") + await checkoutPage.setBillingAddress() + await checkoutPage.checkStep("Customer", "open") + await checkoutPage.save("Customer") + await checkoutPage.checkStep("Shipping", "open") + await checkoutPage.selectShippingMethod({ text: "Standard Shipping" }) + await checkoutPage.checkDiscountAmount("-€12,20") + }) +}) \ No newline at end of file diff --git a/specs/e2e/flex-promotion-every-x-discount-y.spec.ts b/specs/e2e/flex-promotion-every-x-discount-y.spec.ts new file mode 100644 index 00000000..9082bba9 --- /dev/null +++ b/specs/e2e/flex-promotion-every-x-discount-y.spec.ts @@ -0,0 +1,18 @@ +import { test, expect } from "../fixtures/tokenizedPage" + +test.describe("with coupon code", () => { + test.use({ + defaultParams: { + order: "with-items", + lineItemsAttributes: [ + { sku_code: "SWEETSMUB7B7B7E63E74LXXX", quantity: 5 }, + ], + couponCode: "flex_promotion_every_x_discount_y", + }, + }) + + test("should execute a checkout", async ({ checkoutPage }) => { + await checkoutPage.checkOrderSummary("Order Summary") + await checkoutPage.checkDiscountAmount("-€5") + }) +}) \ No newline at end of file diff --git a/specs/e2e/flex-promotion-fixed-amount.spec.ts b/specs/e2e/flex-promotion-fixed-amount.spec.ts new file mode 100644 index 00000000..d8e4a1cc --- /dev/null +++ b/specs/e2e/flex-promotion-fixed-amount.spec.ts @@ -0,0 +1,18 @@ +import { test, expect } from "../fixtures/tokenizedPage" + +test.describe("with coupon code", () => { + test.use({ + defaultParams: { + order: "with-items", + lineItemsAttributes: [ + { sku_code: "SWEETSMUB7B7B7E63E74LXXX", quantity: 5 }, + ], + couponCode: "flex_promotion_fixed_amount", + }, + }) + + test("should execute a checkout", async ({ checkoutPage }) => { + await checkoutPage.checkOrderSummary("Order Summary") + await checkoutPage.checkDiscountAmount("-€5") + }) +}) \ No newline at end of file diff --git a/specs/e2e/flex-promotion-fixed-price.spec.ts b/specs/e2e/flex-promotion-fixed-price.spec.ts new file mode 100644 index 00000000..af6a6e80 --- /dev/null +++ b/specs/e2e/flex-promotion-fixed-price.spec.ts @@ -0,0 +1,18 @@ +import { test, expect } from "../fixtures/tokenizedPage" + +test.describe("with coupon code", () => { + test.use({ + defaultParams: { + order: "with-items", + lineItemsAttributes: [ + { sku_code: "SWEETSMUB7B7B7E63E74LXXX", quantity: 5 }, + ], + couponCode: "flex_promotion_fixed_price", + }, + }) + + test("should execute a checkout", async ({ checkoutPage }) => { + await checkoutPage.checkOrderSummary("Order Summary") + await checkoutPage.checkDiscountAmount("-€162,5") + }) +}) \ No newline at end of file diff --git a/specs/e2e/flex-promotion-nested-country-code.spec.ts b/specs/e2e/flex-promotion-nested-country-code.spec.ts new file mode 100644 index 00000000..43241a13 --- /dev/null +++ b/specs/e2e/flex-promotion-nested-country-code.spec.ts @@ -0,0 +1,32 @@ +import { test, expect } from "../fixtures/tokenizedPage" + +test.describe("with coupon code", () => { + test.use({ + defaultParams: { + order: "with-items", + lineItemsAttributes: [ + { + sku_code: "DUFFLBAG000000FFFFFFXXXX", + quantity: 1, + sku_options: [ + { + name: "Premium zipper", + } + ] + } + ], + couponCode: "flex_promotion_nested_country_code", + }, + }) + + test("should execute a checkout", async ({ checkoutPage }) => { + await checkoutPage.checkOrderSummary("Order Summary") + await checkoutPage.setCustomerMail("prospect@commercelayer.io") + await checkoutPage.setBillingAddress() + await checkoutPage.checkStep("Customer", "open") + await checkoutPage.save("Customer") + await checkoutPage.checkStep("Shipping", "open") + await checkoutPage.selectShippingMethod({ text: "Standard Shipping" }) + await checkoutPage.checkDiscountAmount("-€25,00") + }) +}) \ No newline at end of file diff --git a/specs/e2e/flex-promotion-percentage.spec.ts b/specs/e2e/flex-promotion-percentage.spec.ts new file mode 100644 index 00000000..80ee8e50 --- /dev/null +++ b/specs/e2e/flex-promotion-percentage.spec.ts @@ -0,0 +1,18 @@ +import { test, expect } from "../fixtures/tokenizedPage" + +test.describe("with coupon code", () => { + test.use({ + defaultParams: { + order: "with-items", + lineItemsAttributes: [ + { sku_code: "SWEETSMUB7B7B7E63E74LXXX", quantity: 5 }, + ], + couponCode: "flex_promotion_percentage", + }, + }) + + test("should execute a checkout", async ({ checkoutPage }) => { + await checkoutPage.checkOrderSummary("Order Summary") + await checkoutPage.checkDiscountAmount("-€18,50") + }) +}) \ No newline at end of file diff --git a/specs/fixtures/CheckoutPage.ts b/specs/fixtures/CheckoutPage.ts index 586b787f..ddf02b98 100644 --- a/specs/fixtures/CheckoutPage.ts +++ b/specs/fixtures/CheckoutPage.ts @@ -33,9 +33,8 @@ export class CheckoutPage { } async goto({ orderId, token }: GoToProps) { - const url = `${ - process.env.NEXT_PUBLIC_BASE_PATH || "" - }/${orderId}?accessToken=${token}` + const url = `${process.env.NEXT_PUBLIC_BASE_PATH || "" + }/${orderId}?accessToken=${token}` await this.page.route("**/api/organization**", (route) => { // // Add a prefix to the title. @@ -475,10 +474,10 @@ export class CheckoutPage { } const fieldType = key === "country_code" || - (key === "state_code" && - address.country_code && - // TODO Adjust to check for select or input - ["IT", "US"].includes(address.country_code)) + (key === "state_code" && + address.country_code && + // TODO Adjust to check for select or input + ["IT", "US"].includes(address.country_code)) ? "select" : "input" const element = this.page.locator(`${fieldType}[name=${type}_${key}]`) @@ -627,7 +626,7 @@ export class CheckoutPage { } async checkLineItemAmount(text?: string) { - const element = await this.page.getByTestId(`line-item-amount`) + const element = this.page.getByTestId(`line-item-amount`) if (text !== undefined) { await element.waitFor({ state: "visible" }) await expect(await element.innerText()).toBe(text) @@ -637,7 +636,9 @@ export class CheckoutPage { } async checkDiscountAmount(text?: string) { - const element = await this.page.getByTestId("discount-amount") + const element = this.page.locator( + `[data-testid=discount-amount] >> text=${text}` + ) if (text !== undefined) { await element.waitFor({ state: "visible" }) } else { @@ -646,7 +647,7 @@ export class CheckoutPage { } async checkGiftCardAmount(text?: string) { - const element = await this.page.locator( + const element = this.page.locator( `[data-testid=giftcard-amount] >> text=${text}` ) if (text !== undefined) { @@ -740,13 +741,13 @@ export class CheckoutPage { }: { type: "adyen-dropin" | "klarna" | "stripe" gateway?: - | "paypal" - | "card" - | "card3DS" - | "klarna_pay_over_time" - | "klarna_pay_later" - | "klarna_pay_now" - | "klarna" + | "paypal" + | "card" + | "card3DS" + | "klarna_pay_over_time" + | "klarna_pay_later" + | "klarna_pay_now" + | "klarna" language?: "fr" | "de" | "us" }) { switch (type) {