2021-01-29 00:25:40 -06:00
|
|
|
import {
|
|
|
|
showLoadFailure,
|
|
|
|
showNetworkConnectivityError,
|
|
|
|
} from '../src/app/dialog-handler';
|
2019-03-30 00:09:34 -05:00
|
|
|
import { windowHandler } from '../src/app/window-handler';
|
2020-03-06 03:07:18 -06:00
|
|
|
import { BrowserWindow, dialog, ipcRenderer } from './__mocks__/electron';
|
2019-03-30 00:09:34 -05:00
|
|
|
|
2022-07-11 20:34:05 -05:00
|
|
|
jest.mock('../src/app/auto-update-handler', () => {
|
|
|
|
return {
|
|
|
|
updateAndRestart: jest.fn(),
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2022-06-14 03:30:20 -05:00
|
|
|
jest.mock('fs', () => ({
|
|
|
|
writeFileSync: jest.fn(),
|
|
|
|
existsSync: jest.fn(() => true),
|
|
|
|
unlinkSync: jest.fn(),
|
|
|
|
readFileSync: jest.fn(() => '{ "configVersion": "4.0.0" }'),
|
|
|
|
readdirSync: jest.fn(() => [
|
|
|
|
'Cache',
|
|
|
|
'GPUCache',
|
|
|
|
'Symphony.config',
|
|
|
|
'cloudConfig.config',
|
|
|
|
]),
|
|
|
|
readFile: jest.fn(),
|
|
|
|
writeFile: jest.fn(),
|
|
|
|
lstatSync: jest.fn(() => {
|
|
|
|
return {
|
|
|
|
isDirectory: jest.fn(() => true),
|
|
|
|
};
|
|
|
|
}),
|
|
|
|
}));
|
|
|
|
|
2019-03-30 00:09:34 -05:00
|
|
|
jest.mock('../src/app/window-handler', () => {
|
2021-01-29 00:25:40 -06:00
|
|
|
return {
|
|
|
|
windowHandler: {
|
|
|
|
createBasicAuthWindow: jest.fn(),
|
|
|
|
},
|
|
|
|
};
|
2019-03-30 00:09:34 -05:00
|
|
|
});
|
|
|
|
|
2024-02-19 03:41:50 -06:00
|
|
|
jest.mock('../src/app/plist-handler', () => {
|
|
|
|
return {};
|
|
|
|
});
|
|
|
|
jest.mock('../src/app/config-handler', () => {
|
|
|
|
return {
|
|
|
|
CloudConfigDataTypes: {
|
|
|
|
NOT_SET: 'NOT_SET',
|
|
|
|
ENABLED: 'ENABLED',
|
|
|
|
DISABLED: 'DISABLED',
|
|
|
|
},
|
|
|
|
config: {
|
|
|
|
getConfigFields: jest.fn(() => {
|
|
|
|
return {
|
|
|
|
minimizeOnClose: 'ENABLED',
|
|
|
|
launchOnStartup: 'ENABLED',
|
|
|
|
alwaysOnTop: 'ENABLED',
|
|
|
|
isAlwaysOnTop: 'ENABLED',
|
|
|
|
bringToFront: 'ENABLED',
|
|
|
|
devToolsEnabled: true,
|
|
|
|
};
|
|
|
|
}),
|
|
|
|
getGlobalConfigFields: jest.fn(() => {
|
|
|
|
return {
|
|
|
|
devToolsEnabled: true,
|
|
|
|
};
|
|
|
|
}),
|
|
|
|
getFilteredCloudConfigFields: jest.fn(() => {
|
|
|
|
return {
|
|
|
|
devToolsEnabled: true,
|
|
|
|
};
|
|
|
|
}),
|
|
|
|
getCloudConfigFields: jest.fn(() => {
|
|
|
|
return {
|
|
|
|
devToolsEnabled: true,
|
|
|
|
};
|
|
|
|
}),
|
|
|
|
updateUserConfig: jest.fn(),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2019-07-12 10:55:48 -05:00
|
|
|
jest.mock('../src/renderer/notification', () => {
|
2021-01-29 00:25:40 -06:00
|
|
|
return {
|
|
|
|
setupNotificationPosition: jest.fn(),
|
|
|
|
};
|
2019-07-12 10:55:48 -05:00
|
|
|
});
|
|
|
|
|
2019-03-30 00:09:34 -05:00
|
|
|
jest.mock('electron-log');
|
|
|
|
|
|
|
|
describe('dialog handler', () => {
|
2021-01-29 00:25:40 -06:00
|
|
|
const callbackMocked = jest.fn();
|
|
|
|
const webContentsMocked = jest.fn();
|
2019-03-30 00:09:34 -05:00
|
|
|
|
2021-01-29 00:25:40 -06:00
|
|
|
beforeEach(() => {
|
|
|
|
jest.clearAllMocks().resetModules();
|
|
|
|
});
|
2019-03-30 00:09:34 -05:00
|
|
|
|
2021-01-29 00:25:40 -06:00
|
|
|
describe('events', () => {
|
|
|
|
it('should call login correctly', () => {
|
|
|
|
const spy = jest.spyOn(windowHandler, 'createBasicAuthWindow');
|
|
|
|
const requestMocked = {
|
|
|
|
url: 'https://symphony.corporate.com/',
|
|
|
|
};
|
|
|
|
const authInfoMocked = {
|
|
|
|
host: 'symphony.com',
|
|
|
|
};
|
|
|
|
ipcRenderer.send(
|
|
|
|
'login',
|
|
|
|
webContentsMocked,
|
|
|
|
requestMocked,
|
|
|
|
authInfoMocked,
|
|
|
|
callbackMocked,
|
|
|
|
);
|
|
|
|
expect(spy).toBeCalledWith(
|
|
|
|
webContentsMocked,
|
|
|
|
'symphony.com',
|
|
|
|
true,
|
|
|
|
expect.any(Function),
|
|
|
|
callbackMocked,
|
|
|
|
);
|
|
|
|
});
|
2019-03-30 00:09:34 -05:00
|
|
|
|
2021-01-29 00:25:40 -06:00
|
|
|
describe('certificate-error', () => {
|
2022-04-07 03:37:27 -05:00
|
|
|
let urlMocked;
|
2021-01-29 00:25:40 -06:00
|
|
|
const errorMocked = 'check for server certificate revocation';
|
|
|
|
const certificate = null;
|
2022-04-07 03:37:27 -05:00
|
|
|
beforeEach(() => {
|
|
|
|
jest.clearAllMocks().resetModules();
|
|
|
|
});
|
|
|
|
it('should return true when buttonId is 0', async (done) => {
|
|
|
|
urlMocked = 'https://symphony.corporate.com/';
|
2021-01-29 00:25:40 -06:00
|
|
|
BrowserWindow.fromWebContents = jest.fn(() => {
|
|
|
|
return { isDestroyed: jest.fn(() => false) };
|
|
|
|
});
|
|
|
|
dialog.showMessageBox = jest.fn(() => {
|
2022-04-07 03:37:27 -05:00
|
|
|
return { response: 0 };
|
2021-01-29 00:25:40 -06:00
|
|
|
});
|
|
|
|
await ipcRenderer.send(
|
|
|
|
'certificate-error',
|
|
|
|
webContentsMocked,
|
|
|
|
urlMocked,
|
|
|
|
errorMocked,
|
|
|
|
certificate,
|
|
|
|
callbackMocked,
|
|
|
|
);
|
2022-04-07 03:37:27 -05:00
|
|
|
expect(callbackMocked).toBeCalledWith(true);
|
|
|
|
await ipcRenderer.send(
|
|
|
|
'certificate-error',
|
|
|
|
webContentsMocked,
|
|
|
|
urlMocked,
|
|
|
|
errorMocked,
|
|
|
|
certificate,
|
|
|
|
callbackMocked,
|
|
|
|
);
|
|
|
|
done(expect(callbackMocked).toBeCalledWith(true));
|
2021-01-29 00:25:40 -06:00
|
|
|
});
|
2019-03-30 00:09:34 -05:00
|
|
|
|
2022-04-07 03:37:27 -05:00
|
|
|
it('should return false when buttonId is 1', async (done) => {
|
|
|
|
urlMocked = 'https://symphony2.corporate.com/';
|
2021-01-29 00:25:40 -06:00
|
|
|
BrowserWindow.fromWebContents = jest.fn(() => {
|
|
|
|
return { isDestroyed: jest.fn(() => false) };
|
2019-03-30 00:09:34 -05:00
|
|
|
});
|
2022-04-07 03:37:27 -05:00
|
|
|
dialog.showMessageBox = jest.fn(() => {
|
|
|
|
return { response: 1 };
|
|
|
|
});
|
2021-01-29 00:25:40 -06:00
|
|
|
await ipcRenderer.send(
|
|
|
|
'certificate-error',
|
|
|
|
webContentsMocked,
|
|
|
|
urlMocked,
|
|
|
|
errorMocked,
|
|
|
|
certificate,
|
|
|
|
callbackMocked,
|
|
|
|
);
|
2022-04-07 03:37:27 -05:00
|
|
|
expect(callbackMocked).toBeCalledWith(false);
|
2021-01-29 00:25:40 -06:00
|
|
|
await ipcRenderer.send(
|
|
|
|
'certificate-error',
|
|
|
|
webContentsMocked,
|
|
|
|
urlMocked,
|
|
|
|
errorMocked,
|
|
|
|
certificate,
|
|
|
|
callbackMocked,
|
|
|
|
);
|
2022-04-07 03:37:27 -05:00
|
|
|
done(expect(callbackMocked).toBeCalledWith(false));
|
2021-01-29 00:25:40 -06:00
|
|
|
});
|
2019-03-30 00:09:34 -05:00
|
|
|
});
|
2021-01-29 00:25:40 -06:00
|
|
|
});
|
2019-03-30 00:09:34 -05:00
|
|
|
|
2021-01-29 00:25:40 -06:00
|
|
|
it('should call `showLoadFailure` correctly', () => {
|
|
|
|
const spyFn = 'showMessageBox';
|
|
|
|
const spy = jest.spyOn(dialog, spyFn);
|
|
|
|
const browserWindowMocked: any = { id: 123 };
|
|
|
|
const urlMocked = 'test';
|
|
|
|
const errorDescMocked = 'error';
|
|
|
|
const errorCodeMocked = 404;
|
|
|
|
const showDialogMocked = true;
|
|
|
|
const expectedValue = {
|
|
|
|
type: 'error',
|
|
|
|
buttons: ['Reload', 'Ignore'],
|
|
|
|
defaultId: 0,
|
|
|
|
cancelId: 1,
|
|
|
|
noLink: true,
|
|
|
|
title: 'Loading Error',
|
|
|
|
message: `Error loading URL:\n${urlMocked}\n\n${errorDescMocked}\n\nError Code: ${errorCodeMocked}`,
|
|
|
|
};
|
|
|
|
showLoadFailure(
|
|
|
|
browserWindowMocked,
|
|
|
|
urlMocked,
|
|
|
|
errorDescMocked,
|
|
|
|
errorCodeMocked,
|
|
|
|
callbackMocked,
|
|
|
|
showDialogMocked,
|
|
|
|
);
|
|
|
|
expect(spy).toBeCalledWith({ id: 123 }, expectedValue);
|
|
|
|
});
|
2019-03-30 00:09:34 -05:00
|
|
|
|
2021-01-29 00:25:40 -06:00
|
|
|
it('should call `showNetworkConnectivityError` correctly', () => {
|
|
|
|
const spyFn = 'showMessageBox';
|
|
|
|
const spy = jest.spyOn(dialog, spyFn);
|
|
|
|
const browserWindowMocked: any = { id: 123 };
|
|
|
|
const urlMocked = 'test';
|
|
|
|
const errorDescMocked =
|
|
|
|
'Network connectivity has been lost. Check your internet connection.';
|
|
|
|
const expectedValue = {
|
|
|
|
type: 'error',
|
|
|
|
buttons: ['Reload', 'Ignore'],
|
|
|
|
defaultId: 0,
|
|
|
|
cancelId: 1,
|
|
|
|
noLink: true,
|
|
|
|
title: 'Loading Error',
|
|
|
|
message: `Error loading URL:\n${urlMocked}\n\n${errorDescMocked}`,
|
|
|
|
};
|
|
|
|
showNetworkConnectivityError(
|
|
|
|
browserWindowMocked,
|
|
|
|
urlMocked,
|
|
|
|
callbackMocked,
|
|
|
|
);
|
|
|
|
expect(spy).toBeCalledWith({ id: 123 }, expectedValue);
|
|
|
|
});
|
2019-03-30 00:09:34 -05:00
|
|
|
});
|