nextjs-starter-medusa
119 строк · 4.0 Кб
1import { Locator, Page } from "@playwright/test"
2import { BasePage } from "./base/base-page"
3
4export class CartPage extends BasePage {
5container: Locator
6emptyCartMessage: Locator
7signInButton: Locator
8productRow: Locator
9productTitle: Locator
10productVariant: Locator
11productDeleteButton: Locator
12productQuantitySelect: Locator
13discountButton: Locator
14discountInput: Locator
15discountApplyButton: Locator
16discountErrorMessage: Locator
17discountRow: Locator
18giftCardRow: Locator
19giftCardCode: Locator
20giftCardAmount: Locator
21giftCardRemoveButton: Locator
22cartSubtotal: Locator
23cartDiscount: Locator
24cartGiftCardAmount: Locator
25cartShipping: Locator
26cartTaxes: Locator
27cartTotal: Locator
28checkoutButton: Locator
29
30constructor(page: Page) {
31super(page)
32this.container = page.getByTestId("cart-container")
33this.emptyCartMessage = this.container.getByTestId("empty-cart-message")
34this.signInButton = this.container.getByTestId("sign-in-button")
35this.productRow = this.container.getByTestId("product-row")
36this.productTitle = this.container.getByTestId("product-title")
37this.productVariant = this.container.getByTestId("product-variant")
38this.productDeleteButton = this.container.getByTestId(
39"product-delete-button"
40)
41this.productQuantitySelect = this.container.getByTestId(
42"product-quantity-select"
43)
44this.checkoutButton = this.container.getByTestId("checkout-button")
45this.discountButton = this.container.getByTestId("add-discount-button")
46this.discountInput = this.container.getByTestId("discount-input")
47this.discountApplyButton = this.container.getByTestId(
48"discount-apply-button"
49)
50this.discountErrorMessage = this.container.getByTestId(
51"discount-error-message"
52)
53this.discountRow = this.container.getByTestId("discount-row")
54this.giftCardRow = this.container.getByTestId("gift-card")
55this.giftCardCode = this.container.getByTestId("gift-card-code")
56this.giftCardAmount = this.container.getByTestId("gift-card-amount")
57this.giftCardRemoveButton = this.container.getByTestId(
58"remove-gift-card-button"
59)
60this.cartSubtotal = this.container.getByTestId("cart-subtotal")
61this.cartDiscount = this.container.getByTestId("cart-discount")
62this.cartGiftCardAmount = this.container.getByTestId(
63"cart-gift-card-amount"
64)
65this.cartShipping = this.container.getByTestId("cart-shipping")
66this.cartTaxes = this.container.getByTestId("cart-taxes")
67this.cartTotal = this.container.getByTestId("cart-total")
68}
69
70async getProduct(title: string, variant: string) {
71const productRow = this.productRow
72.filter({
73hasText: title,
74})
75.filter({
76hasText: `Variant: ${variant}`,
77})
78return {
79productRow,
80title: productRow.getByTestId("product-title"),
81variant: productRow.getByTestId("product-variant"),
82deleteButton: productRow.getByTestId("delete-button"),
83quantitySelect: productRow.getByTestId("product-select-button"),
84price: productRow.getByTestId("product-unit-price"),
85total: productRow.getByTestId("product-price"),
86}
87}
88
89async getGiftCard(code: string) {
90const giftCardRow = this.giftCardRow.filter({
91hasText: code,
92})
93const amount = giftCardRow.getByTestId("gift-card-amount")
94return {
95locator: giftCardRow,
96code: giftCardRow.getByTestId("gift-card-code"),
97amount,
98amountValue: await amount.getAttribute("data-value"),
99removeButton: giftCardRow.getByTestId("remove-gift-card-button"),
100}
101}
102
103async getDiscount(code: string) {
104const discount = this.discountRow
105const amount = discount.getByTestId("discount-amount")
106return {
107locator: discount,
108code: discount.getByTestId("discount-code"),
109amount,
110amountValue: await amount.getAttribute("data-value"),
111removeButton: discount.getByTestId("remove-discount-button"),
112}
113}
114
115async goto() {
116await this.cartLink.click({ clickCount: 2 })
117await this.container.waitFor({ state: "visible" })
118}
119}
120