2018-09-14 02:10:51 +10:00
|
|
|
const { remote } = require('electron')
|
2019-03-18 12:40:34 -07:00
|
|
|
const { expect } = require('chai')
|
2018-09-14 02:10:51 +10:00
|
|
|
const { Menu, Tray, nativeImage } = remote
|
2018-08-27 18:58:47 +02:00
|
|
|
|
|
|
|
describe('tray module', () => {
|
2018-08-30 11:16:56 +02:00
|
|
|
let tray
|
2018-08-27 18:58:47 +02:00
|
|
|
|
2018-08-30 11:16:56 +02:00
|
|
|
beforeEach(() => {
|
|
|
|
tray = new Tray(nativeImage.createEmpty())
|
|
|
|
})
|
2018-08-27 18:58:47 +02:00
|
|
|
|
2018-08-30 11:16:56 +02:00
|
|
|
describe('tray.setContextMenu', () => {
|
2019-05-08 15:40:30 -07:00
|
|
|
afterEach(() => {
|
|
|
|
tray.destroy()
|
|
|
|
tray = null
|
|
|
|
})
|
|
|
|
|
2018-08-27 18:58:47 +02:00
|
|
|
it('accepts menu instance', () => {
|
|
|
|
tray.setContextMenu(new Menu())
|
|
|
|
})
|
|
|
|
|
|
|
|
it('accepts null', () => {
|
|
|
|
tray.setContextMenu(null)
|
|
|
|
})
|
|
|
|
})
|
2018-08-30 11:16:56 +02:00
|
|
|
|
2019-05-08 15:40:30 -07:00
|
|
|
describe('tray.destroy()', () => {
|
|
|
|
it('destroys a tray', () => {
|
|
|
|
expect(tray.isDestroyed()).to.be.false()
|
|
|
|
tray.destroy()
|
|
|
|
|
|
|
|
expect(tray.isDestroyed()).to.be.true()
|
|
|
|
tray = null
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-03-22 13:56:22 +09:00
|
|
|
describe('tray.popUpContextMenu', () => {
|
2019-05-08 15:40:30 -07:00
|
|
|
afterEach(() => {
|
|
|
|
tray.destroy()
|
|
|
|
tray = null
|
|
|
|
})
|
|
|
|
|
2019-03-22 13:56:22 +09:00
|
|
|
before(function () {
|
2019-05-08 15:40:30 -07:00
|
|
|
if (process.platform !== 'win32') this.skip()
|
2019-03-22 13:56:22 +09:00
|
|
|
})
|
|
|
|
|
|
|
|
it('can be called when menu is showing', (done) => {
|
|
|
|
tray.setContextMenu(Menu.buildFromTemplate([{ label: 'Test' }]))
|
|
|
|
setTimeout(() => {
|
|
|
|
tray.popUpContextMenu()
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
tray.popUpContextMenu()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2018-08-30 11:16:56 +02:00
|
|
|
describe('tray.setImage', () => {
|
|
|
|
it('accepts empty image', () => {
|
|
|
|
tray.setImage(nativeImage.createEmpty())
|
2019-05-08 15:40:30 -07:00
|
|
|
|
|
|
|
tray.destroy()
|
|
|
|
tray = null
|
2018-08-30 11:16:56 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('tray.setPressedImage', () => {
|
|
|
|
it('accepts empty image', () => {
|
|
|
|
tray.setPressedImage(nativeImage.createEmpty())
|
2019-05-08 15:40:30 -07:00
|
|
|
|
|
|
|
tray.destroy()
|
|
|
|
tray = null
|
2018-08-30 11:16:56 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-03-18 12:40:34 -07:00
|
|
|
describe('tray title get/set', () => {
|
|
|
|
before(function () {
|
2019-05-08 15:40:30 -07:00
|
|
|
if (process.platform !== 'darwin') this.skip()
|
|
|
|
})
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
tray.destroy()
|
|
|
|
tray = null
|
2018-08-30 11:16:56 +02:00
|
|
|
})
|
|
|
|
|
2019-03-18 12:40:34 -07:00
|
|
|
it('sets/gets non-empty title', () => {
|
|
|
|
const title = 'Hello World!'
|
|
|
|
tray.setTitle(title)
|
|
|
|
const newTitle = tray.getTitle()
|
|
|
|
|
|
|
|
expect(newTitle).to.equal(title)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('sets/gets empty title', () => {
|
|
|
|
const title = ''
|
|
|
|
tray.setTitle(title)
|
|
|
|
const newTitle = tray.getTitle()
|
|
|
|
|
|
|
|
expect(newTitle).to.equal(title)
|
2018-08-30 11:16:56 +02:00
|
|
|
})
|
|
|
|
})
|
2018-08-27 18:58:47 +02:00
|
|
|
})
|