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

describe('Affilicate Disclaimer Component', () => {
  test('render with props', () => {
    const { container } = render(<AffiliateDisclaimer />);
    expect(container).toBeTruthy();
  });
  test('show correct affiliate disclaimer text', () => {
    const { getByText } = render(<AffiliateDisclaimer />);

    expect(getByText('Advertising Disclosure')).toBeInTheDocument();
  });
  test('show correct affiliate disclaimer content', async () => {
    const { getByText, container } = render(<AffiliateDisclaimer />);

    expect(getByText('Advertising Disclosure')).toBeTruthy();

    fireEvent.mouseEnter(screen.getByText('Advertising Disclosure'));

    await waitFor(() => {
      screen.getByText(
        'Advertising Disclosure: irishluck.ie contains links to partner websites. When a visitor clicks a link and makes a purchase at a partner site, Irishluck is paid a commission. Affiliate links and commissions do not impact bonuses and come at no additional cost to players. Our opinion of the casino always remains unbiased in our recommendations.'
      );
      const isVisible = container.querySelector('.tooltip');
      expect(isVisible).toBeTruthy();
      expect(container.querySelector('.content')).toBeVisible();
    });
  });
});

afterEach(() => {
  cleanup();
});
