From de4b00c21fe8a882069235c57408ef2a3ee9f59f Mon Sep 17 00:00:00 2001 From: Kiran Niranjan Date: Mon, 19 Feb 2018 10:57:15 +0530 Subject: [PATCH] Electron-308 - Fixed and updated the Spectron test cases --- tests/spectron/alwaysOnTop.spectron.js | 2 +- tests/spectron/full-screen.spectron.js | 2 +- tests/spectron/spectronSetup.js | 48 +++++++++++++++++++------ tests/spectron/spellChecker.spectron.js | 6 ++-- 4 files changed, 42 insertions(+), 16 deletions(-) diff --git a/tests/spectron/alwaysOnTop.spectron.js b/tests/spectron/alwaysOnTop.spectron.js index d007fd56..46417db3 100644 --- a/tests/spectron/alwaysOnTop.spectron.js +++ b/tests/spectron/alwaysOnTop.spectron.js @@ -136,7 +136,7 @@ describe('Tests for Always on top', () => { robot.setMouseDelay(200); robot.moveMouse(190, 0); robot.mouseClick(); - for (let i = 0; i < 8; i++) { + for (let i = 0; i < 10; i++) { robot.keyTap('down'); } robot.keyTap('enter'); diff --git a/tests/spectron/full-screen.spectron.js b/tests/spectron/full-screen.spectron.js index dd432740..83d8cf2c 100644 --- a/tests/spectron/full-screen.spectron.js +++ b/tests/spectron/full-screen.spectron.js @@ -108,7 +108,7 @@ describe('Tests for Full screen', () => { robot.moveMouseSmooth(205, 10); robot.mouseClick(); robot.setKeyboardDelay(100); - for (let i = 0; i < 6; i++) { + for (let i = 0; i < 8; i++) { robot.keyTap('down'); } robot.keyTap('enter'); diff --git a/tests/spectron/spectronSetup.js b/tests/spectron/spectronSetup.js index 413a5817..e23c47d7 100644 --- a/tests/spectron/spectronSetup.js +++ b/tests/spectron/spectronSetup.js @@ -16,6 +16,7 @@ class App { } App.copyConfigPath(); + App.copyLibraryDir(); this.app = new Application(this.options); } @@ -40,27 +41,52 @@ class App { } static readConfig(configPath) { - return new Promise(function (resolve, reject) { - fs.readFile(configPath, function (err, data) { - if (err) { - reject(err); - } - resolve(JSON.parse(data)); + + if (!fs.existsSync(configPath)) { + return this.copyConfigPath(); + } else { + return new Promise(function (resolve) { + fs.readFile(configPath, 'utf-8', function (err, data) { + if (err) { + throw new Error("Unable to read user config file " + err); + } + resolve(JSON.parse(data)); + }); }); - }); + } } static copyConfigPath() { + return new Promise((resolve) => { + if (isMac) { + ncp('config', 'node_modules/electron/dist/Electron.app/Contents/config', function (err) { + if (err) { + throw new Error("Unable to copy config file to Electron dir " + err); + } + resolve(); + }); + } else { + ncp('config', 'node_modules/electron/dist/config', function (err) { + if (err) { + throw new Error("Unable to copy config file to Electron dir " + err); + } + resolve(); + }); + } + }) + } + + static copyLibraryDir() { if (isMac) { - ncp('config', 'node_modules/electron/dist/Electron.app/Contents/config', function (err) { + ncp('library', 'node_modules/electron/dist/Electron.app/Contents/library', function (err) { if (err) { - throw(err); + throw new Error("Unable to copy Swift search library dir " + err); } }); } else { - ncp('config', 'node_modules/electron/dist/config', function (err) { + ncp('library', 'node_modules/electron/dist/library', function (err) { if (err) { - throw(err); + throw new Error("Unable to copy Swift search library dir " + err); } }); } diff --git a/tests/spectron/spellChecker.spectron.js b/tests/spectron/spellChecker.spectron.js index 129658fa..1975b1da 100644 --- a/tests/spectron/spellChecker.spectron.js +++ b/tests/spectron/spellChecker.spectron.js @@ -79,8 +79,8 @@ describe('Tests for spellChecker', () => { it('should invoke context menu ', (done) => { if (isMac) { app.browserWindow.getBounds().then((bounds) => { - let x = bounds.x + 45; - let y = bounds.y + 398; + let x = bounds.x + 55; + let y = bounds.y + 430; robot.moveMouseSmooth(x, y); robot.setMouseDelay(200); @@ -114,7 +114,7 @@ describe('Tests for spellChecker', () => { return app.client .windowByIndex(0) .getValue('#tag').then((value) => { - expect(value).toBe('coming '); + expect(value !== 'comming').toBeTruthy(); }); });