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

Commit

Permalink
Use app action for opening update log
Browse files Browse the repository at this point in the history
Fix #9122

Auditors: @cezaraugusto
  • Loading branch information
bbondy committed May 29, 2017
1 parent 82a4223 commit d95dfa5
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 3 deletions.
20 changes: 20 additions & 0 deletions app/browser/reducers/updatesReducer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

'use strict'

const appConstants = require('../../../js/constants/appConstants')
const path = require('path')
const {app, shell} = require('electron')

const updatesReducer = (state, action) => {
switch (action.actionType) {
case appConstants.APP_UPDATE_LOG_OPENED:
shell.openItem(path.join(app.getPath('userData'), 'updateLog.log'))
break
}
return state
}

module.exports = updatesReducer
2 changes: 1 addition & 1 deletion app/renderer/components/main/updateBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class UpdateHide extends ImmutableComponent {

class UpdateLog extends ImmutableComponent {
onViewLog () {
remote.shell.openItem(path.join(remote.app.getPath('userData'), 'updateLog.log'))
appActions.updateLogOpened()
}
render () {
return <BrowserButton notificationItem secondaryColor
Expand Down
9 changes: 9 additions & 0 deletions js/actions/appActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1402,6 +1402,15 @@ const appActions = {
actionType: appConstants.APP_DEFAULT_SEARCH_ENGINE_LOADED,
searchDetail
})
},

/**
* Dispatches a message to indicate that the update log is being opened
*/
updateLogOpened: function (searchDetail) {
dispatch({
actionType: appConstants.APP_UPDATE_LOG_OPENED
})
}

}
Expand Down
3 changes: 2 additions & 1 deletion js/constants/appConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ const appConstants = {
APP_ADD_PASSWORD: _, /** @param {Object} passwordDetail */
APP_REMOVE_PASSWORD: _, /** @param {Object} passwordDetail */
APP_REMOVE_PASSWORD_SITE: _, /** @param {Object} passwordDetail */
APP_CLEAR_PASSWORDS: _
APP_CLEAR_PASSWORDS: _,
APP_UPDATE_LOG_OPENED: _
}

module.exports = mapValuesByKeys(appConstants)
3 changes: 2 additions & 1 deletion js/stores/appStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,8 @@ const handleAppAction = (action) => {
require('../../app/browser/reducers/tabMessageBoxReducer'),
require('../../app/browser/reducers/dragDropReducer'),
require('../../app/browser/reducers/extensionsReducer'),
require('../../app/browser/reducers/shareReducer')
require('../../app/browser/reducers/shareReducer'),
require('../../app/browser/reducers/updatesReducer')
]
initialized = true
appState = action.appState
Expand Down
46 changes: 46 additions & 0 deletions test/unit/app/browser/reducers/updatesReducerTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/* global describe, it, before, after */
const mockery = require('mockery')
const sinon = require('sinon')
const Immutable = require('immutable')
const assert = require('assert')
const fakeElectron = require('../../../lib/fakeElectron')

const appConstants = require('../../../../../js/constants/appConstants')
require('../../../braveUnit')

describe('updatesReducer', function () {
let updatesReducer
before(function () {
mockery.enable({
warnOnReplace: false,
warnOnUnregistered: false,
useCleanCache: true
})
mockery.registerMock('electron', fakeElectron)
updatesReducer = require('../../../../../app/browser/reducers/updatesReducer')
})

after(function () {
mockery.disable()
})

describe('APP_UPDATE_LOG_OPENED', function () {
before(function () {
this.openItemSpy = sinon.spy(fakeElectron.shell, 'openItem')
this.getPathMock = sinon.mock(fakeElectron.app, 'getPath', () => '')
// Make sure updatesReducer doesn't update state when text is updated
this.newState = updatesReducer(Immutable.Map(), {actionType: appConstants.APP_UPDATE_LOG_OPENED})
})
after(function () {
this.openItemSpy.restore()
this.getPathMock.restore()
})
it('Does not modify state', function () {
assert(this.newState.isEmpty())
})
it('Opens update log path', function () {
assert(this.openItemSpy.calledOnce)
assert(this.openItemSpy.args[0][0].endsWith('updateLog.log'))
})
})
})

0 comments on commit d95dfa5

Please sign in to comment.