forked from electron/electron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi-touch-bar-spec.ts
128 lines (115 loc) · 4.81 KB
/
api-touch-bar-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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import * as path from 'node:path';
import { BrowserWindow, TouchBar } from 'electron/main';
import { closeWindow } from './lib/window-helpers';
import { expect } from 'chai';
const { TouchBarButton, TouchBarColorPicker, TouchBarGroup, TouchBarLabel, TouchBarOtherItemsProxy, TouchBarPopover, TouchBarScrubber, TouchBarSegmentedControl, TouchBarSlider, TouchBarSpacer } = TouchBar;
describe('TouchBar module', () => {
it('throws an error when created without an options object', () => {
expect(() => {
const touchBar = new (TouchBar as any)();
touchBar.toString();
}).to.throw('Must specify options object as first argument');
});
it('throws an error when created with invalid items', () => {
expect(() => {
const touchBar = new TouchBar({ items: [1, true, {}, []] as any });
touchBar.toString();
}).to.throw('Each item must be an instance of TouchBarItem');
});
it('throws an error when an invalid escape item is set', () => {
expect(() => {
const touchBar = new TouchBar({ items: [], escapeItem: 'esc' as any });
touchBar.toString();
}).to.throw('Escape item must be an instance of TouchBarItem');
expect(() => {
const touchBar = new TouchBar({ items: [] });
touchBar.escapeItem = 'esc' as any;
}).to.throw('Escape item must be an instance of TouchBarItem');
});
it('throws an error if multiple OtherItemProxy items are added', () => {
expect(() => {
const touchBar = new TouchBar({ items: [new TouchBarOtherItemsProxy(), new TouchBarOtherItemsProxy()] });
touchBar.toString();
}).to.throw('Must only have one OtherItemsProxy per TouchBar');
});
it('throws an error if the same TouchBarItem is added multiple times', () => {
expect(() => {
const item = new TouchBarLabel({ label: 'Label' });
const touchBar = new TouchBar({ items: [item, item] });
touchBar.toString();
}).to.throw('Cannot add a single instance of TouchBarItem multiple times in a TouchBar');
});
describe('BrowserWindow behavior', () => {
let window: BrowserWindow;
beforeEach(() => {
window = new BrowserWindow({ show: false });
});
afterEach(async () => {
window.setTouchBar(null);
await closeWindow(window);
window = null as unknown as BrowserWindow;
});
it('can be added to and removed from a window', () => {
const label = new TouchBarLabel({ label: 'bar' });
const touchBar = new TouchBar({
items: [
new TouchBarButton({ label: 'foo', backgroundColor: '#F00', click: () => { } }),
new TouchBarButton({
icon: path.join(__dirname, 'fixtures', 'assets', 'logo.png'),
iconPosition: 'right',
click: () => { }
}),
new TouchBarColorPicker({ selectedColor: '#F00', change: () => { } }),
new TouchBarGroup({ items: new TouchBar({ items: [new TouchBarLabel({ label: 'hello' })] }) }),
label,
new TouchBarOtherItemsProxy(),
new TouchBarPopover({ items: new TouchBar({ items: [new TouchBarButton({ label: 'pop' })] }) }),
new TouchBarSlider({ label: 'slide', value: 5, minValue: 2, maxValue: 75, change: () => { } }),
new TouchBarSpacer({ size: 'large' }),
new TouchBarSegmentedControl({
segmentStyle: 'capsule',
segments: [{ label: 'baz', enabled: false }],
selectedIndex: 5
}),
new TouchBarSegmentedControl({ segments: [] }),
new TouchBarScrubber({
items: [{ label: 'foo' }, { label: 'bar' }, { label: 'baz' }],
selectedStyle: 'outline',
mode: 'fixed',
showArrowButtons: true
})
]
});
const escapeButton = new TouchBarButton({ label: 'foo' });
window.setTouchBar(touchBar);
touchBar.escapeItem = escapeButton;
label.label = 'baz';
escapeButton.label = 'hello';
window.setTouchBar(null);
window.setTouchBar(new TouchBar({ items: [new TouchBarLabel({ label: 'two' })] }));
touchBar.escapeItem = null;
});
it('calls the callback on the items when a window interaction event fires', (done) => {
const button = new TouchBarButton({
label: 'bar',
click: () => {
done();
}
});
const touchBar = new TouchBar({ items: [button] });
window.setTouchBar(touchBar);
window.emit('-touch-bar-interaction', {}, (button as any).id);
});
it('calls the callback on the escape item when a window interaction event fires', (done) => {
const button = new TouchBarButton({
label: 'bar',
click: () => {
done();
}
});
const touchBar = new TouchBar({ escapeItem: button });
window.setTouchBar(touchBar);
window.emit('-touch-bar-interaction', {}, (button as any).id);
});
});
});