shlink-web-client/shlink-frontend-kit/test/block/Result.test.tsx

34 lines
1.2 KiB
TypeScript
Raw Normal View History

import { render, screen } from '@testing-library/react';
import type { ResultProps, ResultType } from '../../src';
import { Result } from '../../src';
2020-12-21 20:14:11 +03:00
describe('<Result />', () => {
const setUp = (props: ResultProps) => render(<Result {...props} />);
2020-12-21 20:14:11 +03:00
it.each([
2022-03-26 14:17:42 +03:00
['success' as ResultType, 'bg-main text-white'],
['error' as ResultType, 'bg-danger text-white'],
['warning' as ResultType, 'bg-warning'],
2020-12-21 20:14:11 +03:00
])('renders expected classes based on type', (type, expectedClasses) => {
setUp({ type });
expect(screen.getByRole('document')).toHaveClass(expectedClasses);
2020-12-21 20:14:11 +03:00
});
it.each([
2022-03-26 14:17:42 +03:00
['foo'],
['bar'],
2020-12-21 20:14:11 +03:00
])('renders provided classes in root element', (className) => {
const { container } = setUp({ type: 'success', className });
expect(container.firstChild).toHaveClass(className);
2020-12-21 20:14:11 +03:00
});
it.each([{ small: true }, { small: false }])('renders small results properly', ({ small }) => {
const { container } = setUp({ type: 'success', small });
const bigElement = container.querySelectorAll('.col-md-10');
const smallElement = container.querySelectorAll('.col-12');
2020-12-21 20:14:11 +03:00
expect(bigElement).toHaveLength(small ? 0 : 1);
expect(smallElement).toHaveLength(small ? 1 : 0);
});
});