2022-07-08 12:24:19 +03:00
|
|
|
import { render, screen } from '@testing-library/react';
|
2023-08-02 09:15:50 +03:00
|
|
|
import type { ResultProps, ResultType } from '../../src';
|
|
|
|
import { Result } from '../../src';
|
2020-12-21 20:14:11 +03:00
|
|
|
|
|
|
|
describe('<Result />', () => {
|
2022-07-08 12:24:19 +03:00
|
|
|
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) => {
|
2022-07-08 12:24:19 +03:00
|
|
|
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) => {
|
2022-07-08 12:24:19 +03:00
|
|
|
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 }) => {
|
2022-07-08 12:24:19 +03:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
});
|