/* eslint-disable no-multi-assign */
import React from 'react';
import { render, cleanup } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';
import Ratings from '.';

describe('Rating component', () => {
  const page = () => ({
    name: 'Rizk Casino',
    logo_url_object: {
      filename: 'rizk',
      alt: 'rizk-logo',
    },
    rating: '4.5',
    status: 'active',
    first_rating: '3',
    second_rating: '',
    third_rating: '3',
    fourth_rating: true,
    volatility: 1,
    bonus: {
      rating: '4',
      rating_bonuses: '',
      rating_casino: '3.5',
      rating_customer: '3.5',
      rating_games: '',
      rating_payout: '4.5',
    },
  });

  test('Rating', () => {
    const { container } = render(<Ratings item={page()} type="operator" />);
    expect(container.querySelectorAll('ul')).toHaveLength(1);
    expect(container.querySelectorAll('li')).toHaveLength(6);
  });

  test('Rating with diferent data text', () => {
    const { container, getByText, getAllByText } = render(<Ratings item={page()} type="game" />);
    expect(container.querySelectorAll('ul')).toHaveLength(1);
    expect(container.querySelectorAll('li')).toHaveLength(5);

    expect(getAllByText(3)).toHaveLength(2);
    expect(getByText('Medium')).toBeTruthy();
  });

  test('Rating no type', () => {
    const { container } = render(<Ratings item={page()} type="" />);
    expect(container.querySelectorAll('ul')).toHaveLength(0);
    expect(container.querySelectorAll('li')).toHaveLength(0);
  });
});

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