111 lines
3.7 KiB
TypeScript
111 lines
3.7 KiB
TypeScript
import { describe, it, expect, vi } from 'vitest';
|
|
import { render, screen } from '@testing-library/react';
|
|
import userEvent from '@testing-library/user-event';
|
|
import { CatalogSection } from '../../../src/components/catalog/CatalogSection';
|
|
import { CURRICULUM_MODULES } from '../../../src/constants/modules';
|
|
|
|
describe('CatalogSection', () => {
|
|
const defaultProps = {
|
|
curriculumModules: CURRICULUM_MODULES,
|
|
publicPlans: [
|
|
{
|
|
code: 'LIFETIME_ALL',
|
|
name: 'Lifetime All-Access Plan',
|
|
description: '10 Years access',
|
|
plan_type: 'bundle' as const,
|
|
billing_period: 'lifetime' as const,
|
|
price_inr: 15000,
|
|
price_usd: 350,
|
|
price_eur: 350,
|
|
is_active: true,
|
|
module_slugs: ['acupuncture-points'],
|
|
},
|
|
{
|
|
code: 'CUSTOM_CURATED_1',
|
|
name: 'Summer Clinical Bundle',
|
|
description: 'Curated clinical pack',
|
|
plan_type: 'bundle' as const,
|
|
billing_period: 'yearly' as const,
|
|
price_inr: 2500,
|
|
price_usd: 45,
|
|
price_eur: 45,
|
|
is_active: true,
|
|
module_slugs: ['acupuncture-points', 'nutrition'],
|
|
modules: [{ slug: 'acupuncture-points', name: 'Acupuncture Points' }],
|
|
},
|
|
],
|
|
cart: [CURRICULUM_MODULES[0]],
|
|
currency: 'INR' as const,
|
|
isModuleUnlocked: (code: string) => code === 'POINTS_SCALP',
|
|
getModulePrice: (item: any) => ({
|
|
priceInr: item.priceInr,
|
|
priceUsd: item.priceUsd,
|
|
priceEur: item.priceEur,
|
|
isActive: item.code !== 'POINTS_EAR',
|
|
}),
|
|
toggleCartItem: vi.fn(),
|
|
showLockedByCategory: {
|
|
Points: true,
|
|
Pattern: true,
|
|
Nutrition: true,
|
|
Therapeutics: true,
|
|
Bundles: true,
|
|
},
|
|
setShowLockedByCategory: vi.fn(),
|
|
};
|
|
|
|
it('renders categories, custom curated bundles, unlocked badges, and handles toggles & cart clicks', async () => {
|
|
const user = userEvent.setup();
|
|
render(<CatalogSection {...defaultProps} />);
|
|
|
|
expect(screen.getByText('Points Reference Module')).toBeInTheDocument();
|
|
expect(screen.getByText('Summer Clinical Bundle')).toBeInTheDocument();
|
|
expect(screen.getAllByText('UNLOCKED').length).toBeGreaterThan(0);
|
|
|
|
// Inactive locked module POINTS_EAR is hidden
|
|
expect(screen.queryByText('Ear (EOV+Cat+Ext+MR)')).not.toBeInTheDocument();
|
|
|
|
// Click module item & custom bundle & lifetime pass
|
|
await user.click(screen.getByText('Acu (EOV+Cat+Ext+MR)'));
|
|
expect(defaultProps.toggleCartItem).toHaveBeenCalled();
|
|
|
|
await user.click(screen.getByText('Summer Clinical Bundle'));
|
|
expect(defaultProps.toggleCartItem).toHaveBeenCalledTimes(2);
|
|
|
|
// Click Complete Pack badges across categories
|
|
const completePacks = screen.getAllByText('Complete Pack');
|
|
for (const cp of completePacks) {
|
|
await user.click(cp);
|
|
}
|
|
|
|
// Toggle Hide Locked across all categories
|
|
const hideButtons = screen.getAllByRole('button', { name: /Hide Locked/i });
|
|
for (const btn of hideButtons) {
|
|
await user.click(btn);
|
|
}
|
|
expect(defaultProps.setShowLockedByCategory).toHaveBeenCalledTimes(hideButtons.length);
|
|
});
|
|
|
|
it('renders hidden locked empty states and EUR/USD pricing', async () => {
|
|
const user = userEvent.setup();
|
|
render(
|
|
<CatalogSection
|
|
{...defaultProps}
|
|
currency="EUR"
|
|
isModuleUnlocked={() => false}
|
|
showLockedByCategory={{
|
|
Points: false,
|
|
Pattern: false,
|
|
Nutrition: false,
|
|
Therapeutics: false,
|
|
Bundles: false,
|
|
}}
|
|
/>
|
|
);
|
|
|
|
expect(screen.getAllByText('Locked modules are currently hidden.').length).toBeGreaterThan(0);
|
|
await user.click(screen.getAllByRole('button', { name: /Show Locked/i })[0]);
|
|
expect(defaultProps.setShowLockedByCategory).toHaveBeenCalled();
|
|
});
|
|
});
|