Skip to content

Commit 73b7435

Browse files
committed
test(e2e): update price and cart fixtures
1 parent 9d13664 commit 73b7435

File tree

7 files changed

+105
-29
lines changed

7 files changed

+105
-29
lines changed

e2e/fixtures/base/cart-dropdown.ts

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,33 @@ export class CartDropdown {
1919
await this.navCartLink.hover()
2020
}
2121

22-
async getCartItem(name: string) {
23-
const cartItem = this.cartDropdown.getByTestId("cart-item").filter({
24-
hasText: name,
25-
})
26-
const quantity = cartItem
27-
.getByTestId("cart-item-quantity")
28-
.getAttribute("data-value")
29-
const variant = cartItem
30-
.getByTestId("cart-item-variant")
31-
.getAttribute("data-value")
22+
async close() {
23+
if (await this.cartDropdown.isVisible()) {
24+
const box = await this.cartDropdown.boundingBox()
25+
if (!box) {
26+
return
27+
}
28+
await this.page.mouse.move(box.x + box.width / 4, box.y + box.height / 4)
29+
await this.page.mouse.move(5, 10)
30+
}
31+
}
32+
33+
async getCartItem(name: string, variant: string) {
34+
const cartItem = this.cartDropdown
35+
.getByTestId("cart-item")
36+
.filter({
37+
hasText: name,
38+
})
39+
.filter({
40+
hasText: `Variant: ${variant}`,
41+
})
3242
return {
3343
locator: cartItem,
3444
productLink: cartItem.getByTestId("product-link"),
3545
removeButton: cartItem.getByTestId("cart-item-remove-button"),
3646
name,
37-
quantity,
38-
variant,
47+
quantity: cartItem.getByTestId("cart-item-quantity"),
48+
variant: cartItem.getByTestId("cart-item-variant"),
3949
}
4050
}
4151
}

