import { describe, it, expect, vi } from 'vitest'; import { render, screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import { SubscriptionsView } from '../../../src/components/subscriptions/SubscriptionsView'; describe('SubscriptionsView', () => { it('renders unauthenticated prompt and opens auth modal on click', async () => { const user = userEvent.setup(); const onOpenAuth = vi.fn(); render( ); await user.click(screen.getByRole('button', { name: 'Log In' })); expect(onOpenAuth).toHaveBeenCalledTimes(1); }); it('renders empty state and navigates to catalog', async () => { const user = userEvent.setup(); const onSwitchTab = vi.fn(); render( ); await user.click(screen.getByRole('button', { name: 'Explore Modules Catalog' })); expect(onSwitchTab).toHaveBeenCalledWith('storefront'); }); it('renders active, lifetime, expired, and paginated subscriptions with invoice download', async () => { const user = userEvent.setup(); const onDownloadInvoice = vi.fn(); const future = new Date(Date.now() + 30 * 86400000).toISOString(); const past = new Date(Date.now() - 5 * 86400000).toISOString(); const subs = [ { id: 1, plan_code: 'LIFETIME_ALL', status: 'ACTIVE', started_at: '2026-01-01', expires_at: '', payment_id: 'p1', invoice_number: 'INV-1' }, { id: 2, plan_code: 'POINTS_ACU', status: 'ACTIVE', started_at: '2026-01-01', expires_at: past, payment_id: 'p2' }, ...Array.from({ length: 5 }, (_, i) => ({ id: i + 3, plan_code: `MOD_${i}`, status: 'ACTIVE', started_at: '2026-01-01', expires_at: future, })), ]; render( ); expect(screen.getByText('Lifetime Access')).toBeInTheDocument(); expect(screen.getByText('Expired')).toBeInTheDocument(); await user.click(screen.getAllByRole('button', { name: /Download Invoice/i })[0]); expect(onDownloadInvoice).toHaveBeenCalledWith('p1', undefined); await user.click(screen.getByRole('button', { name: '2' })); expect(screen.getByText('MOD 4')).toBeInTheDocument(); }); });