2022-07-10 00:03:21 +03:00
|
|
|
import { screen, waitFor } from '@testing-library/react';
|
2023-04-14 10:28:53 +03:00
|
|
|
import { fromPartial } from '@total-typescript/shoehorn';
|
2023-08-02 10:01:44 +03:00
|
|
|
import { OpenMapModalBtn } from '../../../src/visits/helpers/OpenMapModalBtn';
|
|
|
|
import type { CityStats } from '../../../src/visits/types';
|
2022-07-10 20:44:49 +03:00
|
|
|
import { renderWithEvents } from '../../__helpers__/setUpTest';
|
2019-01-09 22:11:22 +03:00
|
|
|
|
|
|
|
describe('<OpenMapModalBtn />', () => {
|
|
|
|
const title = 'Foo';
|
2023-04-14 10:28:53 +03:00
|
|
|
const locations: CityStats[] = [
|
|
|
|
fromPartial({ cityName: 'foo', count: 30, latLong: [5, 5] }),
|
|
|
|
fromPartial({ cityName: 'bar', count: 45, latLong: [88, 88] }),
|
2019-03-10 15:05:20 +03:00
|
|
|
];
|
2022-07-10 00:03:21 +03:00
|
|
|
const setUp = (activeCities?: string[]) => renderWithEvents(
|
|
|
|
<OpenMapModalBtn modalTitle={title} locations={locations} activeCities={activeCities} />,
|
|
|
|
);
|
2019-01-09 22:11:22 +03:00
|
|
|
|
2022-06-11 19:10:08 +03:00
|
|
|
it('renders tooltip on button hover and opens modal on click', async () => {
|
|
|
|
const { user } = setUp();
|
2019-01-09 22:11:22 +03:00
|
|
|
|
2022-06-11 19:10:08 +03:00
|
|
|
expect(screen.queryByRole('tooltip')).not.toBeInTheDocument();
|
|
|
|
expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
|
|
|
|
expect(screen.queryByRole('menu')).not.toBeInTheDocument();
|
2019-01-09 22:11:22 +03:00
|
|
|
|
2022-06-11 19:10:08 +03:00
|
|
|
await user.click(screen.getByRole('button'));
|
|
|
|
await waitFor(() => expect(screen.getByRole('tooltip')).toBeInTheDocument());
|
|
|
|
await waitFor(() => expect(screen.getByRole('dialog')).toBeInTheDocument());
|
|
|
|
expect(screen.queryByRole('menu')).not.toBeInTheDocument();
|
2019-01-09 22:11:22 +03:00
|
|
|
});
|
|
|
|
|
2022-06-11 19:10:08 +03:00
|
|
|
it('opens dropdown instead of modal when a list of active cities has been provided', async () => {
|
|
|
|
const { user } = setUp(['bar']);
|
2019-03-10 15:05:20 +03:00
|
|
|
|
2022-06-11 19:10:08 +03:00
|
|
|
expect(screen.queryByRole('menu')).not.toBeInTheDocument();
|
|
|
|
expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
|
2019-03-10 15:05:20 +03:00
|
|
|
|
2022-06-11 19:10:08 +03:00
|
|
|
await user.click(screen.getByRole('button'));
|
2019-03-10 15:05:20 +03:00
|
|
|
|
2022-06-11 19:10:08 +03:00
|
|
|
await waitFor(() => expect(screen.getByRole('menu')).toBeInTheDocument());
|
|
|
|
expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
|
|
|
|
});
|
2019-03-10 15:05:20 +03:00
|
|
|
|
2023-08-08 13:43:09 +03:00
|
|
|
// FIXME This test is throwing an uncaught error, which makes vitest fail execution.
|
|
|
|
// The error is "TypeError: Cannot read properties of null (reading 'contains')"
|
|
|
|
it.skip.each([
|
2022-06-11 19:10:08 +03:00
|
|
|
['Show all locations'],
|
|
|
|
['Show locations in current page'],
|
|
|
|
])('filters out non-active cities from list of locations', async (name) => {
|
|
|
|
const { user } = setUp(['bar']);
|
2019-03-10 15:05:20 +03:00
|
|
|
|
2022-06-11 19:10:08 +03:00
|
|
|
await user.click(screen.getByRole('button'));
|
|
|
|
await user.click(screen.getByRole('menuitem', { name }));
|
2019-01-09 22:11:22 +03:00
|
|
|
|
2023-08-08 13:43:09 +03:00
|
|
|
expect(screen.getByRole('dialog')).toMatchSnapshot();
|
2019-01-09 22:11:22 +03:00
|
|
|
});
|
|
|
|
});
|