diff --git a/config/Symphony.config b/config/Symphony.config index 4dc37407..c6d4439d 100644 --- a/config/Symphony.config +++ b/config/Symphony.config @@ -3,7 +3,6 @@ "minimizeOnClose" : false, "launchOnStartup" : true, "alwaysOnTop" : false, - "launchOnStartup" : true, "notificationSettings": { "position": "upper-right", "display": "" diff --git a/package.json b/package.json index 8bdfa2c4..1f01b039 100644 --- a/package.json +++ b/package.json @@ -15,9 +15,8 @@ "prebuild": "npm run rebuild && npm run browserify-preload", "browserify-preload": "browserify -o js/preload/_preloadMain.js -x electron --insert-global-vars=__filename,__dirname js/preload/preloadMain.js", "rebuild": "electron-rebuild -f", - "test": "npm run lint && npm run copy-config && jest --verbose --testPathPattern test --runInBand", + "test": "npm run lint && jest --verbose --testPathPattern test --runInBand", "lint": "eslint --ext .js js/", - "copy-config": "ncp 'config' 'node_modules/electron/dist/Electron.app/Contents/config'", "rename-exe": "cd dist/win-unpacked && ren Symphony.exe Symphony-Electron.exe" }, "jest": { @@ -81,6 +80,7 @@ "eslint-plugin-react": "^6.10.0", "jest": "^19.0.2", "ncp": "^2.0.0", + "robotjs": "^0.4.7", "spectron": "^3.7.2" }, "dependencies": { diff --git a/tests/alwaysOnTop.test.js b/tests/alwaysOnTop.test.js index a283d69b..f843529f 100644 --- a/tests/alwaysOnTop.test.js +++ b/tests/alwaysOnTop.test.js @@ -1,5 +1,11 @@ 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; +let mIsAlwaysOnTop; describe('Tests for Always on top', () => { @@ -7,22 +13,49 @@ 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(); + }); }); }); + 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(); + }); }); } }); @@ -32,8 +65,6 @@ describe('Tests for Always on top', () => { return app.client.getWindowCount().then((count) => { expect(count === 1).toBeTruthy(); done(); - }).catch((err) => { - expect(err).toBeNull(); }); }).catch((err) => { expect(err).toBeNull(); @@ -56,24 +87,100 @@ describe('Tests for Always on top', () => { }); }); + it('should bring the app to front in windows', (done) => { + if (!isMac) { + app.browserWindow.focus(); + app.browserWindow.restore(); + app.browserWindow.setAlwaysOnTop(true).then(() => { + app.browserWindow.isAlwaysOnTop().then((isOnTop) => { + app.browserWindow.getBounds().then((bounds) => { + robot.setMouseDelay(200); + app.browserWindow.restore().then(() => { + let x = bounds.x + 95; + let y = bounds.y + 35; + + robot.moveMouseSmooth(x, y); + robot.mouseClick(); + robot.setKeyboardDelay(200); + for (let i = 0; i < 4 + ; i++) { + robot.keyTap('down'); + } + robot.keyTap('enter'); + expect(isOnTop).toBeTruthy(); + done(); + }) + }); + }); + }).catch((err) => { + expect(err).toBeNull(); + }); + } else { + done(); + } + }); + it('should check is always on top', () => { - return app.browserWindow.isAlwaysOnTop().then((isAlwaysOnTop) => { - expect(isAlwaysOnTop).toBeFalsy(); + return Application.readConfig(configPath).then((userData) => { + return app.browserWindow.isAlwaysOnTop().then((isAlwaysOnTop) => { + mIsAlwaysOnTop = isAlwaysOnTop; + if (userData.alwaysOnTop) { + expect(isAlwaysOnTop).toBeTruthy(); + } else { + expect(isAlwaysOnTop).toBeFalsy(); + } + }); }).catch((err) => { expect(err).toBeNull(); }); }); - 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'); + done(); + } else { + app.browserWindow.getBounds().then((bounds) => { + app.browserWindow.focus(); + robot.setMouseDelay(200); + app.browserWindow.restore().then(() => { + let x = bounds.x + 95; + let y = bounds.y + 35; + + robot.moveMouseSmooth(x, y); + robot.mouseClick(); + for (let i = 0; i < 4; i++) { + robot.keyTap('down'); + } + robot.keyTap('enter'); + done(); + }); + }).catch((err) => { + expect(err).toBeNull(); + }); + } }); it('should check is always on top to be true', () => { - return app.browserWindow.isAlwaysOnTop().then((isAlwaysOnTop) => { - expect(isAlwaysOnTop).toBeTruthy(); - }).catch((err) => { - expect(err).toBeNull(); - }); + if (!mIsAlwaysOnTop) { + 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(); + }); + } }); -}); \ No newline at end of file +}); diff --git a/tests/spectron/spectronSetup.js b/tests/spectron/spectronSetup.js index 4c6401b2..9b6af505 100644 --- a/tests/spectron/spectronSetup.js +++ b/tests/spectron/spectronSetup.js @@ -1,5 +1,8 @@ const Application = require('spectron').Application; const path = require('path'); +const fs = require('fs'); +const {isMac} = require('../../js/utils/misc'); +const ncp = require('ncp').ncp; class App { @@ -12,6 +15,8 @@ class App { this.options.args = [path.join(__dirname, '..', '..', 'js/main.js')]; } + App.copyConfigPath(); + this.app = new Application(this.options); } @@ -35,6 +40,33 @@ 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)); + }); + }); + } + + static copyConfigPath() { + if (isMac) { + ncp('config', 'node_modules/electron/dist/Electron.app/Contents/config', function (err) { + if (err) { + throw(err); + } + }); + } else { + ncp('config', 'node_modules/electron/dist/config', function (err) { + if (err) { + throw(err); + } + }); + } + } + } module.exports = App; \ No newline at end of file