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

describe('Author Header', () => {
  test('Template One', () => {
    const author = getAuthorList({})[1];
    const { container, getByText } = render(<TemplateOne item={{ relation: { ...author } }} />, {
      wrapper: ({ children }) => <Context.Provider value={{}}>{children}</Context.Provider>,
    });
    expect(getByText('Author 1 Name')).toBeTruthy();
    expect(getByText(author.author_title)).toBeTruthy();
    expect(getByText('23 Posts')).toBeTruthy();
    expect(container.querySelectorAll('a')).toHaveLength(7);
    expect(getByText('Author 1 Name').closest('a').getAttribute('href')).toEqual(
      `/${author.profile_page_path}`
    );
  });
});

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