-
Notifications
You must be signed in to change notification settings - Fork 285
Expand file tree
/
Copy pathapp.test.ts
More file actions
61 lines (50 loc) · 1.62 KB
/
app.test.ts
File metadata and controls
61 lines (50 loc) · 1.62 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 { EVENTS } from '../../shared/events';
import { registerAppHandlers } from './app';
const handleMock = vi.fn();
const onMock = vi.fn();
vi.mock('electron', () => ({
ipcMain: {
handle: (...args: unknown[]) => handleMock(...args),
on: (...args: unknown[]) => onMock(...args),
},
app: {
getVersion: vi.fn(() => '1.0.0'),
},
}));
vi.mock('../config', () => ({
Paths: {
notificationSound: 'file:///path/to/notification.mp3',
twemojiFolder: 'file:///path/to/twemoji',
},
}));
describe('main/handlers/app.ts', () => {
let menubar: Menubar;
beforeEach(() => {
menubar = {
showWindow: vi.fn(),
hideWindow: vi.fn(),
app: { quit: vi.fn() },
} as unknown as Menubar;
});
describe('registerAppHandlers', () => {
it('registers handlers without throwing', () => {
expect(() => registerAppHandlers(menubar)).not.toThrow();
});
it('registers expected app IPC event handlers', () => {
registerAppHandlers(menubar);
const registeredHandlers = handleMock.mock.calls.map(
(call: unknown[]) => call[0],
);
const registeredEvents = onMock.mock.calls.map(
(call: unknown[]) => call[0],
);
expect(registeredHandlers).toContain(EVENTS.VERSION);
expect(registeredHandlers).toContain(EVENTS.NOTIFICATION_SOUND_PATH);
expect(registeredHandlers).toContain(EVENTS.TWEMOJI_DIRECTORY);
expect(registeredEvents).toContain(EVENTS.WINDOW_SHOW);
expect(registeredEvents).toContain(EVENTS.WINDOW_HIDE);
expect(registeredEvents).toContain(EVENTS.QUIT);
});
});
});