import { render, screen } from '@testing-library/react'
import { MemoryRouter, Navigate, Route, Routes } from 'react-router-dom'
import { describe, expect, it } from 'vitest'

describe ('legacy post import routes', () => {
  it ('redirects /posts/import to /posts/new', () => {
    render (
        <MemoryRouter initialEntries={['/posts/import']}>
          <Routes>
            <Route path="/posts/import" element={<Navigate to="/posts/new" replace/>}/>
            <Route path="/posts/new" element={<div>SOURCE ROUTE</div>}/>
          </Routes>
        </MemoryRouter>)

    expect (screen.getByText ('SOURCE ROUTE')).toBeInTheDocument ()
  })

  it ('redirects legacy review routes to /posts/new', () => {
    render (
        <MemoryRouter initialEntries={['/posts/import/legacy/review']}>
          <Routes>
            <Route
                path="/posts/import/:sessionId/review"
                element={<Navigate to="/posts/new" replace/>}/>
            <Route path="/posts/new" element={<div>SOURCE ROUTE</div>}/>
          </Routes>
        </MemoryRouter>)

    expect (screen.getByText ('SOURCE ROUTE')).toBeInTheDocument ()
  })

  it ('redirects legacy result routes to /posts', () => {
    render (
        <MemoryRouter initialEntries={['/posts/import/legacy/result']}>
          <Routes>
            <Route
                path="/posts/import/:sessionId/result"
                element={<Navigate to="/posts" replace/>}/>
            <Route
                path="/posts/new/:sessionId/result"
                element={<Navigate to="/posts" replace/>}/>
            <Route path="/posts" element={<div>POSTS ROUTE</div>}/>
          </Routes>
        </MemoryRouter>)

    expect (screen.getByText ('POSTS ROUTE')).toBeInTheDocument ()
  })
})
