-
Notifications
You must be signed in to change notification settings - Fork 286
Expand file tree
/
Copy pathsystem.test.ts
More file actions
55 lines (45 loc) · 1.28 KB
/
system.test.ts
File metadata and controls
55 lines (45 loc) · 1.28 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
import type { Menubar } from 'menubar';
import { EVENTS } from '../../shared/events';
import { registerSystemHandlers } from './system';
const onMock = vi.fn();
vi.mock('electron', () => ({
ipcMain: {
on: (...args: unknown[]) => onMock(...args),
},
globalShortcut: {
register: vi.fn(),
unregister: vi.fn(),
},
app: {
setLoginItemSettings: vi.fn(),
},
shell: {
openExternal: vi.fn(),
},
}));
describe('main/handlers/system.ts', () => {
let menubar: Menubar;
beforeEach(() => {
menubar = {
showWindow: vi.fn(),
hideWindow: vi.fn(),
window: {
isVisible: vi.fn().mockReturnValue(false),
},
} as unknown as Menubar;
});
describe('registerSystemHandlers', () => {
it('registers handlers without throwing', () => {
expect(() => registerSystemHandlers(menubar)).not.toThrow();
});
it('registers expected system IPC event handlers', () => {
registerSystemHandlers(menubar);
const registeredEvents = onMock.mock.calls.map(
(call: [string]) => call[0],
);
expect(registeredEvents).toContain(EVENTS.OPEN_EXTERNAL);
expect(registeredEvents).toContain(EVENTS.UPDATE_KEYBOARD_SHORTCUT);
expect(registeredEvents).toContain(EVENTS.UPDATE_AUTO_LAUNCH);
});
});
});