acupedia-store-ui/tests/e2e/catalog.spec.ts

131 lines
4.6 KiB
TypeScript

import { test, expect } from '@playwright/test';
import { MOCK_PLANS, mockAuthenticatedUser, mockPublicStoreApis } from './fixtures/apiMocks';
test.describe('Catalog Section', () => {
test('renders custom curated bundles when admin plan exists', async ({ page }) => {
await mockPublicStoreApis(page);
await page.route('**/api/plans', async (route) => {
await route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify([
...MOCK_PLANS,
{
code: 'SUMMER_COMBO',
name: 'Summer Special Combo',
description: 'Special combo of Acupoints and Nutrition',
plan_type: 'bundle',
billing_period: 'yearly',
price_inr: 700,
price_usd: 15,
price_eur: 15,
is_active: true,
badge_text: 'Limited Offer',
heading: 'Special Curated Bundles',
subtitle: 'Hand-picked bundles',
modules: [
{ slug: 'acupuncture-points', name: 'Acupuncture Points' },
{ slug: 'nutrition', name: 'Nutrition' },
],
module_slugs: ['acupuncture-points', 'nutrition'],
},
]),
});
});
await page.goto('./');
await expect(page.getByText('Special Curated Bundles')).toBeVisible();
await expect(page.getByText('Summer Special Combo')).toBeVisible();
await expect(page.getByText('Limited Offer').first()).toBeVisible();
});
test('toggles Hide Locked / Show Locked and marks unlocked modules as UNLOCKED', async ({ page }) => {
await mockPublicStoreApis(page);
await mockAuthenticatedUser(page, {
unlocked_module_codes: ['POINTS_ACU'],
active_subscriptions: [
{
id: 'sub-1',
plan_code: 'POINTS_ACU',
status: 'active',
started_at: '2026-01-01T00:00:00Z',
expires_at: '2027-01-01T00:00:00Z',
},
],
});
await page.goto('./');
// POINTS_ACU should display UNLOCKED badge
await expect(page.getByText('UNLOCKED').first()).toBeVisible();
// Hide Locked for Points card -> hides locked items but keeps UNLOCKED item visible
const hideLockedBtn = page.getByRole('button', { name: /Hide Locked/i }).first();
await hideLockedBtn.click();
await expect(page.getByRole('button', { name: /Show Locked/i }).first()).toBeVisible();
await expect(page.getByText('Acu (EOV+Cat+Ext+MR)')).toBeVisible();
await expect(page.getByText('Ear / Auricular')).not.toBeVisible();
// Show Locked restores them
await page.getByRole('button', { name: /Show Locked/i }).first().click();
await expect(page.getByText('Ear / Auricular')).toBeVisible();
});
test('hides inactive locked plans from the catalog', async ({ page }) => {
await mockPublicStoreApis(page);
await page.route('**/api/plans', async (route) => {
const updated = MOCK_PLANS.map((p) =>
p.code === 'POINTS_SCALP' ? { ...p, is_active: false } : p
);
await route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify(updated),
});
});
await page.goto('./');
await expect(page.getByText('Acu (EOV+Cat+Ext+MR)')).toBeVisible();
await expect(page.getByText('Scalp', { exact: true })).not.toBeVisible();
});
test('renders newly activated Module Builder plan in its category and supports ?planCode deep link', async ({ page }) => {
await mockPublicStoreApis(page);
await page.route('**/api/plans', async (route) => {
await route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify([
...MOCK_PLANS,
{
code: 'MOD_M0044',
base_code: 'MOD_M0044',
name: 'Pediatric Disorders',
description: 'TCM pediatric treatment protocols.',
plan_type: 'one_time',
billing_period: 'yearly',
price_inr: 600,
price_usd: 15,
price_eur: 15,
is_active: true,
modules: [
{
code: 'm0044',
slug: 'pediatric-disorders',
name: 'Pediatric Disorders',
description: 'TCM pediatric treatment protocols.',
category: 'Therapeutics',
sort_order: 40,
},
],
},
]),
});
});
await page.goto('./?planCode=MOD_M0044');
await expect(page.getByText('Pediatric Disorders').first()).toBeVisible();
await expect(page.getByText('1 Item')).toBeVisible();
});
});