shlink-web-client/test/utils/table/TableOrderIcon.test.tsx

38 lines
1.2 KiB
TypeScript
Raw Normal View History

import { render } from '@testing-library/react';
2021-11-07 00:46:40 +03:00
import { TableOrderIcon } from '../../../src/utils/table/TableOrderIcon';
import { OrderDir } from '../../../src/utils/helpers/ordering';
describe('<TableOrderIcon />', () => {
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) => {
const { container } = setUp(field, dir);
expect(container.firstChild).toBeNull();
2021-11-07 00:46:40 +03:00
});
it.each([
['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
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) => {
const { container } = setUp('foo', 'ASC', className);
expect(container.firstChild).toHaveClass(expectedClassName);
2021-11-07 00:46:40 +03:00
});
});