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

jest.mock('next-intl', () => ({
  useTranslations: () => (key: string) => key,
}));
jest.mock('@/services/communauteService', () => ({
  getFilCommunautaire: jest.fn(),
}));
jest.mock('../CommunauteFeed', () => ({__esModule: true, default: ({locale}: {locale: string}) => <div data-testid="feed" data-locale={locale} />}));
jest.mock('../CarouselEnsEvent', () => ({__esModule: true, default: () => <div data-testid="carousel-ens" />}));
jest.mock('../CarouselEventPartner', () => ({__esModule: true, default: () => <div data-testid="carousel-partner" />}));
jest.mock('../CarouselLastEvent', () => ({
  __esModule: true,
  default: ({title, events}: {title: string; events: {infoLink: string; description: string}[]}) => (
    <div data-testid={`carousel-${title}`} data-count={events.length}>{events.map(e => e.infoLink).join('|')}</div>
  ),
}));

import AgendaPage from '../AgendaPage';
import http from '@/http';
import {getFilCommunautaire} from '@/services/communauteService';

describe('AgendaPage — pied de page de l\'agenda', () => {
  beforeEach(() => {
    jest.clearAllMocks();
    (http.get as jest.Mock).mockResolvedValue({data: {'hydra:member': []}});
    (getFilCommunautaire as jest.Mock).mockResolvedValue({
      commentaires: [
        {id: 1, texte: 'Top', date: '2026-09-17', auteur: null, evenement: {eveId: 72, libelle: 'Fest-noz à Rennes', date: '2026-09-20', tevLibelle: 'Fest-noz', vilNom: 'Rennes'}},
        {id: 2, texte: 'Encore', date: '2026-09-16', auteur: null, evenement: {eveId: 72, libelle: 'Fest-noz à Rennes', date: '2026-09-20', tevLibelle: 'Fest-noz', vilNom: 'Rennes'}},
      ],
      annonces: [], covoiturages: [], inscrits: [],
    });
  });

  it('shouldFeedTheCommentedCarouselFromTheLatestCommentsAndMountTheCommunityFeed', async () => {
    render(<AgendaPage locale="fr" />);

    const commentes = await screen.findByTestId('carousel-commented_events');
    expect(commentes).toHaveAttribute('data-count', '1');
    expect(commentes).toHaveTextContent('/fr/evenement/72/fest-noz-a-rennes');
    await waitFor(() => expect(screen.getByTestId('feed')).toHaveAttribute('data-locale', 'fr'));
  });
});
