import { screen, waitFor } from '@testing-library/react' import { beforeEach, describe, expect, it, vi } from 'vitest' import PostHistoryPage from '@/pages/posts/PostHistoryPage' import { buildTag } from '@/test/factories' import { renderWithProviders } from '@/test/render' const postsApi = vi.hoisted (() => ({ fetchPostChanges: vi.fn (), updatePost: vi.fn (), })) const tagsApi = vi.hoisted (() => ({ fetchTag: vi.fn (), fetchExternalTag: vi.fn (), })) vi.mock ('@/lib/posts', () => postsApi) vi.mock ('@/lib/tags', () => tagsApi) describe ('PostHistoryPage', () => { beforeEach (() => { vi.clearAllMocks () postsApi.fetchPostChanges.mockResolvedValue ({ versions: [], count: 0, }) }) it ('shows the external tag name when filtering by external_tag', async () => { const external = buildTag ({ id: 7, name: 'nico:external_history', category: 'nico', }) tagsApi.fetchExternalTag.mockResolvedValue (external) renderWithProviders ( , { route: '/posts/changes?external_tag=7' }, ) await waitFor (() => { expect (postsApi.fetchPostChanges).toHaveBeenCalledWith ({ externalTag: '7', page: 1, limit: 20, }) }) expect (tagsApi.fetchExternalTag).toHaveBeenCalledWith ('7') expect (tagsApi.fetchTag).not.toHaveBeenCalled () expect ( await screen.findByRole ('heading', { level: 1, name: '耕作履歴(nico:external_history)', }), ).toBeInTheDocument () }) })