/* eslint-disable camelcase */
import React from 'react';
import { render, cleanup } from '@testing-library/react';
import { authors } from 'gatsby-core-theme/tests/factories/modules/contact-us-authors.factory';
import '@testing-library/jest-dom/extend-expect';
import AuthorCard from '.';

const authorsKeys = Object.keys(authors);

describe('AuthorCard Component', () => {
  test('render one author', () => {
    const { container } = render(<AuthorCard author={authors[authorsKeys[0]]} />);
    const { name } = authors[authorsKeys[0]];
    expect(container).toBeTruthy();
    expect(container.querySelector('.name').innerHTML).toEqual(name);
  });

  test('render each author', () => {
    Object.keys(authors).forEach((author) => {
      const { name, email_address } = authors[author];
      const { container } = render(<AuthorCard author={authors[author]} />);
      expect(container.querySelector('.name').innerHTML).toEqual(name);
      expect(container.querySelector('a').innerHTML).toEqual(email_address);
    });
  });
});
afterEach(() => {
  cleanup();
});
