diff --git a/src/components/screens/monitor/delegates/delegates.test.js b/src/components/screens/monitor/delegates/delegates.test.js index 2713d24ed4..ba76f98bf5 100644 --- a/src/components/screens/monitor/delegates/delegates.test.js +++ b/src/components/screens/monitor/delegates/delegates.test.js @@ -43,6 +43,59 @@ describe('Delegates monitor page', () => { }); }; + function initSanctionedProps() { + props.sanctionedDelegates = { + isLoading: false, + data: [ + { + address: 'lsktaa9xuys6hztyaryvx6msu279mpkn9sz6w5or2', + consecutiveMissedBlocks: 220, + isBanned: true, + lastForgedHeight: 16695471, + producedBlocks: 1404, + rank: 1563, + registrationHeight: 16331164, + rewards: '140200000000', + status: 'banned', + totalVotesReceived: '2170000000000', + username: 'ziqi', + voteWeight: '0', + }, + { + address: 'lsksaca4v9r3uotdzdhje3smwa49rvj2h2sn5yskt', + consecutiveMissedBlocks: 0, + isBanned: false, + lastForgedHeight: 16784595, + producedBlocks: 4929, + rank: 1503, + registrationHeight: 16270293, + rewards: '491800000000', + status: 'punished', + totalVotesReceived: '8771000000000', + username: 'liskjp', + voteWeight: '0', + }, + { + address: 'lskr39gqjxhepd9o5txgmups9zjhjaadfjgm5dc87', + consecutiveMissedBlocks: 229, + isBanned: true, + lastForgedHeight: 16739690, + producedBlocks: 2014, + rank: 1436, + registrationHeight: 16270293, + rewards: '201125000000', + status: 'banned', + totalVotesReceived: '2356000000000', + username: 'acheng', + voteWeight: '0', + }, + ], + loadData: jest.fn(), + clearData: jest.fn(), + urlSearchParams: {}, + }; + } + const { blocks } = store.getState(); beforeEach(() => { @@ -140,4 +193,27 @@ describe('Delegates monitor page', () => { wrapper = setup(props); expect(wrapper.find('a.delegate-row')).toHaveLength(blocks.forgers.length); }); + + it('properly sorts delegates by their status', () => { + initSanctionedProps(); + wrapper = setup(props); + switchTab('sanctioned'); + + const sortByBtn = wrapper.find('span.sort-by'); + const statuses = wrapper.find('a.delegate-row > span:first-child ~ span ~ span > span').map(ele => ele.text()); + statuses.forEach((status, index) => { + expect(status).equal(index === 1 ? 'Punished' : 'Banned'); + }); + + sortByBtn.last().simulate('click'); + + statuses.forEach((status, index) => { + expect(status).equal(index === 2 ? 'Banned' : 'Punished'); + }); + + wrapper.find('span.sort-by').at(1).simulate('click'); + statuses.forEach((status, index) => { + expect(status).equal(index === 2 ? 'Punished' : 'Banned'); + }); + }); }); diff --git a/src/components/screens/monitor/delegates/delegatesTable/index.js b/src/components/screens/monitor/delegates/delegatesTable/index.js index f84b8fe071..07d06b63b6 100644 --- a/src/components/screens/monitor/delegates/delegatesTable/index.js +++ b/src/components/screens/monitor/delegates/delegatesTable/index.js @@ -25,6 +25,7 @@ const TableWrapper = compose( } return 0; }, + sanctionedStatus: (a, b, direction) => ((direction === 'asc' ? a.status > b.status : b.status > a.status) ? 1 : -1), }), )(({ delegates, handleLoadMore, t, activeTab, blocks, diff --git a/src/components/screens/monitor/delegates/delegatesTable/tableHeader.js b/src/components/screens/monitor/delegates/delegatesTable/tableHeader.js index 2638279ad0..1fe78a1190 100644 --- a/src/components/screens/monitor/delegates/delegatesTable/tableHeader.js +++ b/src/components/screens/monitor/delegates/delegatesTable/tableHeader.js @@ -106,7 +106,7 @@ export default (activeTab, changeSort, t) => ([ classList: getStatusClass(activeTab), sort: { fn: changeSort, - key: 'status', + key: activeTab === 'sanctioned' ? 'sanctionedStatus' : 'status', }, }, ]);