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

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

import VoirAussiEnsembles from '../VoirAussiEnsembles';

const ensembles = [
  {
    eesId: 5,
    eesLibelle: 'Festival Interceltique',
    logoUrl: 'https://media.tamm-kreiz.bzh/fil.png',
    evenements: [
      {eveId: 9, eveDate: '2026-10-03', eveTev: {tevLibelle: 'Stage'}, eveVil: {vilNom: 'Rennes'}},
      {eveId: 10, eveDate: '2026-10-04', eveTev: {tevLibelle: 'Fest-noz'}, eveVil: {vilNom: 'Lorient'}},
    ],
  },
];

describe('VoirAussiEnsembles', () => {
  it('shouldLinkTheEnsembleWithItsLogoAndListTheSiblingEvents', () => {
    render(<VoirAussiEnsembles ensembles={ensembles} locale="fr" currentEveId={9} />);

    expect(screen.getByTestId('voir-aussi-section')).toHaveTextContent('voir_aussi_title');
    expect(screen.getByRole('link', {name: /Festival Interceltique/})).toHaveAttribute('href', '/fr/festivite/5/festival-interceltique');
    expect(screen.getByRole('img', {name: 'Festival Interceltique'})).toHaveAttribute('src', 'https://media.tamm-kreiz.bzh/fil.png');
    const frere = screen.getByRole('link', {name: /Fest-noz à Lorient/});
    expect(frere).toHaveAttribute('href', '/fr/evenement/10/fest-noz-a-lorient');
    expect(screen.queryByRole('link', {name: /Stage à Rennes/})).not.toBeInTheDocument();
  });

  it('shouldRenderNothingWithoutEnsemble', () => {
    const {container} = render(<VoirAussiEnsembles ensembles={[]} locale="fr" currentEveId={9} />);

    expect(container).toBeEmptyDOMElement();
  });
});
