From 39d5853fe3529508fc4e15b3fd4431b9f494aef7 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Mon, 1 Nov 2021 14:10:57 +0100 Subject: [PATCH] Added tests for ordering logic in TagsTable --- test/tags/TagsTable.test.tsx | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/tags/TagsTable.test.tsx b/test/tags/TagsTable.test.tsx index 8530406c..a1a2e52c 100644 --- a/test/tags/TagsTable.test.tsx +++ b/test/tags/TagsTable.test.tsx @@ -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('', () => { const TagsTableRow = () => null; @@ -95,4 +96,25 @@ describe('', () => { (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'); + }); });