api-tray-spec.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. const { remote } = require('electron')
  2. const { expect } = require('chai')
  3. const { Menu, Tray, nativeImage } = remote
  4. describe('tray module', () => {
  5. let tray
  6. beforeEach(() => {
  7. tray = new Tray(nativeImage.createEmpty())
  8. })
  9. describe('tray.setContextMenu', () => {
  10. afterEach(() => {
  11. tray.destroy()
  12. tray = null
  13. })
  14. it('accepts menu instance', () => {
  15. tray.setContextMenu(new Menu())
  16. })
  17. it('accepts null', () => {
  18. tray.setContextMenu(null)
  19. })
  20. })
  21. describe('tray.destroy()', () => {
  22. it('destroys a tray', () => {
  23. expect(tray.isDestroyed()).to.be.false()
  24. tray.destroy()
  25. expect(tray.isDestroyed()).to.be.true()
  26. tray = null
  27. })
  28. })
  29. describe('tray.popUpContextMenu', () => {
  30. afterEach(() => {
  31. tray.destroy()
  32. tray = null
  33. })
  34. before(function () {
  35. if (process.platform !== 'win32') this.skip()
  36. })
  37. it('can be called when menu is showing', (done) => {
  38. tray.setContextMenu(Menu.buildFromTemplate([{ label: 'Test' }]))
  39. setTimeout(() => {
  40. tray.popUpContextMenu()
  41. done()
  42. })
  43. tray.popUpContextMenu()
  44. })
  45. })
  46. describe('tray.setImage', () => {
  47. it('accepts empty image', () => {
  48. tray.setImage(nativeImage.createEmpty())
  49. tray.destroy()
  50. tray = null
  51. })
  52. })
  53. describe('tray.setPressedImage', () => {
  54. it('accepts empty image', () => {
  55. tray.setPressedImage(nativeImage.createEmpty())
  56. tray.destroy()
  57. tray = null
  58. })
  59. })
  60. describe('tray title get/set', () => {
  61. before(function () {
  62. if (process.platform !== 'darwin') this.skip()
  63. })
  64. afterEach(() => {
  65. tray.destroy()
  66. tray = null
  67. })
  68. it('sets/gets non-empty title', () => {
  69. const title = 'Hello World!'
  70. tray.setTitle(title)
  71. const newTitle = tray.getTitle()
  72. expect(newTitle).to.equal(title)
  73. })
  74. it('sets/gets empty title', () => {
  75. const title = ''
  76. tray.setTitle(title)
  77. const newTitle = tray.getTitle()
  78. expect(newTitle).to.equal(title)
  79. })
  80. })
  81. })