api-dialog-spec.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. const assert = require('assert')
  2. const {dialog} = require('electron').remote
  3. describe('dialog module', () => {
  4. describe('showOpenDialog', () => {
  5. it('throws errors when the options are invalid', () => {
  6. assert.throws(() => {
  7. dialog.showOpenDialog({properties: false})
  8. }, /Properties must be an array/)
  9. assert.throws(() => {
  10. dialog.showOpenDialog({title: 300})
  11. }, /Title must be a string/)
  12. assert.throws(() => {
  13. dialog.showOpenDialog({buttonLabel: []})
  14. }, /Button label must be a string/)
  15. assert.throws(() => {
  16. dialog.showOpenDialog({defaultPath: {}})
  17. }, /Default path must be a string/)
  18. })
  19. })
  20. describe('showSaveDialog', () => {
  21. it('throws errors when the options are invalid', () => {
  22. assert.throws(() => {
  23. dialog.showSaveDialog({title: 300})
  24. }, /Title must be a string/)
  25. assert.throws(() => {
  26. dialog.showSaveDialog({buttonLabel: []})
  27. }, /Button label must be a string/)
  28. assert.throws(() => {
  29. dialog.showSaveDialog({defaultPath: {}})
  30. }, /Default path must be a string/)
  31. })
  32. })
  33. describe('showMessageBox', () => {
  34. it('throws errors when the options are invalid', () => {
  35. assert.throws(() => {
  36. dialog.showMessageBox(undefined, {type: 'not-a-valid-type'})
  37. }, /Invalid message box type/)
  38. assert.throws(() => {
  39. dialog.showMessageBox(null, {buttons: false})
  40. }, /Buttons must be an array/)
  41. assert.throws(() => {
  42. dialog.showMessageBox({title: 300})
  43. }, /Title must be a string/)
  44. assert.throws(() => {
  45. dialog.showMessageBox({message: []})
  46. }, /Message must be a string/)
  47. assert.throws(() => {
  48. dialog.showMessageBox({detail: 3.14})
  49. }, /Detail must be a string/)
  50. })
  51. })
  52. describe('showErrorBox', () => {
  53. it('throws errors when the options are invalid', () => {
  54. assert.throws(() => {
  55. dialog.showErrorBox()
  56. }, /Insufficient number of arguments/)
  57. assert.throws(() => {
  58. dialog.showErrorBox(3, 'four')
  59. }, /Error processing argument at index 0/)
  60. assert.throws(() => {
  61. dialog.showErrorBox('three', 4)
  62. }, /Error processing argument at index 1/)
  63. })
  64. })
  65. })