2022-06-11 18:28:47 +03:00
|
|
|
import { render } from '@testing-library/react';
|
2023-02-18 12:40:37 +03:00
|
|
|
import type { OrderDir } from '../../../src/utils/helpers/ordering';
|
2023-02-18 13:11:01 +03:00
|
|
|
import { TableOrderIcon } from '../../../src/utils/table/TableOrderIcon';
|
2021-11-07 00:46:40 +03:00
|
|
|
|
|
|
|
describe('<TableOrderIcon />', () => {
|
2022-06-11 18:28:47 +03:00
|
|
|
const setUp = (field: string, currentDir?: OrderDir, className?: string) => render(
|
|
|
|
<TableOrderIcon currentOrder={{ dir: currentDir, field: 'foo' }} field={field} className={className} />,
|
|
|
|
);
|
2021-11-07 00:46:40 +03:00
|
|
|
|
|
|
|
it.each([
|
2022-03-26 14:17:42 +03:00
|
|
|
['foo', undefined],
|
|
|
|
['bar', 'DESC' as OrderDir],
|
|
|
|
['bar', 'ASC' as OrderDir],
|
2021-11-07 00:46:40 +03:00
|
|
|
])('renders empty when not all conditions are met', (field, dir) => {
|
2022-06-11 18:28:47 +03:00
|
|
|
const { container } = setUp(field, dir);
|
|
|
|
expect(container.firstChild).toBeNull();
|
2021-11-07 00:46:40 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it.each([
|
2022-06-11 18:28:47 +03:00
|
|
|
['DESC' as OrderDir],
|
|
|
|
['ASC' as OrderDir],
|
|
|
|
])('renders an icon when all conditions are met', (dir) => {
|
|
|
|
const { container } = setUp('foo', dir);
|
2021-11-07 00:46:40 +03:00
|
|
|
|
2022-06-11 18:28:47 +03:00
|
|
|
expect(container.firstChild).not.toBeNull();
|
|
|
|
expect(container.firstChild).toMatchSnapshot();
|
2021-11-07 00:46:40 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it.each([
|
2022-03-26 14:17:42 +03:00
|
|
|
[undefined, 'ms-1'],
|
|
|
|
['foo', 'foo'],
|
|
|
|
['bar', 'bar'],
|
2021-11-07 00:46:40 +03:00
|
|
|
])('renders expected classname', (className, expectedClassName) => {
|
2022-06-11 18:28:47 +03:00
|
|
|
const { container } = setUp('foo', 'ASC', className);
|
|
|
|
expect(container.firstChild).toHaveClass(expectedClassName);
|
2021-11-07 00:46:40 +03:00
|
|
|
});
|
|
|
|
});
|