import React, { isValidElement } from 'react'
import { describe, expect, it, vi } from 'vitest'

const navigation = vi.hoisted(() => ({
  notFound: vi.fn(() => {
    throw new Error('NEXT_NOT_FOUND')
  }),
}))

vi.mock('next/navigation', () => navigation)

import FooterContentPage from '@/components/FooterContentPage'
import FooterPage, { generateStaticParams } from './page'
import { footerPageSlugs } from '@/lib/footerContent'

describe('carplace footer route', () => {
  it('generates one static route per registered footer slug', () => {
    expect(generateStaticParams()).toEqual(footerPageSlugs.map((slug) => ({ slug })))
  })

  it('passes valid slugs through to FooterContentPage', () => {
    const element = FooterPage({ params: { slug: 'privacy-policy' } })

    expect(isValidElement(element)).toBe(true)
    expect(element.type).toBe(FooterContentPage)
    expect(element.props.slug).toBe('privacy-policy')
    expect(element.props.forcedLanguage).toBeUndefined()
  })

  it('rejects unknown slugs instead of rendering arbitrary policy pages', () => {
    expect(() => FooterPage({ params: { slug: 'definitely-not-a-policy' } })).toThrow('NEXT_NOT_FOUND')
    expect(navigation.notFound).toHaveBeenCalled()
  })
})
