From 750bd9a88b79205e722ad6226a8435694ce87fa5 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 1 Dec 2016 14:15:05 -0800 Subject: [PATCH 1/2] Add initial dialog specs --- spec/api-dialog-spec.js | 80 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 spec/api-dialog-spec.js diff --git a/spec/api-dialog-spec.js b/spec/api-dialog-spec.js new file mode 100644 index 00000000000..3f8f5704ca4 --- /dev/null +++ b/spec/api-dialog-spec.js @@ -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: []}) + }, /buttonLabel 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: []}) + }, /buttonLabel 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/) + }) + }) +}) From 36371357cd834dde0cd5398715e61a9f04a8cfb1 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 1 Dec 2016 14:16:33 -0800 Subject: [PATCH 2/2] buttonLabel -> Button label for consistency --- lib/browser/api/dialog.js | 4 ++-- spec/api-dialog-spec.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/browser/api/dialog.js b/lib/browser/api/dialog.js index d24a1f98a7d..766d89cf8b0 100644 --- a/lib/browser/api/dialog.js +++ b/lib/browser/api/dialog.js @@ -78,7 +78,7 @@ module.exports = { if (options.buttonLabel == null) { options.buttonLabel = '' } 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) { options.defaultPath = '' @@ -111,7 +111,7 @@ module.exports = { if (options.buttonLabel == null) { options.buttonLabel = '' } 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) { options.defaultPath = '' diff --git a/spec/api-dialog-spec.js b/spec/api-dialog-spec.js index 3f8f5704ca4..6391edcd757 100644 --- a/spec/api-dialog-spec.js +++ b/spec/api-dialog-spec.js @@ -14,7 +14,7 @@ describe('dialog module', () => { assert.throws(() => { dialog.showOpenDialog({buttonLabel: []}) - }, /buttonLabel must be a string/) + }, /Button label must be a string/) assert.throws(() => { dialog.showOpenDialog({defaultPath: {}}) @@ -30,7 +30,7 @@ describe('dialog module', () => { assert.throws(() => { dialog.showSaveDialog({buttonLabel: []}) - }, /buttonLabel must be a string/) + }, /Button label must be a string/) assert.throws(() => { dialog.showSaveDialog({defaultPath: {}})