import React from 'react';
import { render, cleanup } from '@testing-library/react';
import VerifiedAuthor from '../../../../images/icons/verified-author';
import AuthorTemplateOne from '.';

describe('AuthorTemplateOne Component', () => {
  it('renders author name in desired format when authorTemplateTwo is false', () => {
    const { getByText, container } = render(
      <AuthorTemplateOne
        label="Written by"
        authorName="John Doe"
        authorPath="/path-to-author"
        verify={<VerifiedAuthor />}
      />
    );

    expect(container.querySelector('.authorTemplate span')).toHaveTextContent('Written by');
    expect(container.querySelector('.authorTemplate a')).toHaveTextContent('John D.');
    expect(container.querySelector('.authorTemplate a')).toHaveAttribute('href', '/path-to-author');
    const link = getByText('John D.');
    expect(link).toBeInTheDocument();
    expect(link).toHaveAttribute('href', '/path-to-author');
  });
});

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