fix auto launch controller failing test

This commit is contained in:
Vishwas Shashidhar 2019-05-07 14:16:59 +05:30
parent 9e347bab77
commit 5adc162b2e
3 changed files with 7 additions and 8 deletions

View File

@ -8,7 +8,7 @@ const appName: string = 'Symphony';
const executableName: string = '/Symphony.exe'; const executableName: string = '/Symphony.exe';
const isReady: boolean = true; const isReady: boolean = true;
const version: string = '4.0.0'; const version: string = '4.0.0';
const openAtLogin: boolean = true;
interface IApp { interface IApp {
commandLine: any; commandLine: any;
getAppPath(): string; getAppPath(): string;
@ -20,9 +20,9 @@ interface IApp {
once(eventName: any, cb: any): void; once(eventName: any, cb: any): void;
setPath(value: string, path: string): void; setPath(value: string, path: string): void;
setLoginItemSettings(settings: { openAtLogin: boolean, path: string }): void; setLoginItemSettings(settings: { openAtLogin: boolean, path: string }): void;
getLoginItemSettings(options?: { path: string, args: string[] }): LoginItemSettings; getLoginItemSettings(options?: { path: string, args: string[] }): ILoginItemSettings;
} }
interface LoginItemSettings { interface ILoginItemSettings {
openAtLogin: boolean; openAtLogin: boolean;
} }
interface IIpcMain { interface IIpcMain {
@ -74,7 +74,9 @@ export const app: IApp = {
ipcEmitter.on(eventName, cb); ipcEmitter.on(eventName, cb);
}, },
setLoginItemSettings: () => jest.fn(), setLoginItemSettings: () => jest.fn(),
getLoginItemSettings: () => { openAtLogin }, getLoginItemSettings: (): ILoginItemSettings => {
return { openAtLogin: true };
},
}; };
// simple ipc mocks for render and main process ipc using // simple ipc mocks for render and main process ipc using

View File

@ -66,7 +66,7 @@ describe('auto launch controller', async () => {
}); });
const spyFn = 'disableAutoLaunch'; const spyFn = 'disableAutoLaunch';
const spy = jest.spyOn(autoLaunchInstance, spyFn); const spy = jest.spyOn(autoLaunchInstance, spyFn);
jest.spyOn(autoLaunchInstance,'isAutoLaunchEnabled').mockImplementation(() => true); jest.spyOn(autoLaunchInstance,'isAutoLaunchEnabled').mockImplementation(() => ({openAtLogin: true}));
await autoLaunchInstance.handleAutoLaunch(); await autoLaunchInstance.handleAutoLaunch();
console.log(autoLaunchInstance.isAutoLaunchEnabled()); console.log(autoLaunchInstance.isAutoLaunchEnabled());
expect(spy).toBeCalled(); expect(spy).toBeCalled();

View File

@ -57,15 +57,12 @@ class AutoLaunchController {
const { launchOnStartup }: IConfig = config.getConfigFields([ 'launchOnStartup' ]); const { launchOnStartup }: IConfig = config.getConfigFields([ 'launchOnStartup' ]);
const { openAtLogin: isAutoLaunchEnabled }: LoginItemSettings = this.isAutoLaunchEnabled(); const { openAtLogin: isAutoLaunchEnabled }: LoginItemSettings = this.isAutoLaunchEnabled();
console.log(this.isAutoLaunchEnabled());
if (typeof launchOnStartup === 'boolean' && launchOnStartup) { if (typeof launchOnStartup === 'boolean' && launchOnStartup) {
if (!isAutoLaunchEnabled) { if (!isAutoLaunchEnabled) {
this.enableAutoLaunch(); this.enableAutoLaunch();
} }
return; return;
} }
console.log(`Auto launch enabled!! ${isAutoLaunchEnabled}`)
if (isAutoLaunchEnabled) { if (isAutoLaunchEnabled) {
this.disableAutoLaunch(); this.disableAutoLaunch();
} }