Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
Merge pull request #14315 from NejcZdovc/fix/#14287-sort
Browse files Browse the repository at this point in the history
Fixes less sort for ledger table
  • Loading branch information
NejcZdovc committed Jun 2, 2018
1 parent 4f98aad commit bd9920b
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/common/state/ledgerState.js
Original file line number Diff line number Diff line change
Expand Up @@ -523,8 +523,10 @@ const ledgerState = {
* ABOUT PAGE
*/
// TODO (optimization) don't have two almost identical object in state (synopsi->publishers and about->synopsis)
saveAboutSynopsis: (state, publishers) => {
saveAboutSynopsis: (state, publishers = Immutable.List()) => {
state = validateState(state)
publishers = makeImmutable(publishers)
publishers = publishers.sort((prev, next) => (parseFloat(prev.get('percentage')) - parseFloat(next.get('percentage'))) * -1)
state = ledgerState.setAboutProp(state, 'synopsis', publishers)
state = ledgerState.setAboutProp(state, 'synopsisOptions', ledgerState.getSynopsisOptions(state))

Expand Down
72 changes: 72 additions & 0 deletions test/unit/app/common/state/ledgerStateTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -841,4 +841,76 @@ describe('ledgerState unit test', function () {
assert.deepEqual(result.toJS(), expectedState.toJS())
})
})

describe('saveAboutSynopsis', function () {
it('publisher list is empty', function () {
const result = ledgerState.saveAboutSynopsis(defaultState)
const expectedState = defaultState
.setIn(['ledger', 'about'], Immutable.fromJS({
synopsis: [],
synopsisOptions: {}
}))
assert.deepEqual(result.toJS(), expectedState.toJS())
})

it('publisher list is JS object', function () {
const result = ledgerState.saveAboutSynopsis(defaultState, [
{
'clifton.io': {
percentage: 10
}
}
])
const expectedState = defaultState
.setIn(['ledger', 'about'], Immutable.fromJS({
synopsis: [{
'clifton.io': {
percentage: 10
}
}],
synopsisOptions: {}
}))
assert.deepEqual(result.toJS(), expectedState.toJS())
})

it('publisher list is sorted desc', function () {
const result = ledgerState.saveAboutSynopsis(defaultState, [
{
'clifton.io': {
percentage: 10
},
'clifton1.io': {
percentage: 2
},
'clifton2.io': {
percentage: 30
},
'clifton3.io': {
percentage: 1
}
}
])
const expectedState = defaultState
.setIn(['ledger', 'about'], Immutable.fromJS({
synopsis: [
{
'clifton2.io': {
percentage: 30
},
'clifton.io': {
percentage: 10
},
'clifton1.io': {
percentage: 2
},
'clifton3.io': {
percentage: 1
}
}
],
synopsisOptions: {}
}))
assert.deepEqual(result.toJS(), expectedState.toJS())
})
})
})

0 comments on commit bd9920b

Please sign in to comment.