86 lines
3.4 KiB
TypeScript
86 lines
3.4 KiB
TypeScript
import { test, expect } from '@playwright/test';
|
|
import { mockPublicStoreApis, mockAuthenticatedUser } from './fixtures/apiMocks';
|
|
|
|
test.describe('Phase 4: Subscriptions & Entitlements View', () => {
|
|
test.beforeEach(async ({ page }) => {
|
|
await mockPublicStoreApis(page);
|
|
});
|
|
|
|
test('unauthenticated user sees login prompt on Subscriptions tab', async ({ page }) => {
|
|
await page.goto('./');
|
|
await page.getByRole('button', { name: /Subscriptions/i }).first().click();
|
|
|
|
await expect(page.getByText('Please register or log in to view active entitlements.')).toBeVisible();
|
|
await page.getByRole('button', { name: 'Log In' }).click();
|
|
await expect(page.getByText('Welcome Back!')).toBeVisible();
|
|
});
|
|
|
|
test('authenticated user with no subscriptions sees empty state and can return to catalog', async ({ page }) => {
|
|
await mockAuthenticatedUser(page, { active_subscriptions: [] });
|
|
|
|
await page.goto('./');
|
|
await page.getByRole('button', { name: /Subscriptions/i }).first().click();
|
|
|
|
await expect(page.getByText('No active subscriptions')).toBeVisible();
|
|
await page.getByRole('button', { name: 'Explore Modules Catalog' }).click();
|
|
await expect(page.getByText('Acu (EOV+Cat+Ext+MR)')).toBeVisible();
|
|
});
|
|
|
|
test('populated subscriptions list renders passes, pagination, and invoice download', async ({ page }) => {
|
|
const futureDate = new Date(Date.now() + 180 * 24 * 60 * 60 * 1000).toISOString();
|
|
const tenYearsDate = new Date(Date.now() + 3650 * 24 * 60 * 60 * 1000).toISOString();
|
|
|
|
const subs = [
|
|
{
|
|
id: 1,
|
|
plan_code: 'LIFETIME_ALL',
|
|
status: 'ACTIVE',
|
|
started_at: '2026-01-01T00:00:00Z',
|
|
expires_at: tenYearsDate,
|
|
payment_id: 'pay_sub_1',
|
|
invoice_number: 'INV-2026-0001',
|
|
invoice_url: '/api/checkout/payment/pay_sub_1/invoice/view',
|
|
},
|
|
...Array.from({ length: 6 }, (_, i) => ({
|
|
id: i + 2,
|
|
plan_code: `MODULE_${i + 2}`,
|
|
status: 'ACTIVE',
|
|
started_at: '2026-02-01T00:00:00Z',
|
|
expires_at: futureDate,
|
|
payment_id: `pay_sub_${i + 2}`,
|
|
invoice_number: `INV-2026-000${i + 2}`,
|
|
invoice_url: `/api/checkout/payment/pay_sub_${i + 2}/invoice/view`,
|
|
})),
|
|
];
|
|
|
|
await page.addInitScript(() => {
|
|
(window as any).__openedUrls = [];
|
|
window.open = ((url: string) => {
|
|
(window as any).__openedUrls.push(url);
|
|
return null;
|
|
}) as any;
|
|
});
|
|
|
|
await mockAuthenticatedUser(page, {
|
|
active_subscriptions: subs,
|
|
unlocked_module_codes: subs.map((s) => s.plan_code),
|
|
});
|
|
|
|
await page.goto('./');
|
|
await page.getByRole('button', { name: /Subscriptions/i }).first().click();
|
|
|
|
// First page shows 6 items, including LIFETIME_ALL ("10 Years Pass")
|
|
await expect(page.getByText('10 Years Pass')).toBeVisible();
|
|
await expect(page.getByText('INV-2026-0001')).toBeVisible();
|
|
|
|
// Click Download Invoice on first card
|
|
await page.getByRole('button', { name: 'Download Invoice' }).first().click();
|
|
const openedUrls = await page.evaluate(() => (window as any).__openedUrls);
|
|
expect(openedUrls.some((u: string) => u.includes('/api/checkout/payment/pay_sub_1/invoice/view'))).toBe(true);
|
|
|
|
// Pagination is visible since totalCount = 7 > 6
|
|
await page.getByRole('button', { name: '2', exact: true }).click();
|
|
await expect(page.getByText('INV-2026-0007')).toBeVisible();
|
|
});
|
|
});
|