electron/spec/api-dialog-spec.js

170 lines
4.7 KiB
JavaScript
Raw Normal View History

2018-09-13 16:10:51 +00:00
const { expect } = require('chai')
const { closeWindow } = require('./window-helpers')
const { remote } = require('electron')
const { BrowserWindow, dialog } = remote
const isCI = remote.getGlobal('isCi')
2016-12-01 22:15:05 +00:00
describe('dialog module', () => {
describe('showOpenDialog', () => {
it('should not throw for valid cases', () => {
// Blocks the main process and can't be run in CI
if (isCI) return
let w
expect(() => {
dialog.showOpenDialog({ title: 'i am title' })
}).to.not.throw()
expect(() => {
w = new BrowserWindow()
dialog.showOpenDialog(w, { title: 'i am title' })
}).to.not.throw()
closeWindow(w).then(() => { w = null })
})
2016-12-01 22:15:05 +00:00
it('throws errors when the options are invalid', () => {
expect(() => {
2018-09-13 16:10:51 +00:00
dialog.showOpenDialog({ properties: false })
}).to.throw(/Properties must be an array/)
2016-12-01 22:15:05 +00:00
expect(() => {
2018-09-13 16:10:51 +00:00
dialog.showOpenDialog({ title: 300 })
}).to.throw(/Title must be a string/)
2016-12-01 22:15:05 +00:00
expect(() => {
2018-09-13 16:10:51 +00:00
dialog.showOpenDialog({ buttonLabel: [] })
}).to.throw(/Button label must be a string/)
2016-12-01 22:15:05 +00:00
expect(() => {
2018-09-13 16:10:51 +00:00
dialog.showOpenDialog({ defaultPath: {} })
}).to.throw(/Default path must be a string/)
expect(() => {
2018-09-13 16:10:51 +00:00
dialog.showOpenDialog({ message: {} })
}).to.throw(/Message must be a string/)
2016-12-01 22:15:05 +00:00
})
})
describe('showSaveDialog', () => {
it('should not throw for valid cases', () => {
// Blocks the main process and can't be run in CI
if (isCI) return
let w
expect(() => {
dialog.showSaveDialog({ title: 'i am title' })
}).to.not.throw()
expect(() => {
w = new BrowserWindow()
dialog.showSaveDialog(w, { title: 'i am title' })
}).to.not.throw()
closeWindow(w).then(() => { w = null })
})
2016-12-01 22:15:05 +00:00
it('throws errors when the options are invalid', () => {
expect(() => {
2018-09-13 16:10:51 +00:00
dialog.showSaveDialog({ title: 300 })
}).to.throw(/Title must be a string/)
2016-12-01 22:15:05 +00:00
expect(() => {
2018-09-13 16:10:51 +00:00
dialog.showSaveDialog({ buttonLabel: [] })
}).to.throw(/Button label must be a string/)
2016-12-01 22:15:05 +00:00
expect(() => {
2018-09-13 16:10:51 +00:00
dialog.showSaveDialog({ defaultPath: {} })
}).to.throw(/Default path must be a string/)
expect(() => {
2018-09-13 16:10:51 +00:00
dialog.showSaveDialog({ message: {} })
}).to.throw(/Message must be a string/)
expect(() => {
2018-09-13 16:10:51 +00:00
dialog.showSaveDialog({ nameFieldLabel: {} })
}).to.throw(/Name field label must be a string/)
2016-12-01 22:15:05 +00:00
})
})
describe('showMessageBox', () => {
it('should not throw for valid cases', () => {
// Blocks the main process and can't be run in CI
if (isCI) return
let w
expect(() => {
dialog.showMessageBox({ title: 'i am title' })
}).to.not.throw()
expect(() => {
w = new BrowserWindow()
dialog.showMessageBox(w, { title: 'i am title' })
}).to.not.throw()
closeWindow(w).then(() => { w = null })
})
2016-12-01 22:15:05 +00:00
it('throws errors when the options are invalid', () => {
expect(() => {
2018-09-13 16:10:51 +00:00
dialog.showMessageBox(undefined, { type: 'not-a-valid-type' })
}).to.throw(/Invalid message box type/)
2016-12-01 22:15:05 +00:00
expect(() => {
2018-09-13 16:10:51 +00:00
dialog.showMessageBox(null, { buttons: false })
}).to.throw(/Buttons must be an array/)
2016-12-01 22:15:05 +00:00
expect(() => {
2018-09-13 16:10:51 +00:00
dialog.showMessageBox({ title: 300 })
}).to.throw(/Title must be a string/)
2016-12-01 22:15:05 +00:00
expect(() => {
2018-09-13 16:10:51 +00:00
dialog.showMessageBox({ message: [] })
}).to.throw(/Message must be a string/)
2016-12-01 22:15:05 +00:00
expect(() => {
2018-09-13 16:10:51 +00:00
dialog.showMessageBox({ detail: 3.14 })
}).to.throw(/Detail must be a string/)
expect(() => {
2018-09-13 16:10:51 +00:00
dialog.showMessageBox({ checkboxLabel: false })
}).to.throw(/checkboxLabel must be a string/)
2016-12-01 22:15:05 +00:00
})
})
describe('showErrorBox', () => {
it('throws errors when the options are invalid', () => {
expect(() => {
2016-12-01 22:15:05 +00:00
dialog.showErrorBox()
}).to.throw(/Insufficient number of arguments/)
2016-12-01 22:15:05 +00:00
expect(() => {
2016-12-01 22:15:05 +00:00
dialog.showErrorBox(3, 'four')
}).to.throw(/Error processing argument at index 0/)
2016-12-01 22:15:05 +00:00
expect(() => {
2016-12-01 22:15:05 +00:00
dialog.showErrorBox('three', 4)
}).to.throw(/Error processing argument at index 1/)
2016-12-01 22:15:05 +00:00
})
})
describe('showCertificateTrustDialog', () => {
it('throws errors when the options are invalid', () => {
expect(() => {
dialog.showCertificateTrustDialog()
}).to.throw(/options must be an object/)
expect(() => {
dialog.showCertificateTrustDialog({})
}).to.throw(/certificate must be an object/)
expect(() => {
2018-09-13 16:10:51 +00:00
dialog.showCertificateTrustDialog({ certificate: {}, message: false })
}).to.throw(/message must be a string/)
})
})
2016-12-01 22:15:05 +00:00
})