/* eslint-disable no-multi-assign */
import React from 'react';
import { render, cleanup, waitFor } from '@testing-library/react';
import MainProvider from '~context/MainProvider';
import '@testing-library/jest-dom/extend-expect';
import getAuthorList from '../../../../../../../tests/factories/authors/author.factory';
import TemplateOne from '.';

const author = getAuthorList({})[1];

describe('Author Header', () => {
  test('Template One', () => {
    const { container, getByText } = render(
      <MainProvider value={{}}>
        <TemplateOne author={author} />
      </MainProvider>
    );
    expect(getByText('Author 1 Name')).toBeTruthy();
    expect(getByText('Sports Betting')).toBeTruthy();
    expect(container.querySelectorAll('.biography')).toBeTruthy();
    expect(container.querySelectorAll('a')).toHaveLength(6);
    expect(container.querySelectorAll('ul')).toHaveLength(1);
    expect(container.querySelectorAll('li')).toHaveLength(3);
  });
  test('Test author pronoun', async () => {
    const { container, getByText } = render(<TemplateOne author={author} />);

    await waitFor(() => {
      expect(getByText('(He/him/his)')).toBeTruthy();
      expect(container.querySelector('small')).toHaveTextContent(author.pronouns);
    });
  });
});

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