/**
 * (contract: unmatched locale segment → notFound terminates).
 */
import { beforeEach, describe, expect, it, jest } from '@jest/globals'

const mockNotFound = jest.fn(() => {
  const err = new Error('NEXT_NOT_FOUND')
  ;(err as unknown as { digest?: string }).digest = 'NEXT_NOT_FOUND'
  throw err
})

jest.mock('next/navigation', () => ({
  notFound: () => mockNotFound(),
}))

describe('[locale]/[...rest]/page.tsx — CatchAllPage', () => {
  beforeEach(() => {
    jest.clearAllMocks()
  })

  it('calls notFound exactly once and aborts like Next runtime', async () => {
    const { default: CatchAllPage } = await import('../[...rest]/page')

    expect(() => {
      CatchAllPage()
    }).toThrow('NEXT_NOT_FOUND')

    expect(mockNotFound).toHaveBeenCalledTimes(1)
  })
})
