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

jest.mock('next-intl', () => ({
  useTranslations: () => (key: string) => key,
}));

import FichiersSection from '../FichiersSection';

const fichiers = [
  {medId: 1, url: 'https://media.tamm-kreiz.bzh/programme.pdf', filename: 'programme_ab12cd34.pdf', label: 'Programme du stage', mimetype: 'application/pdf', source: 'own'},
  {medId: 2, url: 'https://media.tamm-kreiz.bzh/plan.pdf', filename: 'plan-acces.pdf', label: null, mimetype: 'application/pdf', source: 'ensemble:5'},
  {medId: 3, url: null, filename: 'perdu.pdf', label: 'Perdu', mimetype: 'application/pdf', source: 'own'},
];

describe('FichiersSection', () => {
  it('shouldLinkEachDownloadableFileByItsName', () => {
    render(<FichiersSection fichiers={fichiers} />);

    expect(screen.getByTestId('fichiers-section')).toHaveTextContent('fichiers_title');
    expect(screen.getByRole('link', {name: 'Programme du stage'})).toHaveAttribute('href', 'https://media.tamm-kreiz.bzh/programme.pdf');
    expect(screen.getByRole('link', {name: 'plan-acces.pdf'})).toHaveAttribute('href', 'https://media.tamm-kreiz.bzh/plan.pdf');
    expect(screen.queryByText('Perdu')).not.toBeInTheDocument();
  });

  it('shouldRenderNothingWithoutFile', () => {
    const {container} = render(<FichiersSection fichiers={[]} />);

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