SymphonyElectron/spec/__mocks__/electron.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

202 lines
5.0 KiB
TypeScript

import { EventEmitter } from 'events';
import * as path from 'path';
import { isWindowsOS } from '../../src/common/env';
const ipcEmitter = new EventEmitter();
const mockIdleTime: number = 15;
const appName: string = 'Symphony';
const executableName: string = '/Symphony.exe';
const isReady: boolean = true;
const version: string = '4.0.0';
interface IApp {
commandLine: any;
getAppPath(): string;
getPath(type: string): string;
getName(): string;
isReady(): boolean;
getVersion(): string;
on(eventName: any, cb: any): void;
once(eventName: any, cb: any): void;
setPath(value: string, path: string): void;
setLoginItemSettings(settings: { openAtLogin: boolean, path: string }): void;
getLoginItemSettings(options?: { path: string, args: string[] }): ILoginItemSettings;
setAppLogsPath(): void;
}
interface ILoginItemSettings {
openAtLogin: boolean;
}
interface IIpcMain {
on(event: any, cb: any): void;
send(event: any, cb: any): void;
}
interface IIpcRenderer {
sendSync(event: any, cb: any): any;
on(eventName: any, cb: any): void;
send(event: any, ...cb: any[]): void;
removeListener(eventName: any, cb: any): void;
once(eventName: any, cb: any): void;
}
interface IPowerMonitor {
getSystemIdleTime(): void;
}
const pathToConfigDir = (): string => {
if (isWindowsOS) {
return path.join(__dirname, '/../..') as string;
} else {
return path.join(__dirname, '/..') as string;
}
};
// electron app mock...
export const app: IApp = {
getAppPath: pathToConfigDir,
getPath: (type) => {
if (type === 'exe') {
return path.join(pathToConfigDir(), executableName);
}
if (type === 'userData') {
return path.join(pathToConfigDir(), '/../config');
}
return pathToConfigDir();
},
getName: () => appName,
isReady: () => isReady,
getVersion: () => version,
on: (event, cb) => {
ipcEmitter.on(event, cb);
},
setPath: () => jest.fn(),
commandLine: {
appendSwitch: jest.fn(),
},
once: (eventName, cb) => {
ipcEmitter.on(eventName, cb);
},
setLoginItemSettings: () => jest.fn(),
getLoginItemSettings: (): ILoginItemSettings => {
return { openAtLogin: true };
},
setAppLogsPath: (): void => {
return;
},
};
// simple ipc mocks for render and main process ipc using
// nodes' EventEmitter
export const ipcMain: IIpcMain = {
on: (event, cb) => {
ipcEmitter.on(event, cb);
},
send: (event, args) => {
const senderEvent = {
sender: {
send: (eventSend, arg) => {
ipcEmitter.emit(eventSend, arg);
},
},
};
ipcEmitter.emit(event, senderEvent, args);
},
};
export const powerMonitor: IPowerMonitor = {
getSystemIdleTime: jest.fn().mockReturnValue(mockIdleTime),
};
export const ipcRenderer: IIpcRenderer = {
sendSync: (event, args) => {
const listeners = ipcEmitter.listeners(event);
if (listeners.length > 0) {
const listener = listeners[0];
const eventArg = {};
listener(eventArg, args);
return eventArg;
}
return null;
},
send: (event, ...args) => {
const senderEvent = {
sender: {
send: (eventSend, ...arg) => {
ipcEmitter.emit(eventSend, ...arg);
},
},
preventDefault: jest.fn(),
};
ipcEmitter.emit(event, senderEvent, ...args);
},
on: (eventName, cb) => {
ipcEmitter.on(eventName, cb);
},
removeListener: (eventName, cb) => {
ipcEmitter.removeListener(eventName, cb);
},
once: (eventName, cb) => {
ipcEmitter.on(eventName, cb);
},
};
export const shell = {
openExternal: jest.fn(),
};
// tslint:disable-next-line:variable-name
export const Menu = {
buildFromTemplate: jest.fn(),
setApplicationMenu: jest.fn(),
};
export const crashReporter = {
start: jest.fn(),
};
const getCurrentWindow = jest.fn(() => {
return {
isFullScreen: jest.fn(() => {
return false;
}),
isMaximized: jest.fn(() => {
return false;
}),
on: jest.fn(),
removeListener: jest.fn(),
isDestroyed: jest.fn(() => {
return false;
}),
close: jest.fn(),
maximize: jest.fn(),
minimize: jest.fn(),
unmaximize: jest.fn(),
setFullScreen: jest.fn(),
};
});
export const dialog = {
showMessageBox: jest.fn(),
showErrorBox: jest.fn(),
};
// tslint:disable-next-line:variable-name
export const BrowserWindow = {
getFocusedWindow: jest.fn(() => {
return {
isDestroyed: jest.fn(() => false),
};
}),
fromWebContents: (arg) => arg,
getAllWindows: jest.fn(() => []),
};
export const session = {
defaultSession: {
clearCache: jest.fn(),
},
};
export const remote = {
app,
getCurrentWindow,
};