Full tests coverage
This commit is contained in:
parent
99134d8556
commit
02d782c3da
157 changed files with 1074 additions and 34670 deletions
|
|
@ -20,12 +20,12 @@ vi.mock('next/link', () => ({
|
|||
|
||||
vi.mock('@/lib/useApi', () => ({ useApi: mockUseApi }));
|
||||
|
||||
import { Sidebar } from '../../src/components/layout/Sidebar';
|
||||
import { Sidebar, NAV } from '../../src/components/layout/Sidebar';
|
||||
|
||||
describe('Sidebar', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
mockUsePathname.mockReturnValue('/dashboard');
|
||||
mockUsePathname.mockReturnValue('/shopping-lists');
|
||||
mockUseApi.mockReturnValue({ profile: { displayName: 'Alice' } });
|
||||
});
|
||||
|
||||
|
|
@ -34,33 +34,17 @@ describe('Sidebar', () => {
|
|||
expect(screen.getByText('MeshiTrack')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders navigation sections', () => {
|
||||
it('renders active nav items', () => {
|
||||
render(<Sidebar />);
|
||||
expect(screen.getByText('Dashboard')).toBeInTheDocument();
|
||||
expect(screen.getByText('Medicines')).toBeInTheDocument();
|
||||
expect(screen.getByText('Food')).toBeInTheDocument();
|
||||
expect(screen.getByText('Settings')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders medicines nav items', () => {
|
||||
render(<Sidebar />);
|
||||
expect(screen.getByText('Cabinet')).toBeInTheDocument();
|
||||
expect(screen.getByText('Schedule & Log')).toBeInTheDocument();
|
||||
expect(screen.getByText('Regimens')).toBeInTheDocument();
|
||||
expect(screen.getByText('Library')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders food nav items', () => {
|
||||
render(<Sidebar />);
|
||||
expect(screen.getByText('Recipes')).toBeInTheDocument();
|
||||
expect(screen.getByText('Pantry')).toBeInTheDocument();
|
||||
expect(screen.getByText('Shopping Lists')).toBeInTheDocument();
|
||||
expect(screen.getByText('Stores')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('highlights active route', () => {
|
||||
mockUsePathname.mockReturnValue('/medicines/cabinet');
|
||||
mockUsePathname.mockReturnValue('/shopping-lists');
|
||||
render(<Sidebar />);
|
||||
const cabinetLink = screen.getByText('Cabinet').closest('a');
|
||||
expect(cabinetLink).toHaveAttribute('href', '/medicines/cabinet');
|
||||
const link = screen.getByText('Shopping Lists').closest('a');
|
||||
expect(link).toHaveAttribute('href', '/shopping-lists');
|
||||
});
|
||||
|
||||
it('shows user avatar with display name', () => {
|
||||
|
|
@ -75,10 +59,17 @@ describe('Sidebar', () => {
|
|||
});
|
||||
|
||||
it('highlights nested route', () => {
|
||||
mockUsePathname.mockReturnValue('/medicines/cabinet/some-id');
|
||||
mockUsePathname.mockReturnValue('/shopping-lists/some-id');
|
||||
render(<Sidebar />);
|
||||
// Cabinet link should still match via startsWith
|
||||
const cabinetLink = screen.getByText('Cabinet').closest('a');
|
||||
expect(cabinetLink).toBeInTheDocument();
|
||||
const link = screen.getByText('Shopping Lists').closest('a');
|
||||
expect(link).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders item badge when present', () => {
|
||||
NAV.push({ id: 'test-badge', label: 'Test Badge', href: '/test-badge', icon: 'bell', badge: 5, section: 'Test Section' });
|
||||
render(<Sidebar />);
|
||||
expect(screen.getByText('5')).toBeInTheDocument();
|
||||
expect(screen.getByText('Test Section')).toBeInTheDocument();
|
||||
NAV.pop(); // Clean up NAV list mutation
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue