-
Notifications
You must be signed in to change notification settings - Fork 286
Expand file tree
/
Copy pathreset.test.ts
More file actions
47 lines (35 loc) · 1.18 KB
/
reset.test.ts
File metadata and controls
47 lines (35 loc) · 1.18 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
import type { Menubar } from '@gitify/menubar';
vi.mock('electron', () => ({
dialog: {
showMessageBoxSync: vi.fn(() => 0),
} satisfies Pick<Electron.Dialog, 'showMessageBoxSync'>,
}));
const sendRendererEventMock = vi.fn();
vi.mock('../events', () => ({
sendRendererEvent: (...a: unknown[]) => sendRendererEventMock(...a),
}));
import { dialog } from 'electron';
import { EVENTS } from '../../shared/events';
import { resetApp } from './reset';
function createMb() {
return {
window: {},
app: { quit: vi.fn() },
};
}
describe('main/lifecycle/reset.ts', () => {
it('sends reset event and quits when user confirms', () => {
vi.mocked(dialog.showMessageBoxSync).mockReturnValue(1);
const mb = createMb();
resetApp(mb as unknown as Menubar);
expect(sendRendererEventMock).toHaveBeenCalledWith(mb, EVENTS.RESET_APP);
expect(mb.app.quit).toHaveBeenCalled();
});
it('does nothing when user cancels', () => {
vi.mocked(dialog.showMessageBoxSync).mockReturnValue(0);
const mb = createMb();
resetApp(mb as unknown as Menubar);
expect(sendRendererEventMock).not.toHaveBeenCalled();
expect(mb.app.quit).not.toHaveBeenCalled();
});
});