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

const page = {};

beforeEach(() => {
  siteSchema.email = [
    { email: 'sales@irishluck.ie', contact_type: 'Sales Team' },
    { email: 'support@irishluck.ie', contact_type: 'Support Team' },
    { email: 'contact@irishluck.ie', contact_type: ' General Info' },
  ];
  page.siteSchema = { ...siteSchema };
});
describe('Site Contacts Component', () => {
  test('render site contacts', () => {
    const { container } = render(<SiteContacts page={page} />);
    const { email } = siteSchema;

    expect(container).toBeTruthy();
    expect(container.querySelector('.generalContacts')).toBeTruthy();
    expect(container.querySelectorAll('.generalContacts li')).toHaveLength(email.length);
    expect(container.querySelector('.generalContacts li p')).toHaveTextContent(
      email[0].contact_type
    );
    expect(container.querySelectorAll('.generalContacts li p')[1]).toHaveTextContent(
      email[1].contact_type
    );
    expect(container.querySelectorAll('.generalContacts li a')[2]).toHaveAttribute(
      'href',
      `mailto:${email[2].email}`
    );
    expect(container.querySelectorAll('.generalContacts li a')[0]).toHaveTextContent(
      email[0].email
    );
  });
});
afterEach(() => {
  cleanup();
});
