Added tests for ordering logic in TagsTable

This commit is contained in:
Alejandro Celaya 2021-11-01 14:10:57 +01:00
parent 9cbeef1cb4
commit 39d5853fe3

View file

@ -7,6 +7,7 @@ import { SelectedServer } from '../../src/servers/data';
import { TagsList } from '../../src/tags/reducers/tagsList';
import { rangeOf } from '../../src/utils/utils';
import SimplePaginator from '../../src/common/SimplePaginator';
import { NormalizedTag } from '../../src/tags/data';
describe('<TagsTable />', () => {
const TagsTableRow = () => null;
@ -95,4 +96,25 @@ describe('<TagsTable />', () => {
(wrapper.find(SimplePaginator).prop('setCurrentPage') as Function)(5);
expect(wrapper.find(SimplePaginator).prop('currentPage')).toEqual(5);
});
it('orders tags when column is clicked', () => {
const wrapper = createWrapper(tags(100));
const firstRowText = () => (wrapper.find('tbody').find(TagsTableRow).first().prop('tag') as NormalizedTag).tag;
expect(firstRowText()).toEqual('tag_1');
wrapper.find('thead').find('th').first().simulate('click'); // Tag column ASC
expect(firstRowText()).toEqual('tag_1');
wrapper.find('thead').find('th').first().simulate('click'); // Tag column DESC
expect(firstRowText()).toEqual('tag_99');
wrapper.find('thead').find('th').at(2).simulate('click'); // Visits column - ASC
expect(firstRowText()).toEqual('tag_100');
wrapper.find('thead').find('th').at(2).simulate('click'); // Visits column - DESC
expect(firstRowText()).toEqual('tag_1');
wrapper.find('thead').find('th').at(2).simulate('click'); // Visits column - reset
expect(firstRowText()).toEqual('tag_1');
wrapper.find('thead').find('th').at(1).simulate('click'); // Short URLs column - ASC
expect(firstRowText()).toEqual('tag_100');
wrapper.find('thead').find('th').at(1).simulate('click'); // Short URLs column - DESC
expect(firstRowText()).toEqual('tag_1');
});
});