2018-09-13 16:10:51 +00:00
|
|
|
const { expect } = require('chai')
|
|
|
|
const { dialog } = require('electron').remote
|
2016-12-01 22:15:05 +00:00
|
|
|
|
|
|
|
describe('dialog module', () => {
|
|
|
|
describe('showOpenDialog', () => {
|
|
|
|
it('throws errors when the options are invalid', () => {
|
2018-06-18 14:56:03 +00:00
|
|
|
expect(() => {
|
2018-09-13 16:10:51 +00:00
|
|
|
dialog.showOpenDialog({ properties: false })
|
2018-06-18 14:56:03 +00:00
|
|
|
}).to.throw(/Properties must be an array/)
|
2016-12-01 22:15:05 +00:00
|
|
|
|
2018-06-18 14:56:03 +00:00
|
|
|
expect(() => {
|
2018-09-13 16:10:51 +00:00
|
|
|
dialog.showOpenDialog({ title: 300 })
|
2018-06-18 14:56:03 +00:00
|
|
|
}).to.throw(/Title must be a string/)
|
2016-12-01 22:15:05 +00:00
|
|
|
|
2018-06-18 14:56:03 +00:00
|
|
|
expect(() => {
|
2018-09-13 16:10:51 +00:00
|
|
|
dialog.showOpenDialog({ buttonLabel: [] })
|
2018-06-18 14:56:03 +00:00
|
|
|
}).to.throw(/Button label must be a string/)
|
2016-12-01 22:15:05 +00:00
|
|
|
|
2018-06-18 14:56:03 +00:00
|
|
|
expect(() => {
|
2018-09-13 16:10:51 +00:00
|
|
|
dialog.showOpenDialog({ defaultPath: {} })
|
2018-06-18 14:56:03 +00:00
|
|
|
}).to.throw(/Default path must be a string/)
|
2017-02-09 13:23:02 +00:00
|
|
|
|
2018-06-18 14:56:03 +00:00
|
|
|
expect(() => {
|
2018-09-13 16:10:51 +00:00
|
|
|
dialog.showOpenDialog({ message: {} })
|
2018-06-18 14:56:03 +00:00
|
|
|
}).to.throw(/Message must be a string/)
|
2016-12-01 22:15:05 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('showSaveDialog', () => {
|
|
|
|
it('throws errors when the options are invalid', () => {
|
2018-06-18 14:56:03 +00:00
|
|
|
expect(() => {
|
2018-09-13 16:10:51 +00:00
|
|
|
dialog.showSaveDialog({ title: 300 })
|
2018-06-18 14:56:03 +00:00
|
|
|
}).to.throw(/Title must be a string/)
|
2016-12-01 22:15:05 +00:00
|
|
|
|
2018-06-18 14:56:03 +00:00
|
|
|
expect(() => {
|
2018-09-13 16:10:51 +00:00
|
|
|
dialog.showSaveDialog({ buttonLabel: [] })
|
2018-06-18 14:56:03 +00:00
|
|
|
}).to.throw(/Button label must be a string/)
|
2016-12-01 22:15:05 +00:00
|
|
|
|
2018-06-18 14:56:03 +00:00
|
|
|
expect(() => {
|
2018-09-13 16:10:51 +00:00
|
|
|
dialog.showSaveDialog({ defaultPath: {} })
|
2018-06-18 14:56:03 +00:00
|
|
|
}).to.throw(/Default path must be a string/)
|
2017-02-09 13:23:02 +00:00
|
|
|
|
2018-06-18 14:56:03 +00:00
|
|
|
expect(() => {
|
2018-09-13 16:10:51 +00:00
|
|
|
dialog.showSaveDialog({ message: {} })
|
2018-06-18 14:56:03 +00:00
|
|
|
}).to.throw(/Message must be a string/)
|
2017-02-09 13:23:02 +00:00
|
|
|
|
2018-06-18 14:56:03 +00:00
|
|
|
expect(() => {
|
2018-09-13 16:10:51 +00:00
|
|
|
dialog.showSaveDialog({ nameFieldLabel: {} })
|
2018-06-18 14:56:03 +00:00
|
|
|
}).to.throw(/Name field label must be a string/)
|
2016-12-01 22:15:05 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('showMessageBox', () => {
|
|
|
|
it('throws errors when the options are invalid', () => {
|
2018-06-18 14:56:03 +00:00
|
|
|
expect(() => {
|
2018-09-13 16:10:51 +00:00
|
|
|
dialog.showMessageBox(undefined, { type: 'not-a-valid-type' })
|
2018-06-18 14:56:03 +00:00
|
|
|
}).to.throw(/Invalid message box type/)
|
2016-12-01 22:15:05 +00:00
|
|
|
|
2018-06-18 14:56:03 +00:00
|
|
|
expect(() => {
|
2018-09-13 16:10:51 +00:00
|
|
|
dialog.showMessageBox(null, { buttons: false })
|
2018-06-18 14:56:03 +00:00
|
|
|
}).to.throw(/Buttons must be an array/)
|
2016-12-01 22:15:05 +00:00
|
|
|
|
2018-06-18 14:56:03 +00:00
|
|
|
expect(() => {
|
2018-09-13 16:10:51 +00:00
|
|
|
dialog.showMessageBox({ title: 300 })
|
2018-06-18 14:56:03 +00:00
|
|
|
}).to.throw(/Title must be a string/)
|
2016-12-01 22:15:05 +00:00
|
|
|
|
2018-06-18 14:56:03 +00:00
|
|
|
expect(() => {
|
2018-09-13 16:10:51 +00:00
|
|
|
dialog.showMessageBox({ message: [] })
|
2018-06-18 14:56:03 +00:00
|
|
|
}).to.throw(/Message must be a string/)
|
2016-12-01 22:15:05 +00:00
|
|
|
|
2018-06-18 14:56:03 +00:00
|
|
|
expect(() => {
|
2018-09-13 16:10:51 +00:00
|
|
|
dialog.showMessageBox({ detail: 3.14 })
|
2018-06-18 14:56:03 +00:00
|
|
|
}).to.throw(/Detail must be a string/)
|
2017-02-06 15:35:36 +00:00
|
|
|
|
2018-06-18 14:56:03 +00:00
|
|
|
expect(() => {
|
2018-09-13 16:10:51 +00:00
|
|
|
dialog.showMessageBox({ checkboxLabel: false })
|
2018-06-18 14:56:03 +00:00
|
|
|
}).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', () => {
|
2018-06-18 14:56:03 +00:00
|
|
|
expect(() => {
|
2016-12-01 22:15:05 +00:00
|
|
|
dialog.showErrorBox()
|
2018-06-18 14:56:03 +00:00
|
|
|
}).to.throw(/Insufficient number of arguments/)
|
2016-12-01 22:15:05 +00:00
|
|
|
|
2018-06-18 14:56:03 +00:00
|
|
|
expect(() => {
|
2016-12-01 22:15:05 +00:00
|
|
|
dialog.showErrorBox(3, 'four')
|
2018-06-18 14:56:03 +00:00
|
|
|
}).to.throw(/Error processing argument at index 0/)
|
2016-12-01 22:15:05 +00:00
|
|
|
|
2018-06-18 14:56:03 +00:00
|
|
|
expect(() => {
|
2016-12-01 22:15:05 +00:00
|
|
|
dialog.showErrorBox('three', 4)
|
2018-06-18 14:56:03 +00:00
|
|
|
}).to.throw(/Error processing argument at index 1/)
|
2016-12-01 22:15:05 +00:00
|
|
|
})
|
|
|
|
})
|
2017-04-04 17:49:21 +00:00
|
|
|
|
|
|
|
describe('showCertificateTrustDialog', () => {
|
|
|
|
it('throws errors when the options are invalid', () => {
|
2018-06-18 14:56:03 +00:00
|
|
|
expect(() => {
|
2017-04-04 17:49:21 +00:00
|
|
|
dialog.showCertificateTrustDialog()
|
2018-06-18 14:56:03 +00:00
|
|
|
}).to.throw(/options must be an object/)
|
2017-04-04 17:49:21 +00:00
|
|
|
|
2018-06-18 14:56:03 +00:00
|
|
|
expect(() => {
|
2017-04-04 17:49:21 +00:00
|
|
|
dialog.showCertificateTrustDialog({})
|
2018-06-18 14:56:03 +00:00
|
|
|
}).to.throw(/certificate must be an object/)
|
2017-04-04 17:49:21 +00:00
|
|
|
|
2018-06-18 14:56:03 +00:00
|
|
|
expect(() => {
|
2018-09-13 16:10:51 +00:00
|
|
|
dialog.showCertificateTrustDialog({ certificate: {}, message: false })
|
2018-06-18 14:56:03 +00:00
|
|
|
}).to.throw(/message must be a string/)
|
2017-04-04 17:49:21 +00:00
|
|
|
})
|
|
|
|
})
|
2016-12-01 22:15:05 +00:00
|
|
|
})
|