/* 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 TemplateTwo from '.';

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

describe('Author Header', () => {
  test('Template Two', () => {
    const { container, getByText } = render(
      <MainProvider value={{}}>
        <TemplateTwo
          author={{
            name: 'Ida Moen Olsen',
            author_title: 'Online Casino Specialist',
            image_object: {
              filename:
                'https://assets-srv.s3.eu-west-1.amazonaws.com/2020-09-25-15-01-46-imagesjpeg-191264.png',
              width: '150',
              height: '150',
            },
            image_alt: 'image-alt',
            expertise: ['Casino Expert', 'Game Expert'],
            facebook_profile: 'https://www.irishluck.ie',
            instagram_profile: 'https://www.irishluck.ie',
            linkedin_profile: 'https://www.irishluck.ie',
            twitter_profile: 'https://www.irishluck.ie',
            tik_tok: 'https://www.irishluck.ie',
            profile_page_path: '/',
          }}
        />
      </MainProvider>
    );
    expect(getByText('Ida Moen Olsen')).toBeTruthy();
    expect(getByText('Online Casino Specialist')).toBeTruthy();
    expect(container.querySelectorAll('a')).toHaveLength(5);
    expect(container.querySelectorAll('ul')).toHaveLength(1);
    expect(container.querySelectorAll('li')).toHaveLength(2);
  });
  test('Test author pronoun', async () => {
    const { container, getByText } = render(<TemplateTwo author={author} />);

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

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