/* eslint-disable no-multi-assign */
import React from 'react';
import { render, cleanup } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';
import { getSampleOperatorCards } from 'gatsby-core-theme/tests/factories/modules/card.factory';
import TemplateFive from '.';

describe('Game Cards', () => {
  test('Template Five Provider', () => {
    const card = getSampleOperatorCards().items[0];
    card.relation = {
      ...card.relation,
      game_provider: {
        name: 'Test Game Provider',
        path: 'test-game-provider-path',
      },
    };

    const { container, getByText } = render(<TemplateFive item={card} />);
    expect(getByText('Wildz Casino')).toBeInTheDocument();
    expect(getByText('Test Game Provider')).toBeInTheDocument();
    expect(getByText('Play now')).toBeInTheDocument();
    expect(container.querySelectorAll('a')).toHaveLength(4);
  });
  test('Template Five Operator', () => {
    const card = getSampleOperatorCards().items[0];
    card.extra_fields = {
      ...card.extra_fields,
      operator: {
        name: 'Test Game Operator',
        path: 'test-game-operator-path',
        bonuses: {
          main: {
            one_liner: '20 free spins + Unused Text',
          },
        },
      },
    };

    const { container, getByText } = render(<TemplateFive useOneStarRating={false} item={card} />);
    expect(getByText('Wildz Casino')).toBeInTheDocument();
    expect(getByText('Play at Test Game Operator and get 20 free spins')).toBeInTheDocument();
    expect(getByText('Play now')).toBeInTheDocument();
    expect(container.querySelectorAll('a')).toHaveLength(4);
  });
});

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