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 NavigationProvider from '~organisms/navigation/navigationContext';
import { getMenuObj } from '~helpers/menu';
import MenuIcon from '.';

let data;
let section;
let menus;
const click = jest.fn();

beforeEach(() => {
  data = getNavigation();
  section = {
    modules: [data],
  };
  menus = getMenuObj(section.modules, 'menu');
});
describe('Menu Component', () => {
  test('test menu icon', async () => {
    const { container } = render(<MenuIcon />);
    await waitFor(() => {
      expect(container.querySelectorAll('.menuContainer')).toBeTruthy();
      expect(container.querySelectorAll('.menuIcon')).toHaveLength(1);
    });
  });
  test('test menu icon click event', async () => {
    const mockFn = jest.fn();
    const { container } = render(<MenuIcon onClick={mockFn} />);
    const btn = container.querySelector('.menuIconContainer');
    await waitFor(() => {
      expect(container.querySelectorAll('.menuContainer')).toBeTruthy();
      fireEvent.click(btn);
      expect(mockFn).toHaveBeenCalled();
    });
  });
});
afterEach(() => {
  cleanup();
});
