acupedia-store-ui/tests/e2e/cart-currency-coupons.spec.ts

66 lines
2.7 KiB
TypeScript

import { test, expect } from '@playwright/test';
import { mockAuthenticatedUser, mockPublicStoreApis } from './fixtures/apiMocks';
test.describe('Cart, Multi-Currency & Coupons', () => {
test('adds/removes items and enforces Complete Pack and Lifetime bundle rules', async ({ page }) => {
await mockPublicStoreApis(page);
await page.goto('./');
// Add individual Points: Acu
await page.getByText('Acu (EOV+Cat+Ext+MR)').click();
await expect(page.getByText('1 Item')).toBeVisible();
// Selecting Points Complete Pack replaces individual Points: Acu
await page.locator('span', { hasText: /^Complete Pack$/ }).first().click();
await expect(page.getByText('1 Item')).toBeVisible();
await expect(page.getByText('Points: Complete Pack')).toBeVisible();
// Selecting Lifetime Pass replaces everything else in cart
await page.getByText('Lifetime Unlimited Access Pass').nth(1).click();
await expect(page.getByText('1 Item')).toBeVisible();
await expect(page.getByText('Lifetime Unlimited Access Pass').last()).toBeVisible();
// Remove item via trash button in CartDrawer
await page.getByTitle('Remove item').click();
await expect(page.getByText('0 Items')).toBeVisible();
await expect(page.getByText('Your checkout cart is empty.')).toBeVisible();
});
test('applies valid coupon, handles invalid coupon, and removes coupon', async ({ page }) => {
await mockPublicStoreApis(page);
await page.goto('./');
await page.getByText('Acu (EOV+Cat+Ext+MR)').click();
await expect(page.getByText('Base Subtotal')).toBeVisible();
const couponInput = page.getByPlaceholder('e.g. AGENT40, EVENT_NEW');
await couponInput.fill('SAVE20');
await page.getByRole('button', { name: 'Apply' }).click();
await expect(page.getByText(/Coupon Active: SAVE20/)).toBeVisible();
await expect(page.getByText('Coupon Discount (SAVE20)')).toBeVisible();
// Remove coupon
await page.getByRole('button', { name: 'Remove', exact: true }).click();
await expect(page.getByText(/Coupon Active: SAVE20/)).not.toBeVisible();
// Try invalid coupon
await couponInput.fill('BADCODE');
await page.getByRole('button', { name: 'Apply' }).click();
await expect(page.getByText(/Invalid or expired coupon code/i)).toBeVisible();
});
test('displays EUR pricing without GST for European user', async ({ page }) => {
await mockPublicStoreApis(page);
await mockAuthenticatedUser(page, {
country: 'Germany',
phone_number: '+4915123456789',
});
await page.goto('./');
await expect(page.getByText('Billing Currency:')).toBeVisible();
await page.getByText('Acu (EOV+Cat+Ext+MR)').click();
await expect(page.getByText('€5').first()).toBeVisible();
});
});