mirror of
https://github.com/finos/SymphonyElectron.git
synced 2024-12-29 02:11:28 -06:00
child window handle unit test (#610)
This commit is contained in:
parent
5905b7507d
commit
bb9d547ae3
@ -24,8 +24,9 @@ interface IIpcMain {
|
|||||||
interface IIpcRenderer {
|
interface IIpcRenderer {
|
||||||
sendSync(event: any, cb: any): any;
|
sendSync(event: any, cb: any): any;
|
||||||
on(eventName: any, cb: any): void;
|
on(eventName: any, cb: any): void;
|
||||||
send(event: any, cb: any): void;
|
send(event: any, ...cb: any[]): void;
|
||||||
removeListener(eventName: any, cb: any): void;
|
removeListener(eventName: any, cb: any): void;
|
||||||
|
once(eventName: any, cb: any): void;
|
||||||
}
|
}
|
||||||
interface IPowerMonitor {
|
interface IPowerMonitor {
|
||||||
querySystemIdleTime(): void;
|
querySystemIdleTime(): void;
|
||||||
@ -91,15 +92,16 @@ export const ipcRenderer: IIpcRenderer = {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
send: (event, args) => {
|
send: (event, ...args) => {
|
||||||
const senderEvent = {
|
const senderEvent = {
|
||||||
sender: {
|
sender: {
|
||||||
send: (eventSend, arg) => {
|
send: (eventSend, ...arg) => {
|
||||||
ipcEmitter.emit(eventSend, arg);
|
ipcEmitter.emit(eventSend, ...arg);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
preventDefault: jest.fn(),
|
||||||
};
|
};
|
||||||
ipcEmitter.emit(event, senderEvent, args);
|
ipcEmitter.emit(event, senderEvent, ...args);
|
||||||
},
|
},
|
||||||
on: (eventName, cb) => {
|
on: (eventName, cb) => {
|
||||||
ipcEmitter.on(eventName, cb);
|
ipcEmitter.on(eventName, cb);
|
||||||
@ -107,12 +109,21 @@ export const ipcRenderer: IIpcRenderer = {
|
|||||||
removeListener: (eventName, cb) => {
|
removeListener: (eventName, cb) => {
|
||||||
ipcEmitter.removeListener(eventName, cb);
|
ipcEmitter.removeListener(eventName, cb);
|
||||||
},
|
},
|
||||||
|
once: (eventName, cb) => {
|
||||||
|
ipcEmitter.on(eventName, cb);
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export const shell = {
|
export const shell = {
|
||||||
openExternal: jest.fn(),
|
openExternal: jest.fn(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// tslint:disable-next-line:variable-name
|
||||||
|
export const BrowserWindow = {
|
||||||
|
fromWebContents: (arg) => arg,
|
||||||
|
getAllWindows: jest.fn(() => []),
|
||||||
|
};
|
||||||
|
|
||||||
// tslint:disable-next-line:variable-name
|
// tslint:disable-next-line:variable-name
|
||||||
export const Menu = {
|
export const Menu = {
|
||||||
buildFromTemplate: jest.fn(),
|
buildFromTemplate: jest.fn(),
|
||||||
|
90
spec/childWindowHandle.spec.ts
Normal file
90
spec/childWindowHandle.spec.ts
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
import { handleChildWindow } from '../src/app/child-window-handler';
|
||||||
|
import { windowHandler } from '../src/app/window-handler';
|
||||||
|
import { injectStyles } from '../src/app/window-utils';
|
||||||
|
import { ipcRenderer } from './__mocks__/electron';
|
||||||
|
|
||||||
|
const getMainWindow = {
|
||||||
|
isDestroyed: jest.fn(() => false),
|
||||||
|
getBounds: jest.fn(() => {
|
||||||
|
return {
|
||||||
|
x: 11,
|
||||||
|
y: 22,
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
isAlwaysOnTop: jest.fn(() => true),
|
||||||
|
setMenuBarVisibility: jest.fn(),
|
||||||
|
setAlwaysOnTop: jest.fn(),
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
jest.mock('../src/common/env', () => {
|
||||||
|
return {
|
||||||
|
isWindowsOS: true,
|
||||||
|
isMac: false,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
jest.mock('../src/app/window-utils', () => {
|
||||||
|
return {
|
||||||
|
injectStyles: jest.fn(),
|
||||||
|
preventWindowNavigation: jest.fn(),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
jest.mock('../src/app/window-handler', () => {
|
||||||
|
return {
|
||||||
|
windowHandler: {
|
||||||
|
url: 'https://test.symphony.com',
|
||||||
|
getMainWindow: jest.fn(() => {
|
||||||
|
return getMainWindow;
|
||||||
|
}),
|
||||||
|
openUrlInDefaultBrowser: jest.fn(),
|
||||||
|
addWindow: jest.fn(),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
jest.mock('../src/app/window-actions', () => {
|
||||||
|
return {
|
||||||
|
monitorWindowActions: jest.fn(),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('child window handle', () => {
|
||||||
|
const frameName = { };
|
||||||
|
const disposition = 'new-window';
|
||||||
|
const newWinOptions = {
|
||||||
|
webPreferences: jest.fn(),
|
||||||
|
webContents: { ...ipcRenderer, ...getMainWindow, webContents: ipcRenderer},
|
||||||
|
};
|
||||||
|
|
||||||
|
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);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should call `did-finish-load` correctly on WindowOS', () => {
|
||||||
|
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', { isWindowsOS: true});
|
||||||
|
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).toBeCalledWith('invalid');
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user