2019-03-25 03:26:08 -05:00
|
|
|
import { handleChildWindow } from '../src/app/child-window-handler';
|
2019-04-08 02:35:14 -05:00
|
|
|
import { config } from '../src/app/config-handler';
|
2019-03-25 03:26:08 -05:00
|
|
|
import { windowHandler } from '../src/app/window-handler';
|
|
|
|
import { injectStyles } from '../src/app/window-utils';
|
|
|
|
import { ipcRenderer } from './__mocks__/electron';
|
|
|
|
|
|
|
|
const getMainWindow = {
|
2021-01-29 00:25:40 -06:00
|
|
|
isDestroyed: jest.fn(() => false),
|
|
|
|
getBounds: jest.fn(() => {
|
|
|
|
return {
|
|
|
|
x: 11,
|
|
|
|
y: 22,
|
|
|
|
};
|
|
|
|
}),
|
|
|
|
isAlwaysOnTop: jest.fn(() => true),
|
|
|
|
setMenuBarVisibility: jest.fn(),
|
|
|
|
setAlwaysOnTop: jest.fn(),
|
|
|
|
setFullScreenable: jest.fn(),
|
2019-03-25 03:26:08 -05:00
|
|
|
};
|
|
|
|
|
2020-09-25 04:46:33 -05:00
|
|
|
jest.mock('electron-log');
|
|
|
|
|
2019-03-25 03:26:08 -05:00
|
|
|
jest.mock('../src/common/env', () => {
|
2021-01-29 00:25:40 -06:00
|
|
|
return {
|
|
|
|
isWindowsOS: true,
|
|
|
|
isLinux: false,
|
|
|
|
isMac: false,
|
|
|
|
};
|
2019-03-25 03:26:08 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
jest.mock('../src/app/window-utils', () => {
|
2021-01-29 00:25:40 -06:00
|
|
|
return {
|
|
|
|
injectStyles: jest.fn(),
|
|
|
|
preventWindowNavigation: jest.fn(),
|
|
|
|
};
|
2019-03-25 03:26:08 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
jest.mock('../src/app/window-handler', () => {
|
2021-01-29 00:25:40 -06:00
|
|
|
return {
|
|
|
|
windowHandler: {
|
|
|
|
url: 'https://test.symphony.com',
|
|
|
|
getMainWindow: jest.fn(() => {
|
|
|
|
return getMainWindow;
|
|
|
|
}),
|
|
|
|
openUrlInDefaultBrowser: jest.fn(),
|
|
|
|
addWindow: jest.fn(),
|
|
|
|
},
|
|
|
|
};
|
2019-03-25 03:26:08 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
jest.mock('../src/app/window-actions', () => {
|
2021-01-29 00:25:40 -06:00
|
|
|
return {
|
|
|
|
monitorWindowActions: jest.fn(),
|
|
|
|
};
|
2019-03-25 03:26:08 -05:00
|
|
|
});
|
|
|
|
|
2020-09-25 04:46:33 -05:00
|
|
|
jest.mock('../src/common/logger', () => {
|
2021-01-29 00:25:40 -06:00
|
|
|
return {
|
|
|
|
logger: {
|
|
|
|
setLoggerWindow: jest.fn(),
|
|
|
|
error: jest.fn(),
|
|
|
|
warn: jest.fn(),
|
|
|
|
info: jest.fn(),
|
|
|
|
verbose: jest.fn(),
|
|
|
|
debug: jest.fn(),
|
|
|
|
silly: jest.fn(),
|
|
|
|
},
|
|
|
|
};
|
2020-09-25 04:46:33 -05:00
|
|
|
});
|
|
|
|
|
2019-03-25 03:26:08 -05:00
|
|
|
describe('child window handle', () => {
|
2021-01-29 00:25:40 -06:00
|
|
|
const frameName = {};
|
|
|
|
const disposition = 'new-window';
|
|
|
|
const newWinOptions = {
|
|
|
|
webPreferences: jest.fn(),
|
|
|
|
webContents: { ...ipcRenderer, ...getMainWindow, webContents: ipcRenderer },
|
|
|
|
};
|
2019-03-25 03:26:08 -05:00
|
|
|
|
2021-01-29 00:25:40 -06:00
|
|
|
it('should call `did-start-loading` correctly on WindowOS', () => {
|
|
|
|
const newWinUrl = 'about:blank';
|
|
|
|
const args = [newWinUrl, frameName, disposition, newWinOptions];
|
|
|
|
const spy = jest.spyOn(getMainWindow, 'setMenuBarVisibility');
|
|
|
|
handleChildWindow(ipcRenderer as any);
|
|
|
|
ipcRenderer.send('new-window', ...args);
|
|
|
|
ipcRenderer.send('did-start-loading');
|
|
|
|
expect(spy).toBeCalledWith(false);
|
|
|
|
});
|
2019-03-25 03:26:08 -05:00
|
|
|
|
2021-01-29 00:25:40 -06:00
|
|
|
it('should call `did-finish-load` correctly on WindowOS', () => {
|
|
|
|
config.getGlobalConfigFields = jest.fn(() => {
|
|
|
|
return {
|
|
|
|
url: 'https://foundation-dev.symphony.com',
|
|
|
|
};
|
2019-03-25 03:26:08 -05:00
|
|
|
});
|
2021-01-29 00:25:40 -06:00
|
|
|
const newWinUrl = 'about:blank';
|
|
|
|
const args = [newWinUrl, frameName, disposition, newWinOptions];
|
|
|
|
const spy = jest.spyOn(newWinOptions.webContents.webContents, 'send');
|
|
|
|
handleChildWindow(ipcRenderer as any);
|
|
|
|
ipcRenderer.send('new-window', ...args);
|
|
|
|
ipcRenderer.send('did-finish-load');
|
|
|
|
expect(spy).lastCalledWith('page-load', {
|
|
|
|
enableCustomTitleBar: false,
|
|
|
|
isMainWindow: false,
|
|
|
|
isWindowsOS: true,
|
|
|
|
locale: 'en-US',
|
|
|
|
origin: 'https://foundation-dev.symphony.com',
|
|
|
|
resources: {},
|
2019-03-25 03:26:08 -05:00
|
|
|
});
|
2021-01-29 00:25:40 -06:00
|
|
|
expect(injectStyles).toBeCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should call `windowHandler.openUrlInDefaultBrowser` when url in invalid', () => {
|
|
|
|
const newWinUrl = 'invalid';
|
|
|
|
const args = [newWinUrl, frameName, disposition, newWinOptions];
|
|
|
|
const spy = jest.spyOn(windowHandler, 'openUrlInDefaultBrowser');
|
|
|
|
handleChildWindow(ipcRenderer as any);
|
|
|
|
ipcRenderer.send('new-window', ...args);
|
|
|
|
expect(spy).not.toBeCalledWith('invalid');
|
|
|
|
});
|
2019-03-25 03:26:08 -05:00
|
|
|
});
|