Skip to content

Commit

Permalink
Add tests for extensionsTab
Browse files Browse the repository at this point in the history
  • Loading branch information
cezaraugusto committed Apr 10, 2017
1 parent 5b162c9 commit caa2c39
Show file tree
Hide file tree
Showing 3 changed files with 424 additions and 0 deletions.
42 changes: 42 additions & 0 deletions test/unit/app/common/state/extensionStateTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -640,4 +640,46 @@ describe('extensionState', function () {
commonTests()
})
})

describe('extensionUninstalled', function () {
describe('extensionId has been uninstalled', function () {
before(function () {
this.state = defaultAppState.setIn(['extensions', 'androidDragon'], Immutable.fromJS({
name: 'android dragon dinossaur',
id: 'androidDragon',
url: 'some_url',
path: 'some/path',
version: '1.0',
description: 'epic game about an android dragon dinossaur',
manifest: {
manifest_value: 'dinossaur'
},
enabled: true,
excluded: false
}))
this.state = extensionState.extensionUninstalled(this.state, Immutable.fromJS({
extensionId: 'androidDragon'
}))
})

it('should set the excluded property to true', function () {
let extension = this.state.getIn(['extensions', 'androidDragon'])
assert.equal(extension.get('excluded'), true)
})

it('should not alter any other properties', function () {
let extension = this.state.getIn(['extensions', 'androidDragon'])
assert.equal(extension.get('name'), 'android dragon dinossaur')
assert.equal(extension.get('id'), 'androidDragon')
assert.equal(extension.get('url'), 'some_url')
assert.equal(extension.get('path'), 'some/path')
assert.equal(extension.get('version'), '1.0')
assert.equal(extension.get('description'), 'epic game about an android dragon dinossaur')
assert(Immutable.is(extension.get('manifest'), Immutable.fromJS({manifest_value: 'dinossaur'})))
assert.equal(extension.get('enabled'), true)
})

commonTests()
})
})
})
316 changes: 316 additions & 0 deletions test/unit/app/renderer/extensionsTabTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,316 @@
/* 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 */

const mockery = require('mockery')
const {mount} = require('enzyme')
const assert = require('assert')
const Immutable = require('immutable')
const fakeElectron = require('../../lib/fakeElectron')
const {passwordManagers} = require('../../../../js/constants/passwordManagers')
const config = require('../../../../js/constants/config')
let ExtensionsTab
require('../../braveUnit')

