api-dialog-spec.js 3.2 KB

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