/**
 * (contract Redirect href: pathname + redirect param; BVA pathnames).
 */
import React from 'react'
import { render, screen } from '@testing-library/react'

const mockUsePathname = jest.fn()

jest.mock('next/navigation', () => ({
  usePathname: () => mockUsePathname(),
}))

jest.mock('@/components/redirect', () => ({
  __esModule: true,
  default: ({
    href,
  }: {
    href: { pathname: string; params: { redirect: string } }
  }) => (
    <div
      data-testid="eu-dashboard-redirect"
      data-href={JSON.stringify(href)}
    />
  ),
}))

describe('[locale]/(end-user)/page.tsx — EUDashboardPage', () => {
  beforeEach(() => {
    jest.clearAllMocks()
  })

  it.each([
    { pathname: '/vi/some/path', label: 'locale-prefixed path' },
    { pathname: '/', label: 'root path' },
    { pathname: '', label: 'empty pathname' },
  ])('passes pathname as redirect ($label)', async ({ pathname }) => {
    mockUsePathname.mockReturnValue(pathname)

    const { default: EUDashboardPage } = await import('../../page')
    render(<EUDashboardPage />)

    const raw = screen.getByTestId('eu-dashboard-redirect').dataset.href
    expect(JSON.parse(raw ?? '')).toEqual({
      pathname: '/api-products',
      params: { redirect: pathname },
    })
  })
})
