{"size": 2268, "ext": "js", "max_stars_repo_path": "packages/ui-kit/__tests__/menu-drawer.test.js", "max_stars_repo_name": "lucaspr98/ui-kit", "max_stars_repo_stars_event_min_datetime": "2019-01-31T19:22:49.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-31T18:56:20.000Z", "max_issues_repo_path": "packages/ui-kit/__tests__/menu-drawer.test.js", "max_issues_repo_name": "lucaspr98/ui-kit", "max_issues_repo_issues_event_min_datetime": "2019-02-13T15:14:02.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-26T19:31:48.000Z", "max_forks_repo_path": "packages/ui-kit/__tests__/menu-drawer.test.js", "max_forks_repo_name": "lucaspr98/ui-kit", "max_forks_repo_forks_event_min_datetime": "2019-01-28T23:11:11.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-15T19:01:04.000Z"}
{"max_stars_count": 5, "max_issues_count": 48, "max_forks_count": 10, "avg_line_length": 25.7727272727, "max_line_length": 155, "alphanum_fraction": 0.6494708995}
import { TestProvider } from 'TestProvider';
import { render, fireEvent } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';
import { Drawer } from 'components/Menu';
import * as React from 'react';

const drawerDemoItems = [
  {
    title: 'Portal',
    children: [
      {
        title: 'Comunicados',
        children: [{ title: 'Meus Comunicados' }, { title: 'Criar' }],
      },
      {
        title: 'Usuários',
      },
      {
        title: 'Relatórios',
      },
    ],
  },
];

const drawerArgs = {
  productName: '',
  subtitle: '',
  title: '',
  onClose: () => {},
  open: true,
  srcAvatar:
    'https://thumbs.dreamstime.com/b/portrait-young-man-beard-hair-style-male-avatar-vector-portrait-young-man-beard-hair-style-male-avatar-105082137.jpg',
  logoProps: {
    src:
      'https://www.facom.ufms.br/wp-content/uploads/2019/05/ts-fundo-claro.png',
    height: 60,
    width: 130,
  },
};

test('Render Drawer', () => {
  const { getByText } = render(
    <TestProvider>
      <Drawer {...drawerArgs} items={drawerDemoItems} />
    </TestProvider>
  );
  const element = getByText('Portal');

  expect(element).toContainElement(element);
});

test('Render open item', () => {
  window.HTMLElement.prototype.scrollIntoView = jest.fn();
  const { getByText, queryByText } = render(
    <TestProvider>
      <Drawer {...drawerArgs} items={drawerDemoItems} />
    </TestProvider>
  );
  const portal = getByText('Portal');
  const comunicados = queryByText('Comunicados');

  expect(comunicados).not.toBeInTheDocument();
  fireEvent.click(portal);
  const comunicados2 = getByText('Comunicados');

  expect(comunicados2).toBeInTheDocument();
});

test('Render close item', () => {
  window.HTMLElement.prototype.scrollIntoView = jest.fn();
  const { getByText, queryByText } = render(
    <TestProvider>
      <Drawer {...drawerArgs} items={drawerDemoItems} />
    </TestProvider>
  );

  const portal = getByText('Portal');
  const comunicados = queryByText('Comunicados');

  expect(comunicados).not.toBeInTheDocument();
  fireEvent.click(portal);
  const comunicados2 = getByText('Comunicados');

  expect(comunicados2).toBeInTheDocument();
  fireEvent.click(portal);
  expect(comunicados).not.toBeInTheDocument();
});
