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 #13999 from ryanml/min-visit-time-fix
Browse files Browse the repository at this point in the history
Fixes extra visit time on first logged visit being ignored
  • Loading branch information
NejcZdovc committed May 4, 2018
1 parent 3f3c154 commit 2033592
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 4 deletions.
4 changes: 3 additions & 1 deletion app/browser/reducers/ledgerReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const tabState = require('../../common/state/tabState')
const windows = require('../windows')
const ledgerApi = require('../../browser/api/ledger')
const ledgerNotifications = require('../../browser/api/ledgerNotifications')
const {makeImmutable} = require('../../common/state/immutableUtil')
const {makeImmutable, makeJS} = require('../../common/state/immutableUtil')
const getSetting = require('../../../js/settings').getSetting

const ledgerReducer = (state, action, immutableAction) => {
Expand Down Expand Up @@ -535,7 +535,9 @@ const ledgerReducer = (state, action, immutableAction) => {
}
case appConstants.APP_ON_PUBLISHER_TOGGLE_UPDATE:
{
const viewData = makeJS(action.get('viewData'))
state = ledgerApi.pageDataChanged(state, {}, true)
state = ledgerApi.pageDataChanged(state, viewData, true)
break
}
}
Expand Down
3 changes: 2 additions & 1 deletion app/renderer/components/navigation/publisherToggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class PublisherToggle extends React.Component {
return
}
let updateTimeout = setTimeout(() => {
appActions.onPublisherToggleUpdate()
appActions.onPublisherToggleUpdate(this.props.viewData)
}, updateWait)
this.setState({updateTimeout: updateTimeout})
}
Expand Down Expand Up @@ -117,6 +117,7 @@ class PublisherToggle extends React.Component {
props.tabId = tabId
props.location = location
props.publisherKey = publisherKey
props.viewData = {location, tabId}
props.isVisibleInLedger = ledgerUtil.visibleP(state, publisherKey)
props.isEnabledForPaymentsPublisher = ledgerUtil.stickyP(state, publisherKey)
props.isVerifiedPublisher = ledgerState.getPublisherOption(state, publisherKey, 'verified')
Expand Down
5 changes: 3 additions & 2 deletions js/actions/appActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1982,9 +1982,10 @@ const appActions = {
})
},

onPublisherToggleUpdate: function () {
onPublisherToggleUpdate: function (viewData) {
dispatch({
actionType: appConstants.APP_ON_PUBLISHER_TOGGLE_UPDATE
actionType: appConstants.APP_ON_PUBLISHER_TOGGLE_UPDATE,
viewData
})
}
}
Expand Down
69 changes: 69 additions & 0 deletions test/unit/app/browser/reducers/ledgerReducerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -806,4 +806,73 @@ describe('ledgerReducer unit tests', function () {
assert.equal(testTabId, addNewLocationSpy.getCall(0).args[2])
})
})

describe('APP_ON_PUBLISHER_TOGGLE_UPDATE', function () {
let pageDataChangedSpy

beforeEach(function () {
pageDataChangedSpy = sinon.spy(fakeLedgerApi, 'pageDataChanged')
})

afterEach(function () {
pageDataChangedSpy.restore()
})

it('executes', function () {
ledgerReducer(appState, Immutable.fromJS({
actionType: appConstants.APP_ON_PUBLISHER_TOGGLE_UPDATE,
viewData: {
location: 'https://brave.com',
tabId: 21
}
}))
assert(pageDataChangedSpy.calledTwice)
})

it('modifies state', function () {
const newState = ledgerReducer(appState, Immutable.fromJS({
actionType: appConstants.APP_ON_PUBLISHER_TOGGLE_UPDATE,
viewData: {
location: 'https://brave.com',
tabId: 21
}
}))
assert.notDeepEqual(newState, appState)
})

it('passes in a empty object on first pageDataChanged call', function () {
ledgerReducer(appState, Immutable.fromJS({
actionType: appConstants.APP_ON_PUBLISHER_TOGGLE_UPDATE,
viewData: {
location: 'https://brave.com',
tabId: 21
}
}))
assert.deepEqual({}, pageDataChangedSpy.getCall(0).args[1])
})

it('passes in viewData on second pageDataChanged call', function () {
const viewData = {
location: 'https://brave.com',
tabId: 21
}
ledgerReducer(appState, Immutable.fromJS({
actionType: appConstants.APP_ON_PUBLISHER_TOGGLE_UPDATE,
viewData
}))
assert.deepEqual(viewData, pageDataChangedSpy.getCall(1).args[1])
})

it('keepInfo is set to true for both pageDataChanged calls', function () {
ledgerReducer(appState, Immutable.fromJS({
actionType: appConstants.APP_ON_PUBLISHER_TOGGLE_UPDATE,
viewData: {
location: 'https://brave.com',
tabId: 21
}
}))
assert.equal(true, pageDataChangedSpy.getCall(0).args[2])
assert.equal(true, pageDataChangedSpy.getCall(1).args[2])
})
})
})

0 comments on commit 2033592

Please sign in to comment.