Skip to content
This repository was archived by the owner on Jan 5, 2026. It is now read-only.

Commit 90beb45

Browse files
committed
Fixed tests.
1 parent cf8e152 commit 90beb45

5 files changed

Lines changed: 23 additions & 8 deletions

File tree

packages/app/main/src/appMenuBuilder.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ jest.mock('electron', () => ({
118118
isInvertedColorScheme: jest.fn(() => true),
119119
on: jest.fn(() => null),
120120
},
121+
nativeTheme: {
122+
on: jest.fn(() => null),
123+
},
121124
}));
122125

123126
const mockUpdateStatus = {

packages/app/main/src/commands/azureCommands.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ jest.mock('electron', () => ({
8888
},
8989
session: {
9090
defaultSession: {
91-
clearStorageData: (options, cb) => cb(true),
91+
clearStorageData: _options => null,
9292
},
9393
},
9494
ipcMain: new Proxy(

packages/app/main/src/commands/electronCommands.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ jest.mock('electron', () => ({
6767
showMessageBox: (mainBrowserWindow: any, p: { buttons: string[]; type: string; title: string; message: string }) =>
6868
void 0,
6969
showOpenDialog: () => void 0,
70-
showSaveDialog: () => void 0,
70+
showSaveDialogSync: () => void 0,
7171
},
7272
shell: {
7373
get openExternal() {
@@ -197,7 +197,7 @@ describe('the electron commands', () => {
197197

198198
it('should show the save dialog', async () => {
199199
const handler = registry.getCommand(SharedConstants.Commands.Electron.ShowSaveDialog);
200-
const showSaveDialogSpy = jest.spyOn(Electron.dialog, 'showSaveDialog');
200+
const showSaveDialogSpy = jest.spyOn(Electron.dialog, 'showSaveDialogSync');
201201

202202
await handler({});
203203
expect(showSaveDialogSpy).toHaveBeenCalledWith(emulatorApplication.mainWindow.browserWindow, {});

packages/app/main/src/main.spec.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@ import * as path from 'path';
3535

3636
import { CommandServiceImpl, CommandServiceInstance } from '@bfemulator/sdk-shared';
3737
import { SharedConstants } from '@bfemulator/app-shared';
38-
import { systemPreferences } from 'electron';
38+
import { nativeTheme } from 'electron';
3939

4040
import { emulatorApplication } from './main';
4141

42+
let mockShouldUseInvertedColorScheme = true;
4243
jest.mock('electron', () => ({
4344
app: {
4445
on: () => void 0,
@@ -72,6 +73,12 @@ jest.mock('electron', () => ({
7273
on: jest.fn(() => null),
7374
onInvertedColorSchemeChanged: jest.fn(() => true),
7475
},
76+
nativeTheme: {
77+
on: jest.fn(() => null),
78+
get shouldUseInvertedColorScheme() {
79+
return mockShouldUseInvertedColorScheme;
80+
},
81+
},
7582
}));
7683

7784
jest.mock('./server/webSocketServer', () => ({
@@ -89,18 +96,19 @@ describe('main', () => {
8996
const decorator = CommandServiceInstance();
9097
const descriptor = decorator({ descriptor: {} }, 'none') as any;
9198
commandService = descriptor.descriptor.get();
99+
mockShouldUseInvertedColorScheme = true;
92100
});
93101

94102
afterEach(() => {
95103
emulatorAppSpy.mockClear();
96104
});
97105

98-
it('should call `onInvertedColorSchemeChanged` when `inverted-color-scheme-changed` event is triggered', () => {
99-
const onSpy = jest.spyOn(systemPreferences, 'on');
106+
it('should call `onInvertedColorSchemeChanged` when `updated` event is triggered', () => {
107+
const onSpy = jest.spyOn(nativeTheme, 'on');
100108

101109
(emulatorApplication as any).initializeSystemPreferencesListeners();
102110

103-
expect(onSpy).toHaveBeenCalledWith('inverted-color-scheme-changed', jasmine.any(Function));
111+
expect(onSpy).toHaveBeenCalledWith('updated', jasmine.any(Function));
104112

105113
onSpy.mockClear();
106114
});
@@ -123,7 +131,7 @@ describe('main', () => {
123131
it('should not change to high contrast when theme is not high contrast', () => {
124132
const commandServiceSpy = jest.spyOn(commandService, 'remoteCall');
125133

126-
(systemPreferences.isInvertedColorScheme as any).mockImplementationOnce(() => false);
134+
mockShouldUseInvertedColorScheme = false;
127135

128136
(emulatorApplication as any).onInvertedColorSchemeChanged();
129137

packages/app/main/src/services/azureAuthWorkflowService.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ jest.mock('electron', () => ({
8181
// no-op
8282
}
8383

84+
removeMenu() {
85+
// no-op
86+
}
87+
8488
addListener(type: string, handler: () => void) {
8589
this.listeners.push({ type, handler });
8690
MockBrowserWindow.report('addListener', type, handler);

0 commit comments

Comments
 (0)