mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2024-12-23 09:30:31 +03:00
Added TableOrderIcon test
This commit is contained in:
parent
fe81e023e8
commit
303900756d
1 changed files with 47 additions and 0 deletions
47
test/utils/table/TableOrderIcon.test.tsx
Normal file
47
test/utils/table/TableOrderIcon.test.tsx
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
import { shallow, ShallowWrapper } from 'enzyme';
|
||||||
|
import { faCaretDown as caretDownIcon, faCaretUp as caretUpIcon } from '@fortawesome/free-solid-svg-icons';
|
||||||
|
import { TableOrderIcon } from '../../../src/utils/table/TableOrderIcon';
|
||||||
|
import { OrderDir } from '../../../src/utils/helpers/ordering';
|
||||||
|
|
||||||
|
describe('<TableOrderIcon />', () => {
|
||||||
|
let wrapper: ShallowWrapper;
|
||||||
|
const createWrapper = (field: string, currentDir?: OrderDir, className?: string) => {
|
||||||
|
wrapper = shallow(
|
||||||
|
<TableOrderIcon currentOrder={{ dir: currentDir, field: 'foo' }} field={field} className={className} />,
|
||||||
|
);
|
||||||
|
|
||||||
|
return wrapper;
|
||||||
|
};
|
||||||
|
|
||||||
|
afterEach(() => wrapper?.unmount());
|
||||||
|
|
||||||
|
it.each([
|
||||||
|
[ 'foo', undefined ],
|
||||||
|
[ 'bar', 'DESC' as OrderDir ],
|
||||||
|
[ 'bar', 'ASC' as OrderDir ],
|
||||||
|
])('renders empty when not all conditions are met', (field, dir) => {
|
||||||
|
const wrapper = createWrapper(field, dir);
|
||||||
|
|
||||||
|
expect(wrapper.html()).toEqual(null);
|
||||||
|
});
|
||||||
|
|
||||||
|
it.each([
|
||||||
|
[ 'DESC' as OrderDir, caretDownIcon ],
|
||||||
|
[ 'ASC' as OrderDir, caretUpIcon ],
|
||||||
|
])('renders an icon when all conditions are met', (dir, expectedIcon) => {
|
||||||
|
const wrapper = createWrapper('foo', dir);
|
||||||
|
|
||||||
|
expect(wrapper.html()).not.toEqual(null);
|
||||||
|
expect(wrapper.prop('icon')).toEqual(expectedIcon);
|
||||||
|
});
|
||||||
|
|
||||||
|
it.each([
|
||||||
|
[ undefined, 'ml-1' ],
|
||||||
|
[ 'foo', 'foo' ],
|
||||||
|
[ 'bar', 'bar' ],
|
||||||
|
])('renders expected classname', (className, expectedClassName) => {
|
||||||
|
const wrapper = createWrapper('foo', 'ASC', className);
|
||||||
|
|
||||||
|
expect(wrapper.prop('className')).toEqual(expectedClassName);
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in a new issue