fix: SDA-1890 (Fix auto launch on startup for cloud config) (#934)

* SDA-1890 - Fix auto launch on start up for cloud config

* SDA-1890 - Fix unit tests
This commit is contained in:
Kiran Niranjan 2020-03-20 10:38:38 +05:30 committed by GitHub
parent a104af42c6
commit d61473febe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 5 deletions

View File

@ -6,11 +6,16 @@ jest.mock('electron-log');
jest.mock('../src/app/config-handler', () => {
return {
CloudConfigDataTypes: {
NOT_SET: 'NOT_SET',
ENABLED: 'ENABLED',
DISABLED: 'DISABLED',
},
config: {
getGlobalConfigFields: jest.fn(() => ''),
getConfigFields: jest.fn(() => {
return {
launchOnStartup: true,
launchOnStartup: 'ENABLED',
};
}),
updateUserConfig: jest.fn(),
@ -23,7 +28,7 @@ describe('auto launch controller', async () => {
beforeEach(() => {
jest.spyOn(config, 'getConfigFields').mockImplementation(() => {
return {
launchOnStartup: true,
launchOnStartup: 'ENABLED',
};
});
jest.clearAllMocks();
@ -61,7 +66,7 @@ describe('auto launch controller', async () => {
it('should disable AutoLaunch when `handleAutoLaunch` is called', async () => {
jest.spyOn(config, 'getConfigFields').mockImplementation(() => {
return {
launchOnStartup: false,
launchOnStartup: 'DISABLED',
};
});
const spyFn = 'disableAutoLaunch';

View File

@ -2,7 +2,7 @@ import { app, LoginItemSettings } from 'electron';
import { isMac } from '../common/env';
import { logger } from '../common/logger';
import { config, IConfig } from './config-handler';
import { CloudConfigDataTypes, config, IConfig } from './config-handler';
const { autoLaunchPath }: IConfig = config.getConfigFields([ 'autoLaunchPath' ]);
@ -57,7 +57,7 @@ class AutoLaunchController {
const { launchOnStartup }: IConfig = config.getConfigFields([ 'launchOnStartup' ]);
const { openAtLogin: isAutoLaunchEnabled }: LoginItemSettings = this.isAutoLaunchEnabled();
if (typeof launchOnStartup === 'boolean' && launchOnStartup) {
if (launchOnStartup === CloudConfigDataTypes.ENABLED) {
if (!isAutoLaunchEnabled) {
this.enableAutoLaunch();
}