shlink-web-client/test/utils/Result.test.tsx

33 lines
1.2 KiB
TypeScript
Raw Normal View History

import { render, screen } from '@testing-library/react';
2020-12-21 20:14:11 +03:00
import { Result, ResultProps, ResultType } from '../../src/utils/Result';
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);
});
});