From 3c0dca8f8724ffc44ddae93b32f1b6a741f89c15 Mon Sep 17 00:00:00 2001 From: NejcZdovc Date: Thu, 6 Apr 2017 10:25:10 +0200 Subject: [PATCH] Fixes ledger calculation when you don't have any unpinned sites Resolves #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% --- app/ledger.js | 9 ++++++++- test/about/ledgerTableTest.js | 13 +++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/app/ledger.js b/app/ledger.js index 5be54a5aaba..4738c8e3249 100644 --- a/app/ledger.js +++ b/app/ledger.js @@ -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] }) @@ -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 { diff --git a/test/about/ledgerTableTest.js b/test/about/ledgerTableTest.js index 2bb14212b12..76cfd87e62c 100644 --- a/test/about/ledgerTableTest.js +++ b/test/about/ledgerTableTest.js @@ -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 () {