/**
 * (metadata + params → ApplicationDetailWrapper props).
 */
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/detail', () => ({
  __esModule: true,
  default: ({
    app_id,
    api_product_name,
  }: {
    app_id: string
    api_product_name: string
  }) => (
    <div data-testid="application-detail">{`${app_id}|${api_product_name}`}</div>
  ),
}))

describe('[locale]/(end-user)/.../application/[app_id]/page.tsx', () => {
  describe('generateMetadata', () => {
    it('maps layout translation keys into metadata', async () => {
      const { generateMetadata } = await import('../page')
      const metadata = await generateMetadata()
      expect(metadata.title).toBe('layout.header.application')
      expect(metadata.description).toBe('')
    })
  })

  describe('happy path — prop wiring', () => {
    it.each([
      { app_id: 'app-1', api_product_name: 'api-1' },
      { app_id: 'app-2', api_product_name: 'My API' },
    ])('forwards params + search api_product_name', async ({
      app_id,
      api_product_name,
    }) => {
      const { default: ApplicationDetailPage } = await import('../page')

      const element = await ApplicationDetailPage({
        params: Promise.resolve({ app_id }),
        searchParams: Promise.resolve({ api_product_name }),
      } as never)

      render(element as React.ReactElement)
      expect(screen.getByTestId('application-detail')).toHaveTextContent(
        `${app_id}|${api_product_name}`
      )
    })
  })
})
