-
Notifications
You must be signed in to change notification settings - Fork 285
Expand file tree
/
Copy pathwindow.test.ts
More file actions
61 lines (53 loc) · 1.4 KB
/
window.test.ts
File metadata and controls
61 lines (53 loc) · 1.4 KB
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
import type { Menubar } from 'menubar';
import { configureWindowEvents } from './window';
vi.mock('../config', () => ({
WindowConfig: {
width: 500,
height: 400,
},
}));
describe('main/lifecycle/window.ts', () => {
let menubar: Menubar;
beforeEach(() => {
menubar = {
hideWindow: vi.fn(),
tray: {
getBounds: vi
.fn()
.mockReturnValue({ x: 100, y: 100, width: 22, height: 22 }),
},
window: {
setSize: vi.fn(),
center: vi.fn(),
setAlwaysOnTop: vi.fn(),
webContents: {
on: vi.fn(),
},
},
positioner: {
move: vi.fn(),
},
} as unknown as Menubar;
});
it('configureWindowEvents returns early if no window', () => {
const mbNoWindow = { ...menubar, window: null };
expect(() =>
configureWindowEvents(mbNoWindow as unknown as Menubar),
).not.toThrow();
});
it('configureWindowEvents registers webContents event listeners', () => {
configureWindowEvents(menubar);
expect(menubar.window?.webContents.on).toHaveBeenCalledWith(
'before-input-event',
expect.any(Function),
);
expect(menubar.window?.webContents.on).toHaveBeenCalledWith(
'devtools-opened',
expect.any(Function),
);
expect(menubar.window?.webContents.on).toHaveBeenCalledWith(
'devtools-closed',
expect.any(Function),
);
});
});