SymphonyElectron/spec/dialogHandler.spec.ts
Kiran Niranjan 0431a9f5ad fix: Upgrade master to 6.x (#795)
* Upgrade Electron version to 6.x

* fix: SDA-1347 (Group multiple processes into a single task bar icon) (#778)

* update mac build script

* update mac packager

* feat: ELECTRON-1462 (Combine more information into about app window) (#777)

* ELECTRON-1462 - Merge more info window in to about app window

* ELECTRON-1462 - Adjust window size

* ELECTRON-1462 - Add line space

* ELECTRON-1462 - Resize for windows

* ELECTRON-1462 - Add translation for swift search

* ELECTRON-1462 - Adjust width for Windows OS

* ELECTRON-1462 - Add about app snapshots file

* SDA-1347 - Group multiple processes into single task bar icon

* Change dependency from gulp-tsc to gulp-typescript

* 6.x Update activity detection api

* 6.x Update aip file to remove unwanted spellchecker files

* 6.x Update electron version to 6.1.2

* 6.x Update SDA version and change spellchecker base

* 6.x Update electron-builder version to support 6.x

* 6.x fix escape char for window build command

* 6.x Optimize log path set and get methods

* 6.x Change yml to json

* 6.x Make Window local path as default user data path
2019-10-30 20:58:25 +05:30

105 lines
4.1 KiB
TypeScript

import { showLoadFailure, showNetworkConnectivityError } from '../src/app/dialog-handler';
import { windowHandler } from '../src/app/window-handler';
import { dialog, ipcRenderer } from './__mocks__/electron';
jest.mock('../src/app/window-handler', () => {
return {
windowHandler: {
createBasicAuthWindow: jest.fn(),
},
};
});
jest.mock('../src/renderer/notification', () => {
return {
setupNotificationPosition: jest.fn(),
};
});
jest.mock('electron-log');
describe('dialog handler', () => {
const callbackMocked = jest.fn();
const webContentsMocked = jest.fn();
beforeEach(() => {
jest.clearAllMocks().resetModules();
});
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);
});
describe('certificate-error', () => {
const urlMocked = 'https://symphony.corporate.com/';
const errorMocked = 'check for server certificate revocation';
const certificate = null;
it('should return false when buttonId is 1', async (done) => {
dialog.showMessageBox = jest.fn(() => {
return { response: 1 };
});
await ipcRenderer.send('certificate-error', webContentsMocked, urlMocked, errorMocked, certificate, callbackMocked);
done(expect(callbackMocked).toBeCalledWith(false));
});
it('should return true when buttonId is not 1', async (done) => {
dialog.showMessageBox = jest.fn(() => 2);
await ipcRenderer.send('certificate-error', webContentsMocked, urlMocked, errorMocked, certificate, callbackMocked);
expect(callbackMocked).toBeCalledWith(true);
await ipcRenderer.send('certificate-error', webContentsMocked, urlMocked, errorMocked, certificate, callbackMocked);
done(expect(callbackMocked).toBeCalledWith(true));
});
});
});
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);
});
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);
});
});