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, ...rest}: {children: React.ReactNode; href: string}) => <a href={href} {...rest}>{children}</a>,
}));

import ArticleLiensSection from './ArticleLiensSection';

describe('ArticleLiensSection (spec L71)', () => {
  it('shouldLinkEachLinkedItemToItsOwnPage', () => {
    render(
      <ArticleLiensSection
        locale="fr"
        liens={[
          {id: 1, tableCible: 'annuaire_entree', cibleId: 77, libelle: 'Sonerion'},
          {id: 2, tableCible: 'evenement', cibleId: 12, libelle: 'Fest-noz de Carhaix'},
          {id: 3, tableCible: 'evenement_ensemble', cibleId: 5, libelle: 'Festival de Cornouaille'},
          {id: 4, tableCible: 'formation_stage', cibleId: 9, libelle: 'Stage de bombarde'},
        ]}
      />
    );

    expect(screen.getByRole('heading', {level: 2})).toHaveTextContent('linked_items_title');
    expect(screen.getByRole('link', {name: 'Sonerion'})).toHaveAttribute('href', '/fr/annuaire_entree/77/sonerion');
    expect(screen.getByRole('link', {name: 'Fest-noz de Carhaix'})).toHaveAttribute('href', '/fr/evenement/12/fest-noz-de-carhaix');
    expect(screen.getByRole('link', {name: 'Festival de Cornouaille'})).toHaveAttribute('href', '/fr/festivite/5/festival-de-cornouaille');
    expect(screen.getByRole('link', {name: 'Stage de bombarde'})).toHaveAttribute('href', '/fr/stage/9/stage-de-bombarde');
  });

  it('shouldRenderNothingWithoutLinkedItem', () => {
    const {container} = render(<ArticleLiensSection locale="fr" liens={[]} />);

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