2019-06-28 14:43:05 +00:00
|
|
|
import { expect } from 'chai'
|
|
|
|
import { Menu, Tray, nativeImage } from 'electron'
|
2018-08-27 16:58:47 +00:00
|
|
|
|
|
|
|
describe('tray module', () => {
|
2019-06-28 14:43:05 +00:00
|
|
|
let tray: Tray;
|
2018-08-27 16:58:47 +00:00
|
|
|
|
2018-08-30 09:16:56 +00:00
|
|
|
beforeEach(() => {
|
|
|
|
tray = new Tray(nativeImage.createEmpty())
|
|
|
|
})
|
2018-08-27 16:58:47 +00:00
|
|
|
|
2019-06-28 14:43:05 +00:00
|
|
|
afterEach(() => {
|
|
|
|
tray = null as any
|
|
|
|
})
|
|
|
|
|
2018-08-30 09:16:56 +00:00
|
|
|
describe('tray.setContextMenu', () => {
|
2019-05-08 22:40:30 +00:00
|
|
|
afterEach(() => {
|
|
|
|
tray.destroy()
|
|
|
|
})
|
|
|
|
|
2018-08-27 16:58:47 +00:00
|
|
|
it('accepts menu instance', () => {
|
|
|
|
tray.setContextMenu(new Menu())
|
|
|
|
})
|
|
|
|
|
|
|
|
it('accepts null', () => {
|
|
|
|
tray.setContextMenu(null)
|
|
|
|
})
|
|
|
|
})
|
2018-08-30 09:16:56 +00:00
|
|
|
|
2019-05-08 22:40:30 +00:00
|
|
|
describe('tray.destroy()', () => {
|
|
|
|
it('destroys a tray', () => {
|
2019-06-28 14:43:05 +00:00
|
|
|
expect(tray.isDestroyed()).to.be.false('tray should not be destroyed')
|
2019-05-08 22:40:30 +00:00
|
|
|
tray.destroy()
|
|
|
|
|
2019-06-28 14:43:05 +00:00
|
|
|
expect(tray.isDestroyed()).to.be.true('tray should be destroyed')
|
2019-05-08 22:40:30 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-03-22 04:56:22 +00:00
|
|
|
describe('tray.popUpContextMenu', () => {
|
2019-05-08 22:40:30 +00:00
|
|
|
afterEach(() => {
|
|
|
|
tray.destroy()
|
|
|
|
})
|
|
|
|
|
2019-03-22 04:56:22 +00:00
|
|
|
before(function () {
|
2019-05-08 22:40:30 +00:00
|
|
|
if (process.platform !== 'win32') this.skip()
|
2019-03-22 04:56:22 +00: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 09:16:56 +00:00
|
|
|
describe('tray.setImage', () => {
|
|
|
|
it('accepts empty image', () => {
|
|
|
|
tray.setImage(nativeImage.createEmpty())
|
2019-05-08 22:40:30 +00:00
|
|
|
|
|
|
|
tray.destroy()
|
2018-08-30 09:16:56 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('tray.setPressedImage', () => {
|
|
|
|
it('accepts empty image', () => {
|
|
|
|
tray.setPressedImage(nativeImage.createEmpty())
|
2019-05-08 22:40:30 +00:00
|
|
|
|
|
|
|
tray.destroy()
|
2018-08-30 09:16:56 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-03-18 19:40:34 +00:00
|
|
|
describe('tray title get/set', () => {
|
|
|
|
before(function () {
|
2019-05-08 22:40:30 +00:00
|
|
|
if (process.platform !== 'darwin') this.skip()
|
|
|
|
})
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
tray.destroy()
|
2018-08-30 09:16:56 +00:00
|
|
|
})
|
|
|
|
|
2019-03-18 19:40:34 +00: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 09:16:56 +00:00
|
|
|
})
|
|
|
|
})
|
2018-08-27 16:58:47 +00:00
|
|
|
})
|