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

jest.mock('../Portal');

let openTestValue = true;
const closeTestValue = () => (openTestValue = false);

afterEach(cleanup);

test('should take a snapshot', () => {
	const { asFragment } = render(
		<Menu close={closeTestValue} id="test" open={openTestValue} />
	);

	expect(asFragment()).toMatchSnapshot();
});

describe('Tests Menu', () => {
	test('with content', () => {
		const { getByTestId } = render(
			<Menu
				data-testid="menu-id"
				close={closeTestValue}
				id="test"
				open={openTestValue}>
				<p>It&apos;s Menu content</p>
			</Menu>
		);

		expect(getByTestId('menu-id')).toBeInTheDocument();
	});
	test('with open=false', () => {
		const { getByTestId } = render(
			<div data-testid="menu-wrapper-id">
				<Menu
					data-testid="menu-id"
					close={closeTestValue}
					id="test"
					open={false}
				/>
			</div>
		);

		expect(getByTestId('menu-wrapper-id')).toBeInTheDocument();
		expect(getByTestId('menu-wrapper-id')).toBeEmptyDOMElement();
	});
});
