/
api-tray-spec.ts
101 lines (82 loc) · 2.79 KB
/
api-tray-spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import { expect } from 'chai'
import { Menu, Tray, nativeImage } from 'electron'
import { ifdescribe, ifit } from './spec-helpers'
describe('tray module', () => {
let tray: Tray;
beforeEach(() => { tray = new Tray(nativeImage.createEmpty()) })
afterEach(() => {
tray.destroy()
tray = null as any
})
ifdescribe(process.platform === 'darwin')('tray get/set ignoreDoubleClickEvents', () => {
it('returns false by default', () => {
const ignored = tray.getIgnoreDoubleClickEvents()
expect(ignored).to.be.false('ignored')
})
it('can be set to true', () => {
tray.setIgnoreDoubleClickEvents(true)
const ignored = tray.getIgnoreDoubleClickEvents()
expect(ignored).to.be.true('not ignored')
})
})
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()
})
})
describe('tray.destroy()', () => {
it('destroys a tray', () => {
expect(tray.isDestroyed()).to.be.false('tray should not be destroyed')
tray.destroy()
expect(tray.isDestroyed()).to.be.true('tray should be destroyed')
})
})
describe('tray.popUpContextMenu()', () => {
ifit(process.platform === 'win32')('can be called when menu is showing', function (done) {
tray.setContextMenu(Menu.buildFromTemplate([{ label: 'Test' }]))
setTimeout(() => {
tray.popUpContextMenu()
done()
})
tray.popUpContextMenu()
})
it('can be called with a menu', () => {
const menu = Menu.buildFromTemplate([{ label: 'Test' }]);
expect(() => {
tray.popUpContextMenu(menu);
}).to.not.throw();
});
})
describe('tray.getBounds()', () => {
afterEach(() => { tray.destroy() })
ifit(process.platform !== 'linux') ('returns a bounds object', function () {
const bounds = tray.getBounds()
expect(bounds).to.be.an('object').and.to.have.all.keys('x', 'y', 'width', 'height');
})
})
describe('tray.setImage(image)', () => {
it('accepts empty image', () => {
tray.setImage(nativeImage.createEmpty())
})
})
describe('tray.setPressedImage(image)', () => {
it('accepts empty image', () => {
tray.setPressedImage(nativeImage.createEmpty())
})
})
ifdescribe(process.platform === 'darwin')('tray get/set title', () => {
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)
})
})
})