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

Commit

Permalink
Added unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NejcZdovc committed Mar 3, 2017
1 parent 14f8d7d commit 04878a9
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/renderer/components/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,15 @@ class SettingItemIcon extends ImmutableComponent {
<div>
{
this.props.position === 'left'
? <span className={css(bg.Icon, styles.icon, styles.iconLeft)} onClick={this.props.clickAction} />
? <span className={css(bg.Icon, styles.icon, styles.iconLeft)} data-icon-position='left' onClick={this.props.clickAction} />
: null
}
<div className={css(styles.child)}>
{this.props.children}
</div>
{
this.props.position === 'right'
? <span className={css(bg.Icon, styles.icon, styles.iconRight)} onClick={this.props.clickAction} />
? <span className={css(bg.Icon, styles.icon, styles.iconRight)} data-icon-position='right' onClick={this.props.clickAction} />
: null
}
</div>
Expand Down
21 changes: 20 additions & 1 deletion test/unit/about/preferencesTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const {mount} = require('enzyme')
const sinon = require('sinon')
const assert = require('assert')
const fakeElectron = require('../lib/fakeElectron')
let Preferences
let Preferences, aboutActions, SettingItemIcon
require('../braveUnit')

describe('Preferences component', function () {
Expand Down Expand Up @@ -38,6 +38,8 @@ describe('Preferences component', function () {
window.CustomEvent = {}

Preferences = require('../../../js/about/preferences').AboutPreferences
SettingItemIcon = require('../../../app/renderer/components/settings').SettingItemIcon
aboutActions = require('../../../js/about/aboutActions')
})
after(function () {
mockery.disable()
Expand Down Expand Up @@ -77,4 +79,21 @@ describe('Preferences component', function () {
assert.equal(this.result.find('[data-l10n-id="searchSettings"]').length, 1)
})
})

describe('General', function () {
describe('Default path', function () {
it('call aboutActions.defaultDownloadPath when pencil is clicked', function () {
const spy = sinon.spy(aboutActions, 'defaultDownloadPath')
const wrapper = mount(
<SettingItemIcon
clickAction={aboutActions.defaultDownloadPath()}
position='right'
/>
)
wrapper.find('span[data-icon-position="right"]').simulate('click')
assert.equal(spy.calledOnce, true)
aboutActions.defaultDownloadPath.restore()
})
})
})
})
25 changes: 25 additions & 0 deletions test/unit/app/browser/reducers/downloadsReducerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,29 @@ describe('downloadsReducer', function () {
})
})
})

describe('APP_DOWNLOAD_DEFAULT_PATH', function () {
let stub

after(function () {
stub.restore()
})

it('Opens a folder selection dialog', function () {
stub = sinon.stub(fakeElectron.dialog, 'showOpenDialog')
downloadsReducer({}, {actionType: appConstants.APP_DOWNLOAD_DEFAULT_PATH})
assert(stub.calledOnce)
stub.restore()
})

it('Opens a folder selection with correct params', function (cb) {
stub = sinon.stub(fakeElectron.dialog, 'showOpenDialog', function (window, options) {
assert.equal(options.defaultPath, `${process.cwd()}/downloads`)
assert.deepEqual(options.properties, ['openDirectory'])
cb()
})

downloadsReducer({}, {actionType: appConstants.APP_DOWNLOAD_DEFAULT_PATH})
})
})
})
6 changes: 5 additions & 1 deletion test/unit/lib/fakeElectron.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,16 @@ const fakeElectron = {
},
app: {
on: function () {
}
},
getPath: (param) => `${process.cwd()}/${param}`
},
clipboard: {
writeText: function () {
}
},
dialog: {
showOpenDialog: function () { }
},
shell: {
showItemInFolder: function () {
},
Expand Down

0 comments on commit 04878a9

Please sign in to comment.