2019-06-28 17:43:05 +03:00
|
|
|
import { expect } from 'chai'
|
|
|
|
import { Menu, Tray, nativeImage } from 'electron'
|
2019-07-25 07:22:08 +03:00
|
|
|
import { ifdescribe, ifit } from './spec-helpers'
|
2019-11-23 06:16:43 +03:00
|
|
|
import * as path from 'path'
|
2018-08-27 19:58:47 +03:00
|
|
|
|
|
|
|
describe('tray module', () => {
|
2019-11-01 23:37:02 +03:00
|
|
|
let tray: Tray
|
2018-08-27 19:58:47 +03:00
|
|
|
|
2019-07-25 07:22:08 +03:00
|
|
|
beforeEach(() => { tray = new Tray(nativeImage.createEmpty()) })
|
2018-08-27 19:58:47 +03:00
|
|
|
|
2019-06-28 17:43:05 +03:00
|
|
|
afterEach(() => {
|
2019-07-25 07:22:08 +03:00
|
|
|
tray.destroy()
|
2019-06-28 17:43:05 +03:00
|
|
|
tray = null as any
|
|
|
|
})
|
|
|
|
|
2019-11-23 06:16:43 +03:00
|
|
|
describe('new Tray', () => {
|
|
|
|
it('throws a descriptive error for a missing file', () => {
|
|
|
|
const badPath = path.resolve('I', 'Do', 'Not', 'Exist')
|
|
|
|
expect(() => {
|
|
|
|
tray = new Tray(badPath)
|
|
|
|
}).to.throw(/Image could not be created from .*/)
|
|
|
|
})
|
2020-01-31 08:37:03 +03:00
|
|
|
|
|
|
|
ifit(process.platform === 'win32')('throws a descriptive error if an invlaid guid is given', () => {
|
|
|
|
expect(() => {
|
|
|
|
tray = new Tray(nativeImage.createEmpty(), 'I am not a guid')
|
|
|
|
}).to.throw('Invalid GUID format')
|
|
|
|
})
|
|
|
|
|
|
|
|
ifit(process.platform === 'win32')('accepts a valid guid', () => {
|
|
|
|
expect(() => {
|
|
|
|
tray = new Tray(nativeImage.createEmpty(), '0019A433-3526-48BA-A66C-676742C0FEFB')
|
|
|
|
}).to.not.throw()
|
|
|
|
})
|
2019-11-23 06:16:43 +03:00
|
|
|
})
|
|
|
|
|
2019-07-25 07:22:08 +03:00
|
|
|
ifdescribe(process.platform === 'darwin')('tray get/set ignoreDoubleClickEvents', () => {
|
|
|
|
it('returns false by default', () => {
|
|
|
|
const ignored = tray.getIgnoreDoubleClickEvents()
|
|
|
|
expect(ignored).to.be.false('ignored')
|
2019-05-09 01:40:30 +03:00
|
|
|
})
|
|
|
|
|
2019-07-25 07:22:08 +03:00
|
|
|
it('can be set to true', () => {
|
|
|
|
tray.setIgnoreDoubleClickEvents(true)
|
|
|
|
|
|
|
|
const ignored = tray.getIgnoreDoubleClickEvents()
|
|
|
|
expect(ignored).to.be.true('not ignored')
|
2018-08-27 19:58:47 +03:00
|
|
|
})
|
2019-07-25 07:22:08 +03:00
|
|
|
})
|
2018-08-27 19:58:47 +03:00
|
|
|
|
2019-07-25 07:22:08 +03:00
|
|
|
describe('tray.setContextMenu(menu)', () => {
|
|
|
|
it('accepts both null and Menu as parameters', () => {
|
|
|
|
expect(() => { tray.setContextMenu(new Menu()) }).to.not.throw()
|
|
|
|
expect(() => { tray.setContextMenu(null) }).to.not.throw()
|
2018-08-27 19:58:47 +03:00
|
|
|
})
|
|
|
|
})
|
2018-08-30 12:16:56 +03:00
|
|
|
|
2019-05-09 01:40:30 +03:00
|
|
|
describe('tray.destroy()', () => {
|
|
|
|
it('destroys a tray', () => {
|
2019-06-28 17:43:05 +03:00
|
|
|
expect(tray.isDestroyed()).to.be.false('tray should not be destroyed')
|
2019-05-09 01:40:30 +03:00
|
|
|
tray.destroy()
|
|
|
|
|
2019-06-28 17:43:05 +03:00
|
|
|
expect(tray.isDestroyed()).to.be.true('tray should be destroyed')
|
2019-05-09 01:40:30 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-07-25 07:22:08 +03:00
|
|
|
describe('tray.popUpContextMenu()', () => {
|
|
|
|
ifit(process.platform === 'win32')('can be called when menu is showing', function (done) {
|
2019-03-22 07:56:22 +03:00
|
|
|
tray.setContextMenu(Menu.buildFromTemplate([{ label: 'Test' }]))
|
|
|
|
setTimeout(() => {
|
|
|
|
tray.popUpContextMenu()
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
tray.popUpContextMenu()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-01-23 02:25:17 +03:00
|
|
|
describe('tray.closeContextMenu()', () => {
|
|
|
|
ifit(process.platform === 'win32')('does not crash when called more than once', function (done) {
|
|
|
|
tray.setContextMenu(Menu.buildFromTemplate([{ label: 'Test' }]))
|
|
|
|
setTimeout(() => {
|
|
|
|
tray.closeContextMenu()
|
|
|
|
tray.closeContextMenu()
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
tray.popUpContextMenu()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-07-25 07:22:08 +03:00
|
|
|
describe('tray.getBounds()', () => {
|
|
|
|
afterEach(() => { tray.destroy() })
|
2019-05-09 01:40:30 +03:00
|
|
|
|
2019-11-01 23:37:02 +03:00
|
|
|
ifit(process.platform !== 'linux')('returns a bounds object', function () {
|
2019-07-25 07:22:08 +03:00
|
|
|
const bounds = tray.getBounds()
|
2019-11-01 23:37:02 +03:00
|
|
|
expect(bounds).to.be.an('object').and.to.have.all.keys('x', 'y', 'width', 'height')
|
2018-08-30 12:16:56 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-07-25 07:22:08 +03:00
|
|
|
describe('tray.setImage(image)', () => {
|
2018-08-30 12:16:56 +03:00
|
|
|
it('accepts empty image', () => {
|
2019-07-25 07:22:08 +03:00
|
|
|
tray.setImage(nativeImage.createEmpty())
|
2018-08-30 12:16:56 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-07-25 07:22:08 +03:00
|
|
|
describe('tray.setPressedImage(image)', () => {
|
|
|
|
it('accepts empty image', () => {
|
|
|
|
tray.setPressedImage(nativeImage.createEmpty())
|
2018-08-30 12:16:56 +03:00
|
|
|
})
|
2019-07-25 07:22:08 +03:00
|
|
|
})
|
2018-08-30 12:16:56 +03:00
|
|
|
|
2019-07-25 07:22:08 +03:00
|
|
|
ifdescribe(process.platform === 'darwin')('tray get/set title', () => {
|
2019-03-18 22:40:34 +03: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 12:16:56 +03:00
|
|
|
})
|
|
|
|
})
|
2018-08-27 19:58:47 +03:00
|
|
|
})
|