/**
 * (metadata + renders wrapper with callback from searchParams).
 */
import React from 'react'
import { render, screen } from '@testing-library/react'

jest.mock('next-intl/server', () => ({
  getTranslations: (ns: string) =>
    Promise.resolve((key: string) => `${ns}.${key}`),
}))

jest.mock('@/components/application/create', () => ({
  __esModule: true,
  default: ({ callback }: { callback: string }) => (
    <div data-testid="create-application-wrapper">{callback}</div>
  ),
}))

describe('[locale]/(end-user)/.../application/create/page.tsx', () => {
  describe('generateMetadata', () => {
    it('uses layout namespace for title', async () => {
      const { generateMetadata } = await import('../page')
      const metadata = await generateMetadata()
      expect(metadata.title).toBe('layout.header.application')
      expect(metadata.description).toBe('')
    })
  })

  describe('happy path', () => {
    it('passes callback search param to CreateApplicationWrapper', async () => {
      const { default: CreateApplicationPage } = await import('../page')

      const cb = '/en/api-products/api-1'
      const element = await CreateApplicationPage({
        searchParams: Promise.resolve({ callback: cb }),
      } as never)

      render(element as React.ReactElement)
      expect(
        screen.getByTestId('create-application-wrapper')
      ).toHaveTextContent(cb)
    })
  })
})
