import React from 'react';
import { render, waitFor } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';
import OperatorDetails from '.';

describe('OperatorDetails', () => {
  const mockItem = {
    name: 'Test Name',
    rating: '4.5',
    review_link: 'test-review-link',
    path: 'test-path',
    standardised_logo_url_object: {
      filename: 'test-filename',
    },
    author: {
      name: 'Author Name',
      profile_page_path: 'author-profile-path',
      image: 'author-image',
    },
  };
  const mockItemName = 'Test Name';

  it('renders the component with provided props', async () => {
    const { getByText } = render(<OperatorDetails item={mockItem} itemName={mockItemName} />);

    await waitFor(() => {
      expect(getByText(mockItemName)).toBeInTheDocument();
    });
  });

  it('displays the rating when showRating is true', async () => {
    const { getByText } = render(
      <OperatorDetails item={mockItem} itemName={mockItemName} showRating />
    );

    await waitFor(() => {
      expect(getByText(mockItem.rating)).toBeInTheDocument();
    });
  });

  it('does not display rating when showRating is false', async () => {
    const { queryByText } = render(
      <OperatorDetails item={mockItem} itemName={mockItemName} showRating={false} />
    );

    await waitFor(() => {
      expect(queryByText(mockItem.rating)).not.toBeInTheDocument();
    });
  });

  it('displays author information when showAuthor is true', async () => {
    const { getByText } = render(
      <OperatorDetails item={mockItem} itemName={mockItemName} showAuthor />
    );

    await waitFor(() => {
      expect(getByText(`By Author N.`)).toBeInTheDocument();
    });
  });

  it('does not display author information when showAuthor is false', async () => {
    const { queryByText } = render(
      <OperatorDetails item={mockItem} itemName={mockItemName} showAuthor={false} />
    );

    await waitFor(() => {
      expect(queryByText(`By Author N.`)).not.toBeInTheDocument();
    });
  });
});
