/* eslint-disable no-multi-assign */
import React from 'react';
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 '.';
import { textWordsLimit } from '~helpers/getters';

describe('Author Header', () => {
  test('Template One', () => {
    const author = getAuthorList({})[1];
    const { container, getByText } = render(
      <TemplateOne item={{ path: 'test/author', relation: { ...author } }} />
    );
    expect(getByText('Author 1 Name')).toBeTruthy();
    expect(getByText(author.author_title)).toBeTruthy();
    expect(getByText('23 Posts')).toBeTruthy();
    expect(getByText(textWordsLimit(author.biography, 20))).toBeTruthy();
    expect(container.querySelectorAll('a')).toHaveLength(7);
    expect(getByText('View Author').closest('a').getAttribute('href')).toEqual(`/test/author`);
  });
});

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