Skip to content

Commit

Permalink
Fixes ledger calculation when you don't have any unpinned sites
Browse files Browse the repository at this point in the history
Resolves brave#8102

Auditors: @mrose17 @bradleyrichter

Test Plan:
- Go to payments and add two publishers
- Pin one and exclude the second one
- Set 60 % for a pinned publisher
- Value should be adjusted to 100%
  • Loading branch information
NejcZdovc committed Apr 6, 2017
1 parent df1f5f0 commit 3c0dca8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
9 changes: 8 additions & 1 deletion app/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,7 @@ var synopsisNormalizer = (changedPublisher) => {
underscore.keys(synopsis.publishers).forEach((publisher) => {
if (!visibleP(publisher)) return

results.push(underscore.extend({ publisher: publisher }, underscore.omit(synopsis.publishers[publisher], 'window')))
results.push(underscore.extend({publisher: publisher}, underscore.omit(synopsis.publishers[publisher], 'window')))
}, synopsis)
results = underscore.sortBy(results, (entry) => { return -entry.scores[scorekeeper] })

Expand Down Expand Up @@ -1178,6 +1178,13 @@ var synopsisNormalizer = (changedPublisher) => {

dataPinned.push(changedObject)

// sync app store
appActions.changeLedgerPinnedPercentages(dataPinned)
} else if (dataUnPinned.length === 0 && pinnedTotal < 100) {
// when you don't have any unpinned sites and pinned total is less then 100 %
dataPinned = normalizePinned(dataPinned, pinnedTotal, 100, false)
dataPinned = roundToTarget(dataPinned, 100, 'pinPercentage')

// sync app store
appActions.changeLedgerPinnedPercentages(dataPinned)
} else {
Expand Down
13 changes: 13 additions & 0 deletions test/about/ledgerTableTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,19 @@ describe('Ledger table', function () {
}, 5000)
.waitForVisible(`${firstTableFirstRow} [data-switch-status="true"]`)
})

it('check pinned sites amount, when you have 0 eligible unpinned sites', function * () {
yield this.app.client
.tabByIndex(0)
.click(`${secondTableFirstRow} [data-test-pinned="false"]`)
.waitForVisible(`${firstTableFirstRow} [data-test-pinned="true"]`)
.click(`${firstTableFirstRow} [data-test-id="pinnedInput"]`)
.keys([Brave.keys.DELETE, Brave.keys.DELETE, '60', Brave.keys.ENTER])
.waitForInputText(`${firstTableFirstRow} [data-test-id="pinnedInput"]`, '60')
.waitForTextValue(`${secondTableSecondRow} [data-test-id="percentageValue"]`, '40')
.click(`${secondTableSecondRow} .switchBackground`)
.waitForInputText(`${firstTableFirstRow} [data-test-id="pinnedInput"]`, '100')
})
})

describe('4 publishers', function () {
Expand Down

0 comments on commit 3c0dca8

Please sign in to comment.