shlink-web-client/test/domains/helpers/DomainStatusIcon.test.tsx

34 lines
1.2 KiB
TypeScript
Raw Normal View History

import { screen } from '@testing-library/react';
2021-12-29 01:22:55 +03:00
import { Mock } from 'ts-mockery';
2021-12-29 00:48:35 +03:00
import { DomainStatus } from '../../../src/domains/data';
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 />', () => {
2021-12-29 01:22:55 +03:00
const matchMedia = jest.fn().mockReturnValue(Mock.of<MediaQueryList>({ matches: false }));
const setUp = (status: DomainStatus) => renderWithEvents(
<DomainStatusIcon status={status} matchMedia={matchMedia} />,
);
2021-12-29 00:48:35 +03:00
2021-12-29 01:22:55 +03:00
beforeEach(jest.clearAllMocks);
2021-12-29 00:48:35 +03:00
it.each([
['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
});
it.each([
['invalid' as DomainStatus],
['valid' as DomainStatus],
])('renders proper tooltip based on state', async (status) => {
const { container, user } = setUp(status);
container.firstElementChild && await user.hover(container.firstElementChild);
expect(await screen.findByRole('tooltip')).toMatchSnapshot();
});
2021-12-29 00:48:35 +03:00
});