Skip to content

Commit

Permalink
Merge pull request #4047 from LiskHQ/3989-fix-sorting-of-sactioned-de…
Browse files Browse the repository at this point in the history
…legates

Fixed status sorting issue on delegates sanctioned tab - Closes #3989
  • Loading branch information
ManuGowda authored Jan 7, 2022
2 parents bc7c0a2 + 231769e commit 35b65a4
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 1 deletion.
76 changes: 76 additions & 0 deletions src/components/screens/monitor/delegates/delegates.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down Expand Up @@ -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');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export default (activeTab, changeSort, t) => ([
classList: getStatusClass(activeTab),
sort: {
fn: changeSort,
key: 'status',
key: activeTab === 'sanctioned' ? 'sanctionedStatus' : 'status',
},
},
]);

0 comments on commit 35b65a4

Please sign in to comment.