import React from 'react';
import { render, cleanup, waitFor, fireEvent } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';

import getNavigation from '~tests/factories/sections/navigationStatic.factory';
import { getMenuObj } from '~helpers/menu';
import Item from '.';

let data;
let section;
let menus;

beforeEach(() => {
  data = getNavigation();
  section = {
    modules: [data],
  };
  menus = getMenuObj(section.modules, 'menu');
});
describe('Menu Component', () => {
  test('render menu link item', async () => {
    const { container, getByText } = render(<Item item={menus.children[3]} />);
    await waitFor(() => {
      expect(container).toBeTruthy();
      expect(container.querySelectorAll('a')).toHaveLength(1);
      expect(getByText('Sportsbooks').getAttribute('href')).toEqual('/sportsbooks');
    });
  });

  test('render item ', async () => {
    const { container, getByText } = render(<Item item={menus.children[3]} />);
    await waitFor(() => {
      expect(container).toBeTruthy();
      expect(container.querySelectorAll('a')).toHaveLength(1);
      expect(getByText('Sportsbooks').getAttribute('href')).toEqual('/sportsbooks');
    });
  });
});
afterEach(() => {
  cleanup();
});
