import React from 'react';
import { render, fireEvent, waitFor } from '@testing-library/react';
import { act } from 'react-dom/test-utils';
import FeedBack from '.';

describe('FeedBack Component', () => {
  it('renders correctly with initial state', () => {
    const { getByText } = render(
      <FeedBack pageId={123} casinoTitle="Wildz" trueVotes={10} falseVotes={5} />
    );

    expect(getByText('Would you recomend Wildz ?')).toBeInTheDocument();
  });

  it('handles like button click', async () => {
    const { getByText, getByTestId } = render(
      <FeedBack pageId={123} casinoTitle="Wildz" trueVotes={10} falseVotes={5} />
    );

    const likeButton = getByTestId('like-button');
    await act(async () => {
      fireEvent.click(likeButton);
    });

    await waitFor(() => {
      expect(getByText('Thanks for your feedback!')).toBeInTheDocument();
    });
  });

  it('handles dislike button click', async () => {
    const { getByText, getByTestId } = render(
      <FeedBack pageId={123} casinoTitle="Wildz" trueVotes={10} falseVotes={5} />
    );

    const dislikeButton = getByTestId('dislike-button');
    await act(async () => {
      fireEvent.click(dislikeButton);
    });

    await waitFor(() => {
      expect(getByText('Thanks for your feedback!')).toBeInTheDocument();
    });
  });
});
