/**
 * (success UI; back vs home navigation contract).
 */
import React from 'react'
import { render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'

const mockBack = jest.fn()
const mockPush = jest.fn()

jest.mock('@/i18n/navigation', () => ({
  useRouter: () => ({ back: mockBack, push: mockPush }),
}))

jest.mock('next-intl', () => ({
  useTranslations: () => (k: string) => k,
}))

jest.mock('@/share/icons', () => ({
  ToastSuccess: () => <div data-testid="reg-ticket-status-toast-success" />,
}))

import CertificateStatus from '../index'

describe('[components/regTicket/status] CertificateStatus', () => {
  beforeEach(() => {
    mockBack.mockClear()
    mockPush.mockClear()
  })

  describe('render', () => {
    it('shows success icon and status copy', () => {
      render(<CertificateStatus />)
      expect(
        screen.getByTestId('reg-ticket-status-toast-success'),
      ).toBeInTheDocument()
      expect(screen.getByText('create.status.title')).toBeInTheDocument()
    })
  })

  describe('navigation', () => {
    it('back calls router.back; complete routes to home', async () => {
      const user = userEvent.setup()
      render(<CertificateStatus />)

      await user.click(screen.getByRole('button', { name: 'btn.back' }))
      expect(mockBack).toHaveBeenCalledTimes(1)

      await user.click(screen.getByRole('button', { name: 'btn.compelete' }))
      expect(mockPush).toHaveBeenCalledWith('/')
      expect(mockPush).toHaveBeenCalledTimes(1)
    })
  })
})
