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

Commit

Permalink
(unit test update) Value returned by mocked getSettings is now config…
Browse files Browse the repository at this point in the history
…urable

Auditors: @NejcZdovc
  • Loading branch information
bsclifton committed May 5, 2017
1 parent bf9b6d3 commit 4a15901
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions test/unit/app/renderer/components/navigation/navigatorTest.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/* 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/. */
/* global describe, before, after, it */
/* global describe, before, beforeEach, after, it */

require('../../../../braveUnit')
const mockery = require('mockery')
const {mount} = require('enzyme')
const assert = require('assert')
const Immutable = require('immutable')
let Navigator, windowStore, appStore
let Navigator, windowStore, appStore, settingDefaultValue

const defaultWindowStore = Immutable.fromJS({
activeFrameKey: 0,
Expand Down Expand Up @@ -77,8 +77,11 @@ describe('Navigator component unit tests', function () {
mockery.registerMock('../../../common/state/shieldState', {
braveShieldsEnabled: () => true
})
settingDefaultValue = true
mockery.registerMock('../../../../js/settings', {
getSetting: () => true
getSetting: () => {
return settingDefaultValue
}
})
appStore = require('../../../../../../js/stores/appStoreRenderer')
windowStore = require('../../../../../../js/stores/windowStore')
Expand All @@ -95,6 +98,7 @@ describe('Navigator component unit tests', function () {
before(function () {
appStore.state = appStoreRenderer
windowStore.state = defaultWindowStore
settingDefaultValue = true
wrapper = mount(<Navigator />)
})

Expand Down Expand Up @@ -126,6 +130,7 @@ describe('Navigator component unit tests', function () {

appStore.state = appState2
windowStore.state = defaultWindowStore
settingDefaultValue = true
wrapper = mount(<Navigator />)
})

Expand All @@ -150,9 +155,10 @@ describe('Navigator component unit tests', function () {
})

describe('lion badge', function () {
before(function () {
beforeEach(function () {
appStore.state = appStoreRenderer
windowStore.state = defaultWindowStore
settingDefaultValue = true
})

it('lion icon is shown by default', function () {
Expand All @@ -167,9 +173,18 @@ describe('Navigator component unit tests', function () {
})

it('counter is not shown when disabled via settings', function () {
mockery.registerMock('../../../../js/settings', {
getSetting: () => false
})
/*
Unfortunately, this does not work.
My thought was: deregister, reregister, then reinclude Navigator (so it uses updated mock)
*/
// mockery.deregisterMock('../../../../js/settings')
// mockery.registerMock('../../../../js/settings', {
// getSetting: () => {
// return false
// }
// })
// Navigator = require('../../../../../../app/renderer/components/navigation/navigator')
settingDefaultValue = false
const wrapper = mount(<Navigator />)
assert.equal(wrapper.find('[data-test-id="lionBadge"]').length, 0)
})
Expand Down

0 comments on commit 4a15901

Please sign in to comment.