/**
 * (contract: unknown segments → notFound terminates the route).
 */
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('../page')

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

    expect(mockNotFound).toHaveBeenCalledTimes(1)
  })

  it('default export is a sync function entry', async () => {
    const { default: CatchAllPage } = await import('../page')
    expect(CatchAllPage).toEqual(expect.any(Function))
    expect(CatchAllPage.constructor.name).toBe('Function')
  })
})
