/* eslint-disable import-x/order */ /** * Tests for the locale-aware 404 Not Found page. * Located at app/[locale]/not-found.tsx — uses next-intl and @/i18n/navigation. */ import { render, screen } from '@testing-library/react'; import * as React from 'react'; import { describe, expect, it, vi } from 'vitest'; // Mock next-intl with Vietnamese messages const viMessages = await import('@/messages/vi.json'); vi.mock('next-intl', () => ({ useTranslations: (namespace?: string) => { const messages = viMessages.default ?? viMessages; const ns = namespace ? (messages[namespace as keyof typeof messages] as Record | undefined) : (messages as unknown as Record); return (key: string) => { if (!ns) return key; const parts = key.split('.'); let val: unknown = ns; for (const p of parts) { val = (val as Record)?.[p]; } return typeof val === 'string' ? val : key; }; }, useLocale: () => 'vi', })); vi.mock('@/i18n/navigation', () => ({ Link: ({ children, href, className }: { children: React.ReactNode; href: string; className?: string }) => ( {children} ), useRouter: () => ({ push: vi.fn() }), usePathname: () => '/not-found', })); import NotFound from '../not-found'; describe('NotFound (locale) page', () => { it('renders the 404 numeric display', () => { render(); expect(screen.getByText('404')).toBeInTheDocument(); }); it('renders a home link', () => { render(); const homeLinks = screen.getAllByRole('link'); const hasHomeLink = homeLinks.some((a) => a.getAttribute('href') === '/'); expect(hasHomeLink).toBe(true); }); it('renders a search link', () => { render(); const links = screen.getAllByRole('link'); const hasSearchLink = links.some((a) => a.getAttribute('href') === '/search'); expect(hasSearchLink).toBe(true); }); it('renders the page title text', () => { render(); const headings = screen.getAllByRole('heading'); expect(headings.length).toBeGreaterThan(0); }); });