Merge pull request #8121 from electron/add-basic-dialog-specs

Add basic dialog specs
This commit is contained in:
Kevin Sawicki 2016-12-01 14:55:49 -08:00 committed by GitHub
commit f72942bff1
2 changed files with 82 additions and 2 deletions

View file

@ -78,7 +78,7 @@ module.exports = {
if (options.buttonLabel == null) { if (options.buttonLabel == null) {
options.buttonLabel = '' options.buttonLabel = ''
} else if (typeof options.buttonLabel !== 'string') { } else if (typeof options.buttonLabel !== 'string') {
throw new TypeError('buttonLabel must be a string') throw new TypeError('Button label must be a string')
} }
if (options.defaultPath == null) { if (options.defaultPath == null) {
options.defaultPath = '' options.defaultPath = ''
@ -111,7 +111,7 @@ module.exports = {
if (options.buttonLabel == null) { if (options.buttonLabel == null) {
options.buttonLabel = '' options.buttonLabel = ''
} else if (typeof options.buttonLabel !== 'string') { } else if (typeof options.buttonLabel !== 'string') {
throw new TypeError('buttonLabel must be a string') throw new TypeError('Button label must be a string')
} }
if (options.defaultPath == null) { if (options.defaultPath == null) {
options.defaultPath = '' options.defaultPath = ''

80
spec/api-dialog-spec.js Normal file
View file

@ -0,0 +1,80 @@
const assert = require('assert')
const {dialog} = require('electron').remote
describe('dialog module', () => {
describe('showOpenDialog', () => {
it('throws errors when the options are invalid', () => {
assert.throws(() => {
dialog.showOpenDialog({properties: false})
}, /Properties must be an array/)
assert.throws(() => {
dialog.showOpenDialog({title: 300})
}, /Title must be a string/)
assert.throws(() => {
dialog.showOpenDialog({buttonLabel: []})
}, /Button label must be a string/)
assert.throws(() => {
dialog.showOpenDialog({defaultPath: {}})
}, /Default path must be a string/)
})
})
describe('showSaveDialog', () => {
it('throws errors when the options are invalid', () => {
assert.throws(() => {
dialog.showSaveDialog({title: 300})
}, /Title must be a string/)
assert.throws(() => {
dialog.showSaveDialog({buttonLabel: []})
}, /Button label must be a string/)
assert.throws(() => {
dialog.showSaveDialog({defaultPath: {}})
}, /Default path must be a string/)
})
})
describe('showMessageBox', () => {
it('throws errors when the options are invalid', () => {
assert.throws(() => {
dialog.showMessageBox({type: 'not-a-valid-type'})
}, /Invalid message box type/)
assert.throws(() => {
dialog.showMessageBox({buttons: false})
}, /Buttons must be an array/)
assert.throws(() => {
dialog.showMessageBox({title: 300, buttons: ['OK']})
}, /Title must be a string/)
assert.throws(() => {
dialog.showMessageBox({message: [], buttons: ['OK']})
}, /Message must be a string/)
assert.throws(() => {
dialog.showMessageBox({detail: 3.14, buttons: ['OK']})
}, /Detail must be a string/)
})
})
describe('showErrorBox', () => {
it('throws errors when the options are invalid', () => {
assert.throws(() => {
dialog.showErrorBox()
}, /Insufficient number of arguments/)
assert.throws(() => {
dialog.showErrorBox(3, 'four')
}, /Error processing argument at index 0/)
assert.throws(() => {
dialog.showErrorBox('three', 4)
}, /Error processing argument at index 1/)
})
})
})