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 isReady: boolean = true;
const version: string = '4.0.0';
const openAtLogin: boolean = true;
interface IApp {
commandLine: any;
getAppPath(): string;
@ -20,9 +20,9 @@ interface IApp {
once(eventName: any, cb: any): void;
setPath(value: string, 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;
}
interface IIpcMain {
@ -74,7 +74,9 @@ export const app: IApp = {
ipcEmitter.on(eventName, cb);
},
setLoginItemSettings: () => jest.fn(),
getLoginItemSettings: () => { openAtLogin },
getLoginItemSettings: (): ILoginItemSettings => {
return { openAtLogin: true };
},
};
// 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 spy = jest.spyOn(autoLaunchInstance, spyFn);
jest.spyOn(autoLaunchInstance,'isAutoLaunchEnabled').mockImplementation(() => true);
jest.spyOn(autoLaunchInstance,'isAutoLaunchEnabled').mockImplementation(() => ({openAtLogin: true}));
await autoLaunchInstance.handleAutoLaunch();
console.log(autoLaunchInstance.isAutoLaunchEnabled());
expect(spy).toBeCalled();

View File

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