mirror of
https://github.com/finos/SymphonyElectron.git
synced 2025-02-25 18:55:29 -06:00
Electron-47
1. Handled spellchecker issue for pop outs 2. Wrote spectron test for spellchecker
This commit is contained in:
parent
249021046a
commit
1ef82d2204
@ -18,7 +18,21 @@ const apiEnums = require('../enums/api.js');
|
|||||||
const apiCmds = apiEnums.cmds;
|
const apiCmds = apiEnums.cmds;
|
||||||
const apiName = apiEnums.apiName;
|
const apiName = apiEnums.apiName;
|
||||||
const getMediaSources = require('../desktopCapturer/getSources');
|
const getMediaSources = require('../desktopCapturer/getSources');
|
||||||
const SpellCheckerHelper = require('../spellChecker/spellChecker').SpellCheckHelper;
|
|
||||||
|
// bug in electron preventing us from using spellchecker in pop outs
|
||||||
|
// https://github.com/electron/electron/issues/4025
|
||||||
|
// so loading the spellchecker in try catch so that we don't
|
||||||
|
// block other method from loading
|
||||||
|
try {
|
||||||
|
const SpellCheckerHelper = require('../spellChecker/spellChecker').SpellCheckHelper;
|
||||||
|
// Method to initialize spell checker
|
||||||
|
const spellChecker = new SpellCheckerHelper();
|
||||||
|
spellChecker.initializeSpellChecker();
|
||||||
|
} catch (err){
|
||||||
|
/* eslint-disable no-console */
|
||||||
|
console.error('requiring spellchecker module: ' + err);
|
||||||
|
/* eslint-enable no-console */
|
||||||
|
}
|
||||||
|
|
||||||
require('../downloadManager/downloadManager');
|
require('../downloadManager/downloadManager');
|
||||||
|
|
||||||
@ -329,8 +343,4 @@ function createAPI() {
|
|||||||
window.addEventListener('online', updateOnlineStatus, false);
|
window.addEventListener('online', updateOnlineStatus, false);
|
||||||
|
|
||||||
updateOnlineStatus();
|
updateOnlineStatus();
|
||||||
|
|
||||||
// Method to initialize spell checker
|
|
||||||
const spellChecker = new SpellCheckerHelper();
|
|
||||||
spellChecker.initializeSpellChecker();
|
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
const { remote } = require('electron');
|
||||||
|
const { MenuItem } = remote;
|
||||||
const { SpellCheckHandler, ContextMenuListener, ContextMenuBuilder } = require('electron-spellchecker');
|
const { SpellCheckHandler, ContextMenuListener, ContextMenuBuilder } = require('electron-spellchecker');
|
||||||
|
|
||||||
class SpellCheckHelper {
|
class SpellCheckHelper {
|
||||||
@ -7,17 +9,37 @@ class SpellCheckHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To initialize for a specific window
|
* Method to initialize spell checker
|
||||||
*/
|
*/
|
||||||
initializeSpellChecker() {
|
initializeSpellChecker() {
|
||||||
this.spellCheckHandler.attachToInput();
|
this.spellCheckHandler.attachToInput();
|
||||||
|
|
||||||
const contextMenuBuilder = new ContextMenuBuilder(this.spellCheckHandler);
|
const contextMenuBuilder = new ContextMenuBuilder(this.spellCheckHandler, null, false, SpellCheckHelper.processMenu);
|
||||||
this.contextMenuListener = new ContextMenuListener((info) => {
|
this.contextMenuListener = new ContextMenuListener((info) => {
|
||||||
contextMenuBuilder.showPopupMenu(info);
|
contextMenuBuilder.showPopupMenu(info);
|
||||||
}, null, null);
|
}, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to add default menu items to the
|
||||||
|
* menu that was generated by ContextMenuBuilder
|
||||||
|
*
|
||||||
|
* This method will be invoked by electron-spellchecker
|
||||||
|
* before showing the context menu
|
||||||
|
*
|
||||||
|
* @param menu
|
||||||
|
* @returns menu
|
||||||
|
*/
|
||||||
|
static processMenu(menu) {
|
||||||
|
menu.append(new MenuItem({ type: 'separator' }));
|
||||||
|
menu.append(new MenuItem({
|
||||||
|
role: 'reload',
|
||||||
|
accelerator: 'CmdOrCtrl+R',
|
||||||
|
label: 'Reload'
|
||||||
|
}));
|
||||||
|
return menu;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
120
tests/spectron/spellChecker.spectron.js
Normal file
120
tests/spectron/spellChecker.spectron.js
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
const Application = require('./spectronSetup');
|
||||||
|
const path = require('path');
|
||||||
|
const {isMac} = require('../../js/utils/misc.js');
|
||||||
|
const childProcess = require('child_process');
|
||||||
|
let app = new Application({});
|
||||||
|
let robot;
|
||||||
|
|
||||||
|
describe('Tests for spellChecker', () => {
|
||||||
|
|
||||||
|
let originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
|
||||||
|
jasmine.DEFAULT_TIMEOUT_INTERVAL = Application.getTimeOut();
|
||||||
|
|
||||||
|
beforeAll((done) => {
|
||||||
|
childProcess.exec(`npm rebuild robotjs --target=${process.version} --build-from-source`, function () {
|
||||||
|
robot = require('robotjs');
|
||||||
|
app.startApplication().then((startedApp) => {
|
||||||
|
app = startedApp;
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
afterAll((done) => {
|
||||||
|
if (app && app.isRunning()) {
|
||||||
|
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
|
||||||
|
app.stop().then(() => {
|
||||||
|
done();
|
||||||
|
}).catch((err) => {
|
||||||
|
console.log(err);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should launch the app', (done) => {
|
||||||
|
return app.client.waitUntilWindowLoaded().then(() => {
|
||||||
|
return app.client.getWindowCount().then((count) => {
|
||||||
|
expect(count === 1).toBeTruthy();
|
||||||
|
done();
|
||||||
|
}).catch((err) => {
|
||||||
|
expect(err).toBeFalsy();
|
||||||
|
});
|
||||||
|
}).catch((err) => {
|
||||||
|
expect(err).toBeFalsy();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should check window count', () => {
|
||||||
|
return app.client.url('file:///' + path.join(__dirname, '..', '..', 'demo/index.html'));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set the misspelled word', () => {
|
||||||
|
return app.client
|
||||||
|
.windowByIndex(0)
|
||||||
|
.setValue('#tag', 'comming ')
|
||||||
|
.getValue('#tag').then((value) => {
|
||||||
|
expect(value === 'comming ').toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should bring the app to front in windows', (done) => {
|
||||||
|
if (!isMac) {
|
||||||
|
app.browserWindow.focus();
|
||||||
|
app.browserWindow.restore();
|
||||||
|
app.browserWindow.getBounds().then((bounds) => {
|
||||||
|
robot.setMouseDelay(100);
|
||||||
|
let x = bounds.x + 200;
|
||||||
|
let y = bounds.y + 200;
|
||||||
|
robot.moveMouseSmooth(x, y);
|
||||||
|
robot.mouseClick();
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should invoke context menu ', (done) => {
|
||||||
|
if (isMac) {
|
||||||
|
app.browserWindow.getBounds().then((bounds) => {
|
||||||
|
let x = bounds.x + 45;
|
||||||
|
let y = bounds.y + 398;
|
||||||
|
|
||||||
|
robot.moveMouseSmooth(x, y);
|
||||||
|
robot.setMouseDelay(200);
|
||||||
|
robot.mouseClick('left', true);
|
||||||
|
robot.mouseClick('right');
|
||||||
|
robot.setKeyboardDelay(500);
|
||||||
|
robot.keyTap('down');
|
||||||
|
robot.keyTap('down');
|
||||||
|
robot.keyTap('enter');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
app.browserWindow.getBounds().then((bounds) => {
|
||||||
|
let x = bounds.x + 55;
|
||||||
|
let y = bounds.y + 430;
|
||||||
|
|
||||||
|
robot.moveMouseSmooth(x, y);
|
||||||
|
robot.setMouseDelay(200);
|
||||||
|
robot.mouseClick('left', true);
|
||||||
|
robot.mouseClick('right');
|
||||||
|
robot.setKeyboardDelay(500);
|
||||||
|
robot.keyTap('down');
|
||||||
|
robot.keyTap('down');
|
||||||
|
robot.keyTap('enter');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should verify the text field', () => {
|
||||||
|
return app.client
|
||||||
|
.windowByIndex(0)
|
||||||
|
.getValue('#tag').then((value) => {
|
||||||
|
expect(value).toBe('coming ');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user