import { describe, it, expect, vi } from 'vitest'; import { render, screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import { LoggedOutView } from '../../../src/components/auth/LoggedOutView'; import { PasswordUpdatedModal } from '../../../src/components/auth/PasswordUpdatedModal'; import { StoreFooter } from '../../../src/components/layout/StoreFooter'; import { StoreHeader } from '../../../src/components/layout/StoreHeader'; import { LifetimeBanner } from '../../../src/components/catalog/LifetimeBanner'; describe('Layout & Simple View Components', () => { it('LoggedOutView renders /store prefix and triggers onLoginAgain on both links', async () => { const user = userEvent.setup(); const onLoginAgain = vi.fn(); window.history.pushState({}, '', '/store/'); render(); expect(screen.getByText('Successfully Logged Out')).toBeInTheDocument(); const links = screen.getAllByRole('link'); expect(links[0]).toHaveAttribute('href', '/store/?login=true'); await user.click(links[0]); await user.click(links[1]); expect(onLoginAgain).toHaveBeenCalledTimes(2); }); it('PasswordUpdatedModal renders when open, handles custom props and close, and returns null when closed', async () => { const user = userEvent.setup(); const onClose = vi.fn(); const { rerender } = render(); expect(screen.queryByText('Password Updated!')).not.toBeInTheDocument(); rerender( ); expect(screen.getByText('Custom Title')).toBeInTheDocument(); await user.click(screen.getByRole('button', { name: 'Done' })); expect(onClose).toHaveBeenCalledTimes(1); }); it('StoreFooter and LifetimeBanner render expected branding', () => { render( <> ); expect(screen.getByText(/Acupedia Systems/i)).toBeInTheDocument(); expect(screen.getByText('LIFETIME ACCESS PASSPORT ACTIVE!')).toBeInTheDocument(); }); it('StoreHeader handles unauthenticated and authenticated states and navigation tabs', async () => { const user = userEvent.setup(); const onSwitchTab = vi.fn(); const onOpenProfile = vi.fn(); const onOpenAuth = vi.fn(); const { rerender } = render( ); await user.click(screen.getByRole('button', { name: /Login/i })); await user.click(screen.getByRole('button', { name: /Join/i })); expect(onOpenAuth).toHaveBeenNthCalledWith(1, 'login'); expect(onOpenAuth).toHaveBeenNthCalledWith(2, 'register'); await user.click(screen.getByText('ACUPEDIA')); expect(onSwitchTab).toHaveBeenCalledWith('storefront'); const storeBtns = screen.getAllByRole('button', { name: /Storefront/i }); const subBtns = screen.getAllByRole('button', { name: /My Subscriptions/i }); await user.click(storeBtns[1]); await user.click(subBtns[0]); await user.click(subBtns[1]); expect(onSwitchTab).toHaveBeenCalledWith('subscriptions'); rerender( ); await user.click(screen.getByText('Dr. Lin')); expect(onOpenProfile).toHaveBeenCalledTimes(1); }); });