108 lines
3.9 KiB
TypeScript
108 lines
3.9 KiB
TypeScript
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(<LoggedOutView onLoginAgain={onLoginAgain} />);
|
|
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(<PasswordUpdatedModal isOpen={false} onClose={onClose} />);
|
|
expect(screen.queryByText('Password Updated!')).not.toBeInTheDocument();
|
|
|
|
rerender(
|
|
<PasswordUpdatedModal
|
|
isOpen={true}
|
|
onClose={onClose}
|
|
title="Custom Title"
|
|
description="Custom Desc"
|
|
buttonText="Done"
|
|
/>
|
|
);
|
|
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(
|
|
<>
|
|
<StoreFooter />
|
|
<LifetimeBanner />
|
|
</>
|
|
);
|
|
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(
|
|
<StoreHeader
|
|
activeTab="storefront"
|
|
onSwitchTab={onSwitchTab}
|
|
loggedInUser={null}
|
|
onOpenProfile={onOpenProfile}
|
|
onOpenAuth={onOpenAuth}
|
|
/>
|
|
);
|
|
|
|
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(
|
|
<StoreHeader
|
|
activeTab="subscriptions"
|
|
onSwitchTab={onSwitchTab}
|
|
loggedInUser={{
|
|
id: 1,
|
|
email: 'doc@acupedia.com',
|
|
display_name: 'Dr. Lin',
|
|
country: 'India',
|
|
active_subscriptions: [{ id: 1, plan_code: 'POINTS_ACU', status: 'ACTIVE', started_at: '', expires_at: '' }],
|
|
} as any}
|
|
onOpenProfile={onOpenProfile}
|
|
onOpenAuth={onOpenAuth}
|
|
/>
|
|
);
|
|
|
|
await user.click(screen.getByText('Dr. Lin'));
|
|
expect(onOpenProfile).toHaveBeenCalledTimes(1);
|
|
});
|
|
});
|