import React from 'react'
import { render, screen } from '@testing-library/react'
import { mockUseRouter, mockUseTranslations, MockProviders } from './test-utils'

describe('test-utils', () => {
  describe('mockUseRouter — happy path', () => {
    it('exposes push, replace, back, refresh as functions', () => {
      const router = mockUseRouter()
      expect(router.push).toEqual(expect.any(Function))
      expect(router.replace).toEqual(expect.any(Function))
      expect(router.back).toEqual(expect.any(Function))
      expect(router.refresh).toEqual(expect.any(Function))
    })

    it('router callables do not throw when invoked', () => {
      const router = mockUseRouter()
      expect(() => {
        router.push('/a')
        router.replace('/b')
        router.back()
        router.refresh()
      }).not.toThrow()
    })
  })

  describe('mockUseTranslations — contract', () => {
    it('returns key as label (identity translator)', () => {
      const t = mockUseTranslations()
      expect(t('namespace.key')).toBe('namespace.key')
    })

    it.each([
      ['empty', ''],
      ['unicode', 'auth.title_đăng_nhập'],
    ] as const)('stable for %s key', (_label, key) => {
      const t = mockUseTranslations()
      expect(t(key)).toBe(key)
    })
  })

  describe('MockProviders — render', () => {
    it('renders direct children', () => {
      render(
        <MockProviders>
          <span>Child</span>
        </MockProviders>,
      )
      expect(screen.getByText('Child')).toBeInTheDocument()
    })

    it('renders nested structure', () => {
      render(
        <MockProviders>
          <div>
            <p>Nested</p>
          </div>
        </MockProviders>,
      )
      expect(screen.getByText('Nested')).toBeInTheDocument()
    })
  })
})