describe('ExtensionsTab component', function () {
before(function () {
mockery.enable({
warnOnReplace: false,
warnOnUnregistered: false,
useCleanCache: true
})
mockery.registerMock('../../less/switchControls.less', {})
mockery.registerMock('../../less/about/preferences.less', {})
mockery.registerMock('../../less/forms.less', {})
mockery.registerMock('../../less/button.less', {})
mockery.registerMock('../../node_modules/font-awesome/css/font-awesome.css', {})

mockery.registerMock('../../../../extensions/brave/img/extensions/1password-128.png')
mockery.registerMock('../../../../extensions/brave/img/extensions/bitwarden-128.png')
mockery.registerMock('../../../../extensions/brave/img/extensions/dashlane-128.png')
mockery.registerMock('../../../../extensions/brave/img/extensions/lastpass-128.png')
mockery.registerMock('../../../../extensions/brave/img/extensions/pdfjs-128.png')
mockery.registerMock('../../../../extensions/brave/img/extensions/pocket-128.png')
mockery.registerMock('../../../../extensions/brave/img/sync-128.png')
mockery.registerMock('../../../../extensions/torrent/img/extensions/webtorrent-128.png')

mockery.registerMock('electron', fakeElectron)
window.chrome = fakeElectron
ExtensionsTab = require('../../../../app/renderer/components/preferences/extensionsTab')
})
after(function () {
mockery.disable()
})

describe('extensionsTab', function () {
const extensions = (extensionId, isEnabled, isExcluded) => Immutable.fromJS({
[extensionId]: {
'enabled': isEnabled,
'excluded': isExcluded,
'name': 'coffee extension',
'url': '',
'manifest': {},
base_path: '',
version: '123456',
id: extensionId,
description: 'gives you a free cup of coffee every time a test passes'
}
})

describe('password managers extensions', function () {
describe('onepassword', function () {
it('shows on UI by default', function () {
const wrapper = mount(
<ExtensionsTab
extensions={extensions(passwordManagers.ONE_PASSWORD, false, false)}
settings={Immutable.Map()}
onChangeSetting={null} />
)
assert.equal(wrapper.find(`[data-extension-id="${passwordManagers.ONE_PASSWORD}"]`).length, 1)
})
it('can be excluded', function () {
const wrapper = mount(
<ExtensionsTab
extensions={extensions(passwordManagers.ONE_PASSWORD, false, true)}
settings={Immutable.Map()}
onChangeSetting={null} />
)
assert.equal(wrapper.find(`[data-extension-id="${passwordManagers.ONE_PASSWORD}"]`).length, 0)
})
it('can be enabled', function () {
const wrapper = mount(
<ExtensionsTab
extensions={extensions(passwordManagers.ONE_PASSWORD, true, false)}
settings={Immutable.Map()}
onChangeSetting={null} />
)
assert.equal(wrapper.find('[data-extension-enabled=true]').length, 1)
})
it('can be disabled', function () {
const wrapper = mount(
<ExtensionsTab
extensions={extensions(passwordManagers.ONE_PASSWORD, false, false)}
settings={Immutable.Map()}
onChangeSetting={null} />
)
assert.equal(wrapper.find('[data-extension-enabled=false]').length, 1)
})
})
describe('lastpass', function () {
it('shows on UI by default', function () {
const wrapper = mount(
<ExtensionsTab
extensions={extensions(passwordManagers.LAST_PASS, false, false)}
settings={Immutable.Map()}
onChangeSetting={null} />
)
assert.equal(wrapper.find(`[data-extension-id="${passwordManagers.LAST_PASS}"]`).length, 1)
})
it('can be excluded', function () {
const wrapper = mount(
<ExtensionsTab
extensions={extensions(passwordManagers.LAST_PASS, false, true)}
settings={Immutable.Map()}
onChangeSetting={null} />
)
assert.equal(wrapper.find(`[data-extension-id="${passwordManagers.LAST_PASS}"]`).length, 0)
})
it('can be enabled', function () {
const wrapper = mount(
<ExtensionsTab
extensions={extensions(passwordManagers.LAST_PASS, true, false)}
settings={Immutable.Map()}
onChangeSetting={null} />
)
assert.equal(wrapper.find('[data-extension-enabled=true]').length, 1)
})
it('can be disabled', function () {
const wrapper = mount(
<ExtensionsTab
extensions={extensions(passwordManagers.LAST_PASS, false, false)}
settings={Immutable.Map()}
onChangeSetting={null} />
)
assert.equal(wrapper.find('[data-extension-enabled=false]').length, 1)
})
})
describe('dashlane', function () {
it('shows on UI by default', function () {
const wrapper = mount(
<ExtensionsTab
extensions={extensions(passwordManagers.DASHLANE, false, false)}
settings={Immutable.Map()}
onChangeSetting={null} />
)
assert.equal(wrapper.find(`[data-extension-id="${passwordManagers.DASHLANE}"]`).length, 1)
})
it('can be excluded', function () {
const wrapper = mount(
<ExtensionsTab
extensions={extensions(passwordManagers.DASHLANE, false, true)}
settings={Immutable.Map()}
onChangeSetting={null} />
)
assert.equal(wrapper.find(`[data-extension-id="${passwordManagers.DASHLANE}"]`).length, 0)
})
it('can be enabled', function () {
const wrapper = mount(
<ExtensionsTab
extensions={extensions(passwordManagers.DASHLANE, true, false)}
settings={Immutable.Map()}
onChangeSetting={null} />
)
assert.equal(wrapper.find('[data-extension-enabled=true]').length, 1)
})
it('can be disabled', function () {
const wrapper = mount(
<ExtensionsTab
extensions={extensions(passwordManagers.DASHLANE, false, false)}
settings={Immutable.Map()}
onChangeSetting={null} />
)
assert.equal(wrapper.find('[data-extension-enabled=false]').length, 1)
})
})
})
describe('common extensions', function () {
describe('brave', function () {
it('do not show Brave extension', function () {
const wrapper = mount(
<ExtensionsTab
extensions={extensions(config.braveExtensionId, false, false)}
settings={Immutable.Map()}
onChangeSetting={null} />
)
assert.equal(wrapper.find(`[data-extension-id="${config.braveExtensionId}"]`).length, 0)
})
})
describe('pdfjs', function () {
it('shows on UI by default', function () {
const wrapper = mount(
<ExtensionsTab
extensions={extensions(config.PDFJSExtensionId, false, false)}
settings={Immutable.Map()}
onChangeSetting={null} />
)
assert.equal(wrapper.find(`[data-extension-id="${config.PDFJSExtensionId}"]`).length, 1)
})
it('does not show if excluded', function () {
const wrapper = mount(
<ExtensionsTab
extensions={extensions(config.PDFJSExtensionId, false, true)}
settings={Immutable.Map()}
onChangeSetting={null} />
)
assert.equal(wrapper.find(`[data-extension-id="${config.PDFJSExtensionId}"]`).length, 0)
})
it('can be enabled', function () {
const wrapper = mount(
<ExtensionsTab
extensions={extensions(config.PDFJSExtensionId, true, false)}
settings={Immutable.Map()}
onChangeSetting={null} />
)
assert.equal(wrapper.find('[data-extension-enabled=true]').length, 1)
})
it('can be disabled', function () {
const wrapper = mount(
<ExtensionsTab
extensions={extensions(config.PDFJSExtensionId, false, false)}
settings={Immutable.Map()}
onChangeSetting={null} />
)
assert.equal(wrapper.find('[data-extension-enabled=false]').length, 1)
})
})
describe('pocket', function () {
it('shows on UI by default', function () {
const wrapper = mount(
<ExtensionsTab
extensions={extensions(config.PocketExtensionId, false, false)}
settings={Immutable.Map()}
onChangeSetting={null} />
)
assert.equal(wrapper.find(`[data-extension-id="${config.PocketExtensionId}"]`).length, 1)
})
it('does not show if excluded', function () {
const wrapper = mount(
<ExtensionsTab
extensions={extensions(config.PocketExtensionId, false, true)}
settings={Immutable.Map()}
onChangeSetting={null} />
)
assert.equal(wrapper.find(`[data-extension-id="${config.PocketExtensionId}"]`).length, 0)
})
it('can be enabled', function () {
const wrapper = mount(
<ExtensionsTab
extensions={extensions(config.PocketExtensionId, true, false)}
settings={Immutable.Map()}
onChangeSetting={null} />
)
assert.equal(wrapper.find('[data-extension-enabled=true]').length, 1)
})
it('can be disabled', function () {
const wrapper = mount(
<ExtensionsTab
extensions={extensions(config.PocketExtensionId, false, false)}
settings={Immutable.Map()}
onChangeSetting={null} />
)
assert.equal(wrapper.find('[data-extension-enabled=false]').length, 1)
})
})
describe('torrent', function () {
it('shows on UI by default', function () {
const wrapper = mount(
<ExtensionsTab
extensions={extensions(config.torrentExtensionId, false, false)}
settings={Immutable.Map()}
onChangeSetting={null} />
)
assert.equal(wrapper.find(`[data-extension-id="${config.torrentExtensionId}"]`).length, 1)
})
it('can not be excluded', function () {
const wrapper = mount(
<ExtensionsTab
extensions={extensions(config.torrentExtensionId, false, true)}
settings={Immutable.Map()}
onChangeSetting={null} />
)
assert.equal(wrapper.find(`[data-extension-id="${config.torrentExtensionId}"]`).length, 1)
})
it('can be enabled', function () {
const wrapper = mount(
<ExtensionsTab
extensions={extensions(config.torrentExtensionId, true, false)}
settings={Immutable.Map()}
onChangeSetting={null} />
)
assert.equal(wrapper.find('[data-extension-enabled=true]').length, 1)
})
it('can be disabled', function () {
const wrapper = mount(
<ExtensionsTab
extensions={extensions(config.torrentExtensionId, false, false)}
settings={Immutable.Map()}
onChangeSetting={null} />
)
assert.equal(wrapper.find('[data-extension-enabled=false]').length, 1)
})
})
describe('sync', function () {
it('do not show sync extension', function () {
const wrapper = mount(
<ExtensionsTab
extensions={extensions(config.syncExtensionId, false, false)}
settings={Immutable.Map()}
onChangeSetting={null} />
)
assert.equal(wrapper.find(`[data-extension-id="${config.syncExtensionId}"]`).length, 0)
})
})
})
})
})
Loading

0 comments on commit caa2c39

Please sign in to comment.