Skip to content

test: refactor discount e2e tests#3515

Merged
itsjustriley merged 11 commits intomainfrom
refactor-skeleton-discount
Mar 2, 2026
Merged

test: refactor discount e2e tests#3515
itsjustriley merged 11 commits intomainfrom
refactor-skeleton-discount

Conversation

@itsjustriley
Copy link
Copy Markdown
Contributor

@itsjustriley itsjustriley commented Feb 26, 2026

Part of https://github.com/Shopify/developer-tools-team/issues/1075

Referring to Freddie's example test, this refactors e2e discount tests and improves skeleton accessibility.

Note: duplicates some of freddie's work (skeleton accessibility updates, base utils) so will need to be rebased

  • makes tests less smart (no dynamically choosing selectors - uses accessibility features)
  • simple utils
  • assumes stable products

To validate tests pass locally: npx playwright test e2e/specs/skeleton/discounts.spec.ts (use --ui flag if desired)

@shopify
Copy link
Copy Markdown
Contributor

shopify Bot commented Feb 26, 2026

Oxygen deployed a preview of your refactor-skeleton-discount branch. Details:

Storefront Status Preview link Deployment details Last update (UTC)
Skeleton (skeleton.hydrogen.shop) ✅ Successful (Logs) Preview deployment Inspect deployment March 2, 2026 6:59 PM

Learn more about Hydrogen's GitHub integration.

@itsjustriley itsjustriley force-pushed the refactor-skeleton-discount branch 3 times, most recently from c0aad6c to 32e6470 Compare February 26, 2026 18:02
Comment thread e2e/specs/skeleton/discounts.spec.ts Outdated
@andguy95 andguy95 mentioned this pull request Feb 26, 2026
@itsjustriley itsjustriley force-pushed the refactor-skeleton-discount branch from 3e3a075 to 807256d Compare February 27, 2026 17:02
@itsjustriley itsjustriley marked this pull request as ready for review February 27, 2026 18:07
@itsjustriley itsjustriley requested a review from a team as a code owner February 27, 2026 18:07
Comment thread templates/skeleton/app/components/CartSummary.tsx Outdated
@binks-code-reviewer
Copy link
Copy Markdown

binks-code-reviewer Bot commented Feb 27, 2026

🤖 Code Review · #projects-dev-ai for questions
React with 👍/👎 or reply — all feedback helps improve the agent.

🚫 PR closed

📋 History

✅ 1 findings → ✅ 1 findings → ✅ No issues → ✅ 2 findings → ✅ No issues → ✅ No issues → 🚫 PR closed

Comment thread e2e/fixtures/cart-utils.ts
Comment thread e2e/fixtures/cart-utils.ts
Comment thread e2e/fixtures/cart-utils.ts Outdated
Comment thread e2e/fixtures/cart-utils.ts Outdated
Comment thread e2e/fixtures/cart-utils.ts Outdated
Comment thread e2e/fixtures/cart-utils.ts Outdated
@itsjustriley itsjustriley requested a review from fredericoo March 2, 2026 14:09
Comment thread templates/skeleton/app/components/CartSummary.tsx
Comment thread e2e/fixtures/discount-utils.ts
@itsjustriley itsjustriley force-pushed the refactor-skeleton-discount branch from 64f9684 to f751d84 Compare March 2, 2026 14:30
Comment thread templates/skeleton/app/components/CartMain.tsx
Comment thread templates/skeleton/app/components/CartSummary.tsx
export function CartSummary({cart, layout}: CartSummaryProps) {
const className =
layout === 'page' ? 'cart-summary-page' : 'cart-summary-aside';
const summaryId = useId();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: the old code had aria-labelledby="cart-summary" on the container but the referenced id="cart-summary" was missing from the <h4> - so the aria-labelledby was broken. Using useId() both fixes this broken reference and prevents duplicate IDs when multiple cart summaries render on the same page. nice catch and fix.

Comment thread templates/skeleton/app/components/CartSummary.tsx
Comment thread e2e/fixtures/cart-utils.ts
const appliedCodes = await storefront.getAppliedDiscountCodes();
expect(appliedCodes).not.toContain(inactiveDiscountCode);
await discount.assertNoDiscounts();
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

non-blocking: this test accesses page.getByLabel('Discounts') and getByRole('group') directly instead of using DiscountUtil. The whole point of the refactor is centralizing selectors. I think this logic should be encapsulated as a new method on DiscountUtil (e.g., assertDiscountCount(n)) for consistency.

await cart.addItem(PRODUCT_NAME);
await cart.closeCartAside();
await cart.navigateToCartPage();
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

non-blocking: the old version computed subtotalBefore - subtotalAfter === 10, verifying the exact discount amount regardless of product price. The new version hardcodes both prices. Both approaches hardcode assumptions about the discount amount (the old toBe(10) is equally a magic number), but the new version requires updating two interdependent constants if the product price changes. I think at minimum a comment would help: // Product: $749.95, discount: $10.00 off, expected: $739.95

setTestStore('mockShop');

const PRODUCT_NAME = "Women's T-shirt";
const PRODUCT_HANDLE = 'women-t-shirt';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: switching from "go to home, find product, click" to page.goto('/products/${PRODUCT_HANDLE}') is a good simplification - tests are faster and more focused on cart behavior.

await page.getByRole('button', {name: 'Add to cart'}).click();
await page.goto(`/products/${productHandle}`);
await cart.addItem(productName);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the removed comment // Validate that the backend has returned the correct subtotal explained that assertSubtotal verifies backend state, not just UI. I think we should keep that comment or something equivalent - it's a "why" comment that helps future readers understand intent.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We validate the back end state in the addItem util now, which I think is self-documenting.

@@ -853,7 +853,7 @@ export class StorefrontPage {
async openCartAside(): Promise<void> {
const cartLink = this.page
.getByRole('banner')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: /cart/i to 'Cart' is good - exact matches are more precise. Note that Playwright's getByRole({name: 'Cart'}) uses substring matching by default, so if the cart link text includes a badge count (e.g., "Cart 2"), it would still match. This should be safe.

@itsjustriley itsjustriley force-pushed the refactor-skeleton-discount branch from 61da714 to c1759db Compare March 2, 2026 18:09
@itsjustriley itsjustriley requested a review from kdaviduik March 2, 2026 18:29
@itsjustriley itsjustriley merged commit ea01a39 into main Mar 2, 2026
15 checks passed
@itsjustriley itsjustriley deleted the refactor-skeleton-discount branch March 2, 2026 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants