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

jest.mock('next-intl', () => ({
  useTranslations: () => (key: string) => key,
}));
jest.mock('@/components/global/CarteLeafletSingle', () => ({
  __esModule: true,
  default: () => <div data-testid="carte" />,
}));

import Lieu from '../Lieu';

const salle = {
  placeName: 'Salle des fêtes',
  adresse: 'Rennes 35000',
  parquet: true,
  parking: false,
  capacity: 250,
  geoX: 48.1,
  geoY: -1.7,
  geoZ: 14,
};

describe('Lieu', () => {
  it('shouldShowThePlacePhotoAndItsTransportStations', () => {
    render(<Lieu {...salle} photoUrl="https://media.tamm-kreiz.bzh/salle.jpg" stations={['Gare de Rennes', 'République']} />);

    expect(screen.getByRole('img', {name: 'Salle des fêtes'})).toHaveAttribute('src', 'https://media.tamm-kreiz.bzh/salle.jpg');
    const stations = screen.getByTestId('lieu-stations');
    expect(stations).toHaveTextContent('stations_title');
    expect(stations).toHaveTextContent('Gare de Rennes');
    expect(stations).toHaveTextContent('République');
    expect(screen.getByText('250')).toBeInTheDocument();
  });

  it('shouldSkipPhotoAndStationsWhenUnknown', () => {
    render(<Lieu {...salle} />);

    expect(screen.queryByRole('img')).not.toBeInTheDocument();
    expect(screen.queryByTestId('lieu-stations')).not.toBeInTheDocument();
  });

  it('shouldHideTheFeaturesGridWhenThereIsNoPlace', () => {
    render(<Lieu {...salle} placeName="Rennes" capacity={null} avecCaracteristiques={false} />);

    expect(screen.queryByText('personnes')).not.toBeInTheDocument();
    expect(screen.queryByText('parking')).not.toBeInTheDocument();
    expect(screen.getByText('Rennes 35000')).toBeInTheDocument();
  });
});
