api-dialog-spec.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. assert.throws(() => {
  19. dialog.showOpenDialog({message: {}})
  20. }, /Message must be a string/)
  21. })
  22. })
  23. describe('showSaveDialog', () => {
  24. it('throws errors when the options are invalid', () => {
  25. assert.throws(() => {
  26. dialog.showSaveDialog({title: 300})
  27. }, /Title must be a string/)
  28. assert.throws(() => {
  29. dialog.showSaveDialog({buttonLabel: []})
  30. }, /Button label must be a string/)
  31. assert.throws(() => {
  32. dialog.showSaveDialog({defaultPath: {}})
  33. }, /Default path must be a string/)
  34. assert.throws(() => {
  35. dialog.showSaveDialog({message: {}})
  36. }, /Message must be a string/)
  37. assert.throws(() => {
  38. dialog.showSaveDialog({nameFieldLabel: {}})
  39. }, /Name field label must be a string/)
  40. })
  41. })
  42. describe('showMessageBox', () => {
  43. it('throws errors when the options are invalid', () => {
  44. assert.throws(() => {
  45. dialog.showMessageBox(undefined, {type: 'not-a-valid-type'})
  46. }, /Invalid message box type/)
  47. assert.throws(() => {
  48. dialog.showMessageBox(null, {buttons: false})
  49. }, /Buttons must be an array/)
  50. assert.throws(() => {
  51. dialog.showMessageBox({title: 300})
  52. }, /Title must be a string/)
  53. assert.throws(() => {
  54. dialog.showMessageBox({message: []})
  55. }, /Message must be a string/)
  56. assert.throws(() => {
  57. dialog.showMessageBox({detail: 3.14})
  58. }, /Detail must be a string/)
  59. assert.throws(() => {
  60. dialog.showMessageBox({checkboxLabel: false})
  61. }, /checkboxLabel must be a string/)
  62. })
  63. })
  64. describe('showErrorBox', () => {
  65. it('throws errors when the options are invalid', () => {
  66. assert.throws(() => {
  67. dialog.showErrorBox()
  68. }, /Insufficient number of arguments/)
  69. assert.throws(() => {
  70. dialog.showErrorBox(3, 'four')
  71. }, /Error processing argument at index 0/)
  72. assert.throws(() => {
  73. dialog.showErrorBox('three', 4)
  74. }, /Error processing argument at index 1/)
  75. })
  76. })
  77. describe('showCertificateTrustDialog', () => {
  78. it('throws errors when the options are invalid', () => {
  79. assert.throws(() => {
  80. dialog.showCertificateTrustDialog()
  81. }, /options must be an object/)
  82. assert.throws(() => {
  83. dialog.showCertificateTrustDialog({})
  84. }, /certificate must be an object/)
  85. assert.throws(() => {
  86. dialog.showCertificateTrustDialog({certificate: {}, message: false})
  87. }, /message must be a string/)
  88. })
  89. })
  90. })