import { screen } from '@testing-library/react'
import { describe, expect, it, vi } from 'vitest'

import WikiHistoryPage from '@/pages/wiki/WikiHistoryPage'
import { renderWithProviders } from '@/test/render'

const api = vi.hoisted (() => ({
  apiGet: vi.fn (),
}))

vi.mock ('@/lib/api', () => api)

describe ('WikiHistoryPage', () => {
  it ('renders deprecated state outside the wiki title link', async () => {
    api.apiGet.mockResolvedValueOnce ([{
      revisionId:  2,
      pred:        1,
      succ:        null,
      wikiPage:    {
	id:           3,
	title:        '旧タグ',
	deprecatedAt: '2026-06-01T00:00:00.000Z',
      },
      user:        { id: 4, name: 'tester' },
      kind:        'content',
      message:     'updated',
      timestamp:   '2026-06-02T00:00:00.000Z',
    }])

    renderWithProviders (<WikiHistoryPage/>)

    const link = await screen.findByRole ('link', { name: '旧タグ' })
    const marker = screen.getByText ('（廃止）')

    expect (link).toHaveAttribute ('href', '/wiki/%E6%97%A7%E3%82%BF%E3%82%B0?version=2')
    expect (marker.closest ('a')).toBeNull ()
  })
})
