import type { ReactNode } from 'react' import { fireEvent, render, screen } from '@testing-library/react' import MainNavLayout from '../layout' vi.mock('@/app/components/header', () => ({ default: () =>
Header
, })) vi.mock('@/app/components/header/header-wrapper', () => ({ default: ({ children }: { children: ReactNode }) =>
{children}
, })) vi.mock('react-i18next', () => ({ useTranslation: () => ({ t: (key: string) => key, }), })) vi.mock('../index', () => ({ default: ({ className }: { className?: string }) => , })) describe('MainNavLayout', () => { beforeEach(() => { localStorage.clear() }) it('renders desktop main nav instead of the desktop header', () => { render(
content
) expect(screen.getByTestId('main-nav')).toBeInTheDocument() expect(screen.queryByTestId('desktop-header')).not.toBeInTheDocument() expect(screen.getByText('content')).toBeInTheDocument() }) it('uses the main nav without the desktop header wrapper', () => { render(
content
) expect(screen.getByTestId('main-nav')).toBeInTheDocument() expect(screen.queryByTestId('header-wrapper')).not.toBeInTheDocument() expect(screen.queryByTestId('desktop-header')).not.toBeInTheDocument() }) it('renders one main landmark as the skip navigation target', () => { render(
content
) const main = screen.getByRole('main') expect(screen.getAllByRole('main')).toHaveLength(1) expect(main).toHaveAttribute('id', 'main-content') expect(main).toHaveAttribute('tabIndex', '-1') expect(main).toHaveClass('outline-hidden', 'focus:outline-hidden', 'focus-visible:outline-hidden') expect(main).toHaveTextContent('content') }) it('renders skip navigation before the repeated main navigation', () => { const { container } = render(
content
) const skipLink = screen.getByRole('link', { name: 'navigation.skipToMain' }) expect(skipLink).toHaveAttribute('href', '#main-content') expect(skipLink).toHaveClass('outline-hidden', 'focus-visible:ring-2', 'focus-visible:ring-state-accent-solid') expect(container.querySelector('a, button, input, select, textarea, [tabindex]:not([tabindex="-1"])')).toBe(skipLink) }) it('moves focus to the main content when skip navigation is activated', () => { render(
content
) const skipLink = screen.getByRole('link', { name: 'navigation.skipToMain' }) const main = screen.getByRole('main') fireEvent.click(skipLink) expect(main).toHaveFocus() }) })