/**
 * (shell: form mount + back navigation).
 */
import React from 'react'
import { render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import CreateApplicationWrapper from '../index'

const mockPush = jest.fn()
const mockBack = jest.fn()
jest.mock('@/i18n/navigation', () => ({
  useRouter: () => ({ push: mockPush, back: mockBack }),
}))
jest.mock('next-intl', () => ({ useTranslations: () => (k: string) => k }))
jest.mock('@/components/application/create/form', () => ({
  __esModule: true,
  default: () => (
    <form data-testid="create-form-stub">
      <span>Form</span>
    </form>
  ),
}))
jest.mock('@/share/ui/button', () => ({
  Button: ({
    children,
    onClick,
  }: {
    children: React.ReactNode
    onClick?: () => void
  }) => (
    <button type="button" onClick={onClick}>{children}</button>
  ),
}))
jest.mock('@/share/ui/card', () => ({
  Card: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
  CardContent: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
}))
jest.mock('lucide-react', () => ({ ChevronLeft: () => null }))

describe('[components/application/create] CreateApplicationWrapper', () => {
  beforeEach(() => {
    mockPush.mockClear()
    mockBack.mockClear()
  })

  describe('happy path', () => {
    it('renders ApplicationForm stub', () => {
      render(<CreateApplicationWrapper callback="/en/api-products/api-1" />)
      expect(screen.getByTestId('create-form-stub')).toBeInTheDocument()
    })
  })

  describe('navigation', () => {
    it('default back triggers router.back', async () => {
      render(<CreateApplicationWrapper callback="/en/api-products/api-1" />)
      await userEvent.click(screen.getByText('btn.default_back'))
      expect(mockBack).toHaveBeenCalledTimes(1)
    })
  })
})
