mirror of
https://github.com/finos/SymphonyElectron.git
synced 2025-02-25 18:55:29 -06:00
Electron-93 - Implemented robotjs for always on top test
This commit is contained in:
parent
586b569864
commit
3c37591de9
@ -81,6 +81,7 @@
|
||||
"eslint-plugin-react": "^6.10.0",
|
||||
"jest": "^19.0.2",
|
||||
"ncp": "^2.0.0",
|
||||
"robotjs": "^0.4.7",
|
||||
"spectron": "^3.7.2"
|
||||
},
|
||||
"dependencies": {
|
||||
|
@ -1,5 +1,10 @@
|
||||
const Application = require('./spectron/spectronSetup');
|
||||
const {isMac} = require('../js/utils/misc.js');
|
||||
const childProcess = require('child_process');
|
||||
|
||||
let app = new Application({});
|
||||
let robot;
|
||||
let configPath;
|
||||
|
||||
describe('Tests for Always on top', () => {
|
||||
|
||||
@ -7,22 +12,51 @@ describe('Tests for Always on top', () => {
|
||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = Application.getTimeOut();
|
||||
|
||||
beforeAll((done) => {
|
||||
return app.startApplication().then((startedApp) => {
|
||||
app = startedApp;
|
||||
done();
|
||||
}).catch((err) => {
|
||||
expect(err).toBeNull();
|
||||
childProcess.exec(`npm rebuild robotjs --target=${process.version} --build-from-source`, function () {
|
||||
robot = require('robotjs');
|
||||
return app.startApplication().then((startedApp) => {
|
||||
app = startedApp;
|
||||
getConfigPath().then((config) => {
|
||||
configPath = config;
|
||||
done();
|
||||
}).catch((err) => {
|
||||
expect(err).toBeNull();
|
||||
});
|
||||
}).catch((err) => {
|
||||
expect(err).toBeNull();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function getConfigPath() {
|
||||
return new Promise(function (resolve, reject) {
|
||||
app.client.addCommand('getUserDataPath', function () {
|
||||
return this.execute(function () {
|
||||
return require('electron').remote.app.getPath('userData');
|
||||
})
|
||||
});
|
||||
app.client.getUserDataPath().then((path) => {
|
||||
resolve(path.value + '/Symphony.config')
|
||||
}).catch((err) => {
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
afterAll((done) => {
|
||||
if (app && app.isRunning()) {
|
||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
|
||||
app.stop().then(() => {
|
||||
done();
|
||||
childProcess.exec('npm run rebuild', function (err, stdout) {
|
||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
|
||||
done();
|
||||
});
|
||||
}).catch((err) => {
|
||||
console.log(err);
|
||||
done();
|
||||
childProcess.exec('npm run rebuild', function () {
|
||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
|
||||
expect(err).toBeNull();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
@ -64,16 +98,72 @@ describe('Tests for Always on top', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should change the always on top property', () => {
|
||||
return app.browserWindow.setAlwaysOnTop(true);
|
||||
it('should toggle the always on top property to true', (done) => {
|
||||
if (isMac) {
|
||||
robot.setMouseDelay(200);
|
||||
robot.moveMouse(190, 0);
|
||||
robot.mouseClick();
|
||||
for (let i = 0; i < 8; i++) {
|
||||
robot.keyTap('down');
|
||||
}
|
||||
robot.keyTap('enter');
|
||||
setTimeout(() => {
|
||||
done();
|
||||
}, 5000)
|
||||
}
|
||||
});
|
||||
|
||||
it('should check is always on top to be true', () => {
|
||||
return app.browserWindow.isAlwaysOnTop().then((isAlwaysOnTop) => {
|
||||
expect(isAlwaysOnTop).toBeTruthy();
|
||||
return Application.readConfig(configPath).then((userData) => {
|
||||
if (userData.alwaysOnTop) {
|
||||
return app.browserWindow.isAlwaysOnTop().then((isAlwaysOnTop) => {
|
||||
expect(isAlwaysOnTop).toBeTruthy();
|
||||
}).catch((err) => {
|
||||
expect(err).toBeNull();
|
||||
});
|
||||
} else {
|
||||
return app.browserWindow.isAlwaysOnTop().then((isAlwaysOnTop) => {
|
||||
expect(isAlwaysOnTop).toBeFalsy();
|
||||
}).catch((err) => {
|
||||
expect(err).toBeNull();
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('should toggle the always on top property to false', (done) => {
|
||||
if (isMac) {
|
||||
robot.setMouseDelay(200);
|
||||
robot.moveMouse(190, 0);
|
||||
robot.mouseClick();
|
||||
for (let i = 0; i < 8; i++) {
|
||||
robot.keyTap('down');
|
||||
}
|
||||
robot.keyTap('enter');
|
||||
setTimeout(() => {
|
||||
done();
|
||||
}, 5000);
|
||||
}
|
||||
});
|
||||
|
||||
it('should check is always on top to be true', () => {
|
||||
return Application.readConfig(configPath).then((userData) => {
|
||||
if (userData.alwaysOnTop) {
|
||||
return app.browserWindow.isAlwaysOnTop().then((isAlwaysOnTop) => {
|
||||
expect(isAlwaysOnTop).toBeTruthy();
|
||||
}).catch((err) => {
|
||||
expect(err).toBeNull();
|
||||
});
|
||||
} else {
|
||||
return app.browserWindow.isAlwaysOnTop().then((isAlwaysOnTop) => {
|
||||
expect(isAlwaysOnTop).toBeFalsy();
|
||||
}).catch((err) => {
|
||||
expect(err).toBeNull();
|
||||
});
|
||||
}
|
||||
}).catch((err) => {
|
||||
expect(err).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
@ -1,5 +1,6 @@
|
||||
const Application = require('spectron').Application;
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
class App {
|
||||
|
||||
@ -35,6 +36,17 @@ class App {
|
||||
return 90000
|
||||
}
|
||||
|
||||
static readConfig(configPath) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
fs.readFile(configPath, function (err, data) {
|
||||
if (err) {
|
||||
reject(err);
|
||||
}
|
||||
resolve(JSON.parse(data));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = App;
|
Loading…
Reference in New Issue
Block a user