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 Items from '.';

let data;
let section;
let menus;

beforeEach(() => {
  data = getNavigation();
  section = {
    modules: [data],
  };
  menus = getMenuObj(section.modules, 'menu');
});
describe('Menu Component', () => {
  test('render menu and lists', async () => {
    const { container } = render(<Items item={menus.children[3]} />);
    await waitFor(() => {
      expect(container).toBeTruthy();
      expect(container.querySelectorAll('.menuItem.level1 > ul').length).toEqual(1);
      expect(container.querySelectorAll('.menuItem.level1 > ul > li').length).toEqual(4);
      expect(container.querySelectorAll('ul')).toHaveLength(5);
    });
  });
});
afterEach(() => {
  cleanup();
});