e2e/fixtures/cart-page.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export class CartPage extends BasePage {
2323
cartGiftCardAmount: Locator
2424
cartShipping: Locator
2525
cartTaxes: Locator
26+
cartTotal: Locator
2627
checkoutButton: Locator
2728

2829
constructor(page: Page) {
@@ -61,22 +62,23 @@ export class CartPage extends BasePage {
6162
)
6263
this.cartShipping = this.container.getByTestId("cart-shipping")
6364
this.cartTaxes = this.container.getByTestId("cart-taxes")
65+
this.cartTotal = this.container.getByTestId("cart-total")
6466
}
6567

6668
async getProduct(title: string, variant: string) {
6769
const productRow = this.productRow
6870
.filter({
69-
has: this.productTitle.filter({ hasText: title }),
71+
hasText: title,
7072
})
7173
.filter({
72-
has: this.productVariant.filter({ hasText: variant }),
74+
hasText: `Variant: ${variant}`,
7375
})
7476
return {
7577
productRow,
7678
title: productRow.getByTestId("product-title"),
7779
variant: productRow.getByTestId("product-variant"),
7880
deleteButton: productRow.getByTestId("delete-button"),
79-
quantitySelect: productRow.getByTestId("quantity-select"),
81+
quantitySelect: productRow.getByTestId("product-select-button"),
8082
price: productRow.getByTestId("product-unit-price"),
8183
total: productRow.getByTestId("product-price"),
8284
}

e2e/fixtures/product-page.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export class ProductPage extends BasePage {
99
productTitle: Locator
1010
productDescription: Locator
1111
productOptions: Locator
12+
productPrice: Locator
1213
addProductButton: Locator
1314
mobileActionsContainer: Locator
1415
mobileTitle: Locator
@@ -24,6 +25,7 @@ export class ProductPage extends BasePage {
2425
this.productTitle = this.container.getByTestId("product-title")
2526
this.productDescription = this.container.getByTestId("product-description")
2627
this.productOptions = this.container.getByTestId("product-options")
28+
this.productPrice = this.container.getByTestId("product-price")
2729
this.addProductButton = this.container.getByTestId("add-product-button")
2830
this.mobileActionsContainer = page.getByTestId("mobile-actions")
2931
this.mobileTitle = this.mobileActionsContainer.getByTestId("mobile-title")
@@ -35,10 +37,16 @@ export class ProductPage extends BasePage {
3537
)
3638
}
3739

40+
async clickAddProduct() {
41+
await this.addProductButton.click()
42+
await this.cartDropdown.cartDropdown.waitFor({ state: "visible" })
43+
}
44+
3845
async selectOption(option: string) {
46+
await this.page.mouse.move(0, 0) // hides the checkout container
3947
const optionButton = this.productOptions
4048
.getByTestId("option-button")
4149
.filter({ hasText: option })
42-
await optionButton.click()
50+
await optionButton.click({ clickCount: 2 })
4351
}
4452
}

src/lib/util/get-product-price.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,13 @@ export function getProductPrice({
3636
})
3737

3838
return {
39+
calculated_price_number: cheapestVariant.calculated_price,
3940
calculated_price: formatAmount({
4041
amount: cheapestVariant.calculated_price,
4142
region,
4243
includeTaxes: false,
4344
}),
45+
original_price_number: cheapestVariant.original_price,
4446
original_price: formatAmount({
4547
amount: cheapestVariant.original_price,
4648
region,
@@ -68,11 +70,13 @@ export function getProductPrice({
6870
}
6971

7072
return {
73+
calculated_price_number: variant.calculated_price,
7174
calculated_price: formatAmount({
7275
amount: variant.calculated_price,
7376
region,
7477
includeTaxes: false,
7578
}),
79+
original_price_number: variant.original_price,
7680
original_price: formatAmount({
7781
amount: variant.original_price,
7882
region,

src/modules/common/components/cart-totals/index.tsx

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,37 +38,57 @@ const CartTotals: React.FC<CartTotalsProps> = ({ data }) => {
3838
<InformationCircleSolid color="var(--fg-muted)" />
3939
</Tooltip>
4040
</span>
41-
<span data-testid="cart-subtotal">{getAmount(subtotal)}</span>
41+
<span data-testid="cart-subtotal" data-value={subtotal || 0}>
42+
{getAmount(subtotal)}
43+
</span>
4244
</div>
4345
{!!discount_total && (
4446
<div className="flex items-center justify-between">
4547
<span>Discount</span>
46-
<span className="text-ui-fg-interactive" data-testid="cart-discount" data-value={getAmount(discount_total)}>
48+
<span
49+
className="text-ui-fg-interactive"
50+
data-testid="cart-discount"
51+
data-value={discount_total || 0}
52+
>
4753
- {getAmount(discount_total)}
4854
</span>
4955
</div>
5056
)}
5157
{!!gift_card_total && (
5258
<div className="flex items-center justify-between">
5359
<span>Gift card</span>
54-
<span className="text-ui-fg-interactive" data-testid="cart-gift-card-amount" data-value={getAmount(gift_card_total)}>
60+
<span
61+
className="text-ui-fg-interactive"
62+
data-testid="cart-gift-card-amount"
63+
data-value={gift_card_total || 0}
64+
>
5565
- {getAmount(gift_card_total)}
5666
</span>
5767
</div>
5868
)}
5969
<div className="flex items-center justify-between">
6070
<span>Shipping</span>
61-
<span data-testid="cart-shipping">{getAmount(shipping_total)}</span>
71+
<span data-testid="cart-shipping" data-value={shipping_total || 0}>
72+
{getAmount(shipping_total)}
73+
</span>
6274
</div>
6375
<div className="flex justify-between">
6476
<span className="flex gap-x-1 items-center ">Taxes</span>
65-
<span data-testid="cart-taxes">{getAmount(tax_total)}</span>
77+
<span data-testid="cart-taxes" data-value={tax_total || 0}>
78+
{getAmount(tax_total)}
79+
</span>
6680
</div>
6781
</div>
6882
<div className="h-px w-full border-b border-gray-200 my-4" />
6983
<div className="flex items-center justify-between text-ui-fg-base mb-2 txt-medium ">
7084
<span>Total</span>
71-
<span className="txt-xlarge-plus" data-testid="cart-taxes">{getAmount(total)}</span>
85+
<span
86+
className="txt-xlarge-plus"
87+
data-testid="cart-total"
88+
data-value={total || 0}
89+
>
90+
{getAmount(total)}
91+
</span>
7292
</div>
7393
<div className="h-px w-full border-b border-gray-200 mt-4" />
7494
</div>

src/modules/layout/components/cart-dropdown/index.tsx

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,17 @@ const CartDropdown = ({
133133
{item.title}
134134
</LocalizedClientLink>
135135
</h3>
136-
<LineItemOptions variant={item.variant} data-testid="cart-item-variant" data-value={item.variant} />
137-
<span data-testid="cart-item-quantity" data-value={item.quantity}>Quantity: {item.quantity}</span>
136+
<LineItemOptions
137+
variant={item.variant}
138+
data-testid="cart-item-variant"
139+
data-value={item.variant}
140+
/>
141+
<span
142+
data-testid="cart-item-quantity"
143+
data-value={item.quantity}
144+
>
145+
Quantity: {item.quantity}
146+
</span>
138147
</div>
139148
<div className="flex justify-end">
140149
<LineItemPrice
@@ -145,7 +154,11 @@ const CartDropdown = ({
145154
</div>
146155
</div>
147156
</div>
148-
<DeleteButton id={item.id} className="mt-1" data-testid="cart-item-remove-button">
157+
<DeleteButton
158+
id={item.id}
159+
className="mt-1"
160+
data-testid="cart-item-remove-button"
161+
>
149162
Remove
150163
</DeleteButton>
151164
</div>
@@ -158,7 +171,11 @@ const CartDropdown = ({
158171
Subtotal{" "}
159172
<span className="font-normal">(excl. taxes)</span>
160173
</span>
161-
<span className="text-large-semi" data-testid="cart-subtotal">
174+
<span
175+
className="text-large-semi"
176+
data-testid="cart-subtotal"
177+
data-value={cartState.subtotal || 0}
178+
>
162179
{formatAmount({
163180
amount: cartState.subtotal || 0,
164181
region: cartState.region,
@@ -167,7 +184,11 @@ const CartDropdown = ({
167184
</span>
168185
</div>
169186
<LocalizedClientLink href="/cart" passHref>
170-
<Button className="w-full" size="large" data-testid="go-to-cart-button">
187+
<Button
188+
className="w-full"
189+
size="large"
190+
data-testid="go-to-cart-button"
191+
>
171192
Go to cart
172193
</Button>
173194
</LocalizedClientLink>

src/modules/products/components/product-price/index.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,24 @@ export default function ProductPrice({
3636
})}
3737
>
3838
{!variant && "From "}
39-
{selectedPrice.calculated_price}
39+
<span
40+
data-testid="product-price"
41+
data-value={selectedPrice.calculated_price_number}
42+
>
43+
{selectedPrice.calculated_price}
44+
</span>
4045
</span>
4146
{selectedPrice.price_type === "sale" && (
4247
<>
4348
<p>
4449
<span className="text-ui-fg-subtle">Original: </span>
45-
<span className="line-through">{selectedPrice.original_price}</span>
50+
<span
51+
className="line-through"
52+
data-testid="original-product-price"
53+
data-value={selectedPrice.original_price_number}
54+
>
55+
{selectedPrice.original_price}
56+
</span>
4657
</p>
4758
<span className="text-ui-fg-interactive">
4859
-{selectedPrice.percentage_diff}%

0 commit comments

Comments
 (0)