import React from 'react';
import {render, screen} from '@testing-library/react';

jest.mock('next-intl', () => ({
  useTranslations: () => (key: string) => key,
  useLocale: () => 'bzh',
}));
jest.mock('next/link', () => ({
  __esModule: true,
  default: ({children, href}: {children: React.ReactNode; href: string}) => <a href={href}>{children}</a>,
}));

import NextEventFormations from '../NextEventFormations';
import http from '@/http';

const mockedHttp = http as jest.Mocked<typeof http>;

describe('NextEventFormations', () => {
  beforeEach(() => {
    jest.clearAllMocks();
    mockedHttp.get.mockResolvedValue({status: 200, data: {'hydra:member': []}});
  });

  it('shouldTakeTheLocaleFromNextIntlRatherThanTheCookie', async () => {
    // Aucun cookie NEXT_LOCALE : c'est le cas au rendu serveur, où document n'existe même pas.
    expect(document.cookie).toBe('');

    render(<NextEventFormations fodId={12} />);

    expect(await screen.findByText('no_next_stages')).toBeInTheDocument();
    expect(screen.getByRole('link')).toHaveAttribute('href', '/bzh/evenements?discipline=12&tev=2');
  });
});
