import { QueryClient, QueryClientProvider } from '@tanstack/react-query' import { render, screen } from '@testing-library/react' import { HelmetProvider } from 'react-helmet-async' import { beforeEach, describe, expect, it, vi } from 'vitest' import { apiGet } from '@/lib/api' import App from '@/App' import { helpFixture } from '@/test/helpFixtures' vi.hoisted (() => { window.history.replaceState (null, '', '/help/changes') }) vi.mock ('@/lib/help', async () => (await import ('@/test/helpFixtures')).helpFixture.api) vi.mock ('@/lib/api', () => ({ apiGet: vi.fn (), apiPost: async () => ({}), isApiError: () => false })) vi.mock ('@/components/TopNav', () => ({ default: () => null })) vi.mock ('@/components/DevModeWatermark', () => ({ default: () => null })) vi.mock ('@/lib/useClientBehaviourSettings', () => ({ useClientBehaviourSettings: () => ({ animation: 'off', linkPreload: 'off' }) })) describe ('Help global edition history', () => { beforeEach (() => helpFixture.reset ()) it ('routes /help/changes to published editions in date and numeric order', async () => { const client = new QueryClient ({ defaultOptions: { queries: { retry: false } } }) const { container } = render ( ) const links = await screen.findAllByRole ('link') const editions = links.map (link => link.getAttribute ('href')) .filter (href => href?.startsWith ('/help/') && href.includes ('edition=')) expect (editions).toEqual ([ `/help/${encodeURIComponent ('設定 手順')}?edition=2026-10-03`, '/help/guide?edition=2026-10-02.10', '/help/guide?edition=2026-10-02.3', '/help/guide?edition=2026-10-02.2', '/help/guide?edition=2026-10-02', '/help/guide?edition=2026-10-01']) expect (container).toHaveTextContent ('旧ホーム') expect (screen.getAllByRole ('columnheader').map (cell => cell.textContent)) .toEqual (['差分', 'タイトル', '有効開始年月日']) expect (container).not.toHaveTextContent ('未公開ホーム') expect (container).not.toHaveTextContent ('Invalid Date') expect (container.textContent).not.toMatch (/\d{1,2}:\d{2}/) expect (screen.getAllByRole ('link', { name: '差分' }).map (link => link.getAttribute ('href'))).toEqual ([ '/help/guide/diff?from=2026-10-02.3&to=2026-10-02.10', '/help/guide/diff?from=2026-10-02.2&to=2026-10-02.3', '/help/guide/diff?from=2026-10-02&to=2026-10-02.2', '/help/guide/diff?from=2026-10-01&to=2026-10-02']) expect (apiGet).not.toHaveBeenCalled () expect (window.location.pathname).toBe ('/help/changes') }) })