2022-07-10 00:03:21 +03:00
|
|
|
import { screen } from '@testing-library/react';
|
2023-04-13 22:48:29 +03:00
|
|
|
import { fromPartial } from '@total-typescript/shoehorn';
|
2023-02-18 12:40:37 +03:00
|
|
|
import type { DomainStatus } from '../../../src/domains/data';
|
2021-12-29 00:48:35 +03:00
|
|
|
import { DomainStatusIcon } from '../../../src/domains/helpers/DomainStatusIcon';
|
2022-07-10 20:44:49 +03:00
|
|
|
import { renderWithEvents } from '../../__helpers__/setUpTest';
|
2021-12-29 00:48:35 +03:00
|
|
|
|
|
|
|
describe('<DomainStatusIcon />', () => {
|
2023-05-27 12:57:26 +03:00
|
|
|
const matchMedia = vi.fn().mockReturnValue(fromPartial<MediaQueryList>({ matches: false }));
|
2022-07-10 00:03:21 +03:00
|
|
|
const setUp = (status: DomainStatus) => renderWithEvents(
|
|
|
|
<DomainStatusIcon status={status} matchMedia={matchMedia} />,
|
|
|
|
);
|
2021-12-29 00:48:35 +03:00
|
|
|
|
2023-05-27 12:57:26 +03:00
|
|
|
beforeEach(vi.clearAllMocks);
|
2021-12-29 00:48:35 +03:00
|
|
|
|
|
|
|
it.each([
|
2022-05-09 20:45:09 +03:00
|
|
|
['validating' as DomainStatus],
|
|
|
|
['invalid' as DomainStatus],
|
|
|
|
['valid' as DomainStatus],
|
|
|
|
])('renders expected icon and tooltip when status is not validating', (status) => {
|
|
|
|
const { container } = setUp(status);
|
|
|
|
expect(container.firstChild).toMatchSnapshot();
|
2021-12-29 00:48:35 +03:00
|
|
|
});
|
2021-12-29 01:14:55 +03:00
|
|
|
|
|
|
|
it.each([
|
2022-05-09 20:45:09 +03:00
|
|
|
['invalid' as DomainStatus],
|
|
|
|
['valid' as DomainStatus],
|
|
|
|
])('renders proper tooltip based on state', async (status) => {
|
2022-05-10 21:54:14 +03:00
|
|
|
const { container, user } = setUp(status);
|
2021-12-29 01:14:55 +03:00
|
|
|
|
2022-05-10 21:54:14 +03:00
|
|
|
container.firstElementChild && await user.hover(container.firstElementChild);
|
2022-05-09 20:45:09 +03:00
|
|
|
expect(await screen.findByRole('tooltip')).toMatchSnapshot();
|
2021-12-29 01:14:55 +03:00
|
|
|
});
|
2021-12-29 00:48:35 +03:00
|
|
|
});
|