import React from 'react';
import { render, fireEvent } from '@testing-library/react';
import 'jest-styled-components';
import { Grommet } from '../../Grommet';
import { Text } from '../../Text';
import { WorldMap } from '..';
describe('WorldMap', () => {
test('default', () => {
const { container } = render(
,
);
expect(container.firstChild).toMatchSnapshot();
});
test('color', () => {
const { container } = render(
,
);
expect(container.firstChild).toMatchSnapshot();
});
test('continents', () => {
const { container } = render(
{},
},
]}
/>
,
);
expect(container.firstChild).toMatchSnapshot();
});
test('places', () => {
const { container } = render(
{},
},
]}
/>
,
);
expect(container.firstChild).toMatchSnapshot();
});
test('onSelectPlace and events of places', () => {
const onClick = jest.fn();
const onHover = jest.fn();
const { container, getByLabelText } = render(
{}}
/>
,
);
fireEvent.mouseOver(getByLabelText('Sydney'));
expect(container.firstChild).toMatchSnapshot();
expect(onHover).toHaveBeenCalledTimes(1);
fireEvent.mouseOut(getByLabelText('Sydney'));
expect(container.firstChild).toMatchSnapshot();
fireEvent.click(getByLabelText('Sydney'));
expect(onClick).toHaveBeenCalledTimes(1);
fireEvent.focus(getByLabelText('Sydney'));
fireEvent.blur(getByLabelText('Sydney'));
expect(container.firstChild).toMatchSnapshot();
});
test('events on continents', () => {
const onClick = jest.fn();
const onHover = jest.fn();
const { container, getByLabelText } = render(
,
);
fireEvent.mouseOver(getByLabelText('Africa'));
expect(container.firstChild).toMatchSnapshot();
expect(onHover).toHaveBeenCalledTimes(1);
fireEvent.mouseOut(getByLabelText('Africa'));
expect(container.firstChild).toMatchSnapshot();
fireEvent.click(getByLabelText('Africa'));
expect(onClick).toHaveBeenCalledTimes(1);
fireEvent.focus(getByLabelText('Africa'));
fireEvent.blur(getByLabelText('Africa'));
expect(container.firstChild).toMatchSnapshot();
});
test('fill', () => {
const { container } = render(
,
);
expect(container.firstChild).toMatchSnapshot();
});
test('onClick handlers', () => {
const onPlaceClick = jest.fn();
const onContinentClick = jest.fn();
const { getByLabelText } = render(
,
);
fireEvent.click(getByLabelText('Sydney'));
expect(onPlaceClick).toHaveBeenCalledTimes(1);
expect(onPlaceClick).toHaveBeenCalledWith('Sydney');
fireEvent.click(getByLabelText('Africa'));
expect(onContinentClick).toHaveBeenCalledTimes(1);
expect(onContinentClick).toHaveBeenCalledWith('Africa');
});
test('onHover handlers', () => {
const onPlaceHover = jest.fn();
const onContinentHover = jest.fn();
const { getByLabelText } = render(
,
);
fireEvent.mouseEnter(getByLabelText('Sydney'));
expect(onPlaceHover).toHaveBeenCalledTimes(1);
expect(onPlaceHover).toHaveBeenCalledWith(true);
expect(onPlaceHover).not.toHaveBeenCalledWith(false);
fireEvent.mouseLeave(getByLabelText('Sydney'));
expect(onPlaceHover).toHaveBeenCalledTimes(2);
expect(onPlaceHover).toHaveBeenCalledWith(false);
fireEvent.mouseEnter(getByLabelText('Africa'));
expect(onContinentHover).toHaveBeenCalledTimes(1);
expect(onContinentHover).toHaveBeenCalledWith(true);
expect(onContinentHover).not.toHaveBeenCalledWith(false);
fireEvent.mouseLeave(getByLabelText('Africa'));
expect(onContinentHover).toHaveBeenCalledTimes(2);
expect(onContinentHover).toHaveBeenCalledWith(false);
});
test('places content', () => {
const { container } = render(
Sydney,
dropProps: {
align: { left: 'right' },
elevation: 'medium',
margin: { left: 'small' },
},
},
]}
/>
,
);
expect(container.firstChild).toMatchSnapshot();
});
});