import React from 'react'; import '@testing-library/jest-dom'; import { render, screen } from '@testing-library/react'; import { MemoryRouter } from 'react-router-dom'; import DashboardWeek from './components/DashboardWeek'; import { I18nProvider } from './i18n/I18nProvider'; import type { JobApplication } from './types'; beforeEach(() => { localStorage.clear(); jest.useFakeTimers(); jest.setSystemTime(new Date(2026, 10, 3, 12)); }); afterEach(() => { jest.useRealTimers(); localStorage.clear(); }); function open(deadline?: string, followUpAt?: string) { const jobs = [{ id: 3, jobTitle: 'Recorded role', company: { name: 'Example employer' }, deadline, followUpAt }] as JobApplication[]; const original = JSON.stringify(jobs); const view = render(); expect(JSON.stringify(jobs)).toBe(original); return view; } test.each([ ['2026-11-03', true], ['2026-11-09', true], ['2026-11-10', false], ['2026-11-02', false], ['as soon as possible', false], ['2026-11-04T24:00:00Z', false], ['2026-11-04T10:99:00Z', false], ])('deadline %s respects the local seven-day boundary and recorded precision', (value, visible) => { const view = open(value); expect(screen.queryByRole('link', { name: 'Recorded role' }) !== null).toBe(visible); if (visible) expect(view.container.querySelector('time')).toHaveAttribute('datetime', value); }); test('invalid calendar dates do not silently roll into a real upcoming day', () => { jest.setSystemTime(new Date(2026, 2, 1, 12)); open('2026-02-30'); expect(screen.queryByRole('link', { name: 'Recorded role' })).not.toBeInTheDocument(); }); test('recorded follow-up timestamps and date-only deadlines stay distinct and untranslated', () => { localStorage.setItem('uiLanguage', 'nb'); const view = open('2026-11-04', '2026-11-05T10:30:00Z'); expect(screen.getByRole('heading', { name: 'Uken din' })).toBeInTheDocument(); expect(screen.getByText('Søknadsfrist')).toBeInTheDocument(); expect(screen.getByText('Oppfølging')).toBeInTheDocument(); expect([...view.container.querySelectorAll('time')].map(node => node.getAttribute('datetime'))).toEqual(['2026-11-04', '2026-11-05T10:30:00Z']); });