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

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

import ProfilActivite from '../ProfilActivite';

const fest = {eveId: 12, libelle: 'Fest-noz de Carhaix', date: '2026-11-07', vilNom: 'Carhaix'};

describe('ProfilActivite', () => {
  it('shouldListTheCommentsAdsAndCarpoolsWithTheirLinks', () => {
    render(
      <ProfilActivite
        locale="fr"
        commentaires={[{id: 1, texte: 'Super soirée !', date: '2026-09-12', heure: '10:00', evenement: fest}]}
        annonces={[{id: 3, titre: 'Cherche bombarde', texte: 'En bon état', date: '2026-09-15', typeId: 2}]}
        covoiturages={[
          {id: 5, ville: 'Quimper', nombre: 3, heure: '19:30', propose: 1, evenement: fest},
          {id: 6, ville: 'Brest', nombre: 1, heure: null, propose: 0, evenement: null},
        ]}
      />
    );

    expect(screen.getByText('Super soirée !')).toBeInTheDocument();
    expect(screen.getAllByRole('link', {name: 'Fest-noz de Carhaix'})[0]).toHaveAttribute('href', '/fr/evenement/12/fest-noz-de-carhaix');
    expect(screen.getByText('Cherche bombarde')).toBeInTheDocument();
    expect(screen.getByRole('link', {name: 'activity_ads_link'})).toHaveAttribute('href', '/fr/petites-annonces');
    expect(screen.getByText('carpool_offer')).toBeInTheDocument();
    expect(screen.getByText('carpool_request')).toBeInTheDocument();
    expect(screen.getAllByRole('link', {name: 'Fest-noz de Carhaix'})).toHaveLength(2);
    expect(screen.queryByText('activity_no_comments')).not.toBeInTheDocument();
  });

  it('shouldSayWhenEachListIsEmpty', () => {
    render(<ProfilActivite locale="fr" commentaires={[]} annonces={[]} covoiturages={[]} />);

    expect(screen.getByText('activity_no_comments')).toBeInTheDocument();
    expect(screen.getByText('activity_no_ads')).toBeInTheDocument();
    expect(screen.getByText('activity_no_carpools')).toBeInTheDocument();
    expect(screen.queryByRole('link', {name: 'activity_ads_link'})).not.toBeInTheDocument();
  });
});
