From c99681e53a712352ee87da3dc2ae2276a1c1471e Mon Sep 17 00:00:00 2001 From: Kiran Niranjan Date: Sun, 2 Jul 2017 21:52:10 +0530 Subject: [PATCH 1/5] Electron-90 1. Spectron tests for notification position 2. Added Spectron --- package.json | 6 +- spectron/app.js | 44 ++++++++ spectron/test/notificationPosition-test.js | 123 +++++++++++++++++++++ 3 files changed, 172 insertions(+), 1 deletion(-) create mode 100644 spectron/app.js create mode 100644 spectron/test/notificationPosition-test.js diff --git a/package.json b/package.json index 77c57629..5d0048c7 100644 --- a/package.json +++ b/package.json @@ -78,7 +78,11 @@ "eslint-plugin-import": "^2.2.0", "eslint-plugin-jsx-a11y": "^4.0.0", "eslint-plugin-react": "^6.10.0", - "jest": "^19.0.2" + "jest": "^19.0.2", + "chai-roughly": "^1.0.0", + "chai-as-promised": "^7.0.0", + "chai": "^4.0.2", + "spectron": "^3.7.2" }, "dependencies": { "@paulcbetts/system-idle-time": "^1.0.4", diff --git a/spectron/app.js b/spectron/app.js new file mode 100644 index 00000000..350f74d0 --- /dev/null +++ b/spectron/app.js @@ -0,0 +1,44 @@ +const Application = require('spectron').Application; +const path = require('path'); +const chai = require('chai'); +const chaiAsPromised = require('chai-as-promised'); +const chaiRoughly = require('chai-roughly'); + +global.before(function () { + chai.should(); + chai.use(chaiAsPromised); + chai.use(chaiRoughly); +}); + +class App { + + constructor(options) { + + this.options = options; + + if (!this.options.path){ + this.options.path = App.getAppPath(); + this.options.args = [path.join(__dirname, '..', 'js/main.js')]; + } + + this.app = new Application(this.options); + } + + startApplication() { + return this.app.start().then(() => { + chaiAsPromised.transferPromiseness = this.app.transferPromiseness; + return this.app + }); + } + + static getAppPath() { + let electronPath = path.join(__dirname, '..', 'node_modules', '.bin', 'electron'); + if (process.platform === 'win32') { + electronPath += '.cmd'; + } + return electronPath + } + +} + +module.exports = App; \ No newline at end of file diff --git a/spectron/test/notificationPosition-test.js b/spectron/test/notificationPosition-test.js new file mode 100644 index 00000000..001690ef --- /dev/null +++ b/spectron/test/notificationPosition-test.js @@ -0,0 +1,123 @@ +const Application = require('../app'); +const assert = require('assert'); +const path = require('path'); + +describe('Tests for Notification position', () => { + + let app; + + before(() => { + app = new Application({}); + }); + + after(() => { + if (app && app.isRunning()) { + return app.stop(); + } + }); + + it('should launch the app', () => { + return app.startApplication().then((startedApp) => { + app = startedApp; + app.client.waitUntilWindowLoaded() + .getWindowCount().should.eventually.equal(1); + }); + }); + + it('should load demo html page', () => { + let filePath; + if (process.platform === 'win32') { + filePath = 'file:///' + path.join(__dirname, '..', '..', 'demo/index.html'); + } else { + filePath = 'file://$(pwd)/' + path.join(__dirname, '..', '..', 'demo/index.html') + } + return app.client.url(filePath); + }); + + it('should load demo html', () => { + return app.client.waitUntilWindowLoaded() + .getTitle().should.eventually.equal('') + }); + + it('should notification configure window', () => { + return app.client + .click('#open-config-win') + .windowByIndex(1) + .click('#upper-left') + .click('#ok-button') + .windowByIndex(0) + .click('#notf') + .windowByIndex(1) + }); + + it('should check notification position', () => { + return app.browserWindow + .getBounds().then((bounds) => { + bounds.x.should.be.equal(0); + bounds.y.should.be.above(0); + }); + }); + + it('should change the window', () => { + return app.client.windowByIndex(0); + }); + + it('should change notification position to lower-right', () => { + return app.client + .click('#open-config-win') + .windowByIndex(2) + .click('#lower-right') + .click('#ok-button') + .windowByIndex(0) + .click('#notf') + .windowByIndex(1) + }); + + it('should check notification position and equal to lower-right', () => { + return app.browserWindow + .getBounds().then((bounds) => { + bounds.x.should.be.above(0); + bounds.y.should.be.above(0); + }); + }); + + it('should change the window', () => { + return app.client.windowByIndex(0); + }); + + it('should change notification position to upper-right', () => { + return app.client + .click('#open-config-win') + .windowByIndex(2) + .click('#upper-right') + .click('#ok-button') + .windowByIndex(0) + .click('#notf') + .windowByIndex(1) + }); + + it('should check notification position and equal to upper-right', () => { + return app.browserWindow + .getBounds().then((bounds) => { + bounds.x.should.be.above(0); + bounds.y.should.be.above(0); + }); + }); + + it('should close the notification', () => { + return app.client + .windowByIndex(0) + }); + + it('should open notification', () => { + return app.client + .windowByIndex(0) + .click('#notf') + .getWindowCount().should.eventually.equal(3) + .windowByIndex(1) + .click('#close') + .getWindowCount().should.eventually.equal(3) + .windowByIndex(0) + }); + +}); \ No newline at end of file From 83ab55e95de193aee1b96b332158cf4419f95dd2 Mon Sep 17 00:00:00 2001 From: Kiran Niranjan Date: Sun, 2 Jul 2017 21:55:06 +0530 Subject: [PATCH 2/5] Electron-90 1. Spectron tests for notification position 2. Added Spectron --- spectron/{test => tests}/notificationPosition-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename spectron/{test => tests}/notificationPosition-test.js (98%) diff --git a/spectron/test/notificationPosition-test.js b/spectron/tests/notificationPosition-test.js similarity index 98% rename from spectron/test/notificationPosition-test.js rename to spectron/tests/notificationPosition-test.js index 001690ef..8c51307d 100644 --- a/spectron/test/notificationPosition-test.js +++ b/spectron/tests/notificationPosition-test.js @@ -109,7 +109,7 @@ describe('Tests for Notification position', () => { .windowByIndex(0) }); - it('should open notification', () => { + it('should open notification and close', () => { return app.client .windowByIndex(0) .click('#notf') From 067d3417307b70737a663bcc7a09a485c8c1bc17 Mon Sep 17 00:00:00 2001 From: Kiran Niranjan Date: Tue, 4 Jul 2017 11:31:03 +0530 Subject: [PATCH 3/5] Electron-90 updated some test cases --- spectron/tests/notificationPosition-test.js | 30 ++++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/spectron/tests/notificationPosition-test.js b/spectron/tests/notificationPosition-test.js index 8c51307d..324358cd 100644 --- a/spectron/tests/notificationPosition-test.js +++ b/spectron/tests/notificationPosition-test.js @@ -59,7 +59,9 @@ describe('Tests for Notification position', () => { }); it('should change the window', () => { - return app.client.windowByIndex(0); + return app.client.windowByIndex(0).then(() => { + return app.browserWindow.getTitle().should.eventually.equal('Symphony | Secure Seamless Communication') + }); }); it('should change notification position to lower-right', () => { @@ -70,7 +72,9 @@ describe('Tests for Notification position', () => { .click('#ok-button') .windowByIndex(0) .click('#notf') - .windowByIndex(1) + .windowByIndex(1).then(() => { + return app.browserWindow.getTitle().should.eventually.equal('Electron') + }); }); it('should check notification position and equal to lower-right', () => { @@ -82,7 +86,10 @@ describe('Tests for Notification position', () => { }); it('should change the window', () => { - return app.client.windowByIndex(0); + return app.client + .windowByIndex(0).then(() => { + return app.browserWindow.getTitle().should.eventually.equal('Symphony | Secure Seamless Communication') + }); }); it('should change notification position to upper-right', () => { @@ -93,7 +100,9 @@ describe('Tests for Notification position', () => { .click('#ok-button') .windowByIndex(0) .click('#notf') - .windowByIndex(1) + .windowByIndex(1).then(() => { + return app.browserWindow.getTitle().should.eventually.equal('Electron') + }); }); it('should check notification position and equal to upper-right', () => { @@ -104,9 +113,11 @@ describe('Tests for Notification position', () => { }); }); - it('should close the notification', () => { + it('should change the window to main', () => { return app.client - .windowByIndex(0) + .windowByIndex(0).then(() => { + return app.browserWindow.getTitle().should.eventually.equal('Symphony | Secure Seamless Communication') + }); }); it('should open notification and close', () => { @@ -114,10 +125,9 @@ describe('Tests for Notification position', () => { .windowByIndex(0) .click('#notf') .getWindowCount().should.eventually.equal(3) - .windowByIndex(1) - .click('#close') - .getWindowCount().should.eventually.equal(3) - .windowByIndex(0) + .windowByIndex(1).then(() => { + return app.browserWindow.getTitle().should.eventually.equal('Electron') + }); }); }); \ No newline at end of file From 9ee4b76d372f89c5ade948cd541632f12eaec614 Mon Sep 17 00:00:00 2001 From: Kiran Niranjan Date: Wed, 5 Jul 2017 14:03:52 +0530 Subject: [PATCH 4/5] Electron-90 Moved the Notification test to Jest from mocha --- package.json | 3 - spectron/tests/notificationPosition-test.js | 133 ------------------ tests/notificationPosition.test.js | 143 ++++++++++++++++++++ spectron/app.js => tests/spectronSetup.js | 10 -- 4 files changed, 143 insertions(+), 146 deletions(-) delete mode 100644 spectron/tests/notificationPosition-test.js create mode 100644 tests/notificationPosition.test.js rename spectron/app.js => tests/spectronSetup.js (68%) diff --git a/package.json b/package.json index 5d0048c7..b1ec3e98 100644 --- a/package.json +++ b/package.json @@ -79,9 +79,6 @@ "eslint-plugin-jsx-a11y": "^4.0.0", "eslint-plugin-react": "^6.10.0", "jest": "^19.0.2", - "chai-roughly": "^1.0.0", - "chai-as-promised": "^7.0.0", - "chai": "^4.0.2", "spectron": "^3.7.2" }, "dependencies": { diff --git a/spectron/tests/notificationPosition-test.js b/spectron/tests/notificationPosition-test.js deleted file mode 100644 index 324358cd..00000000 --- a/spectron/tests/notificationPosition-test.js +++ /dev/null @@ -1,133 +0,0 @@ -const Application = require('../app'); -const assert = require('assert'); -const path = require('path'); - -describe('Tests for Notification position', () => { - - let app; - - before(() => { - app = new Application({}); - }); - - after(() => { - if (app && app.isRunning()) { - return app.stop(); - } - }); - - it('should launch the app', () => { - return app.startApplication().then((startedApp) => { - app = startedApp; - app.client.waitUntilWindowLoaded() - .getWindowCount().should.eventually.equal(1); - }); - }); - - it('should load demo html page', () => { - let filePath; - if (process.platform === 'win32') { - filePath = 'file:///' + path.join(__dirname, '..', '..', 'demo/index.html'); - } else { - filePath = 'file://$(pwd)/' + path.join(__dirname, '..', '..', 'demo/index.html') - } - return app.client.url(filePath); - }); - - it('should load demo html', () => { - return app.client.waitUntilWindowLoaded() - .getTitle().should.eventually.equal('') - }); - - it('should notification configure window', () => { - return app.client - .click('#open-config-win') - .windowByIndex(1) - .click('#upper-left') - .click('#ok-button') - .windowByIndex(0) - .click('#notf') - .windowByIndex(1) - }); - - it('should check notification position', () => { - return app.browserWindow - .getBounds().then((bounds) => { - bounds.x.should.be.equal(0); - bounds.y.should.be.above(0); - }); - }); - - it('should change the window', () => { - return app.client.windowByIndex(0).then(() => { - return app.browserWindow.getTitle().should.eventually.equal('Symphony | Secure Seamless Communication') - }); - }); - - it('should change notification position to lower-right', () => { - return app.client - .click('#open-config-win') - .windowByIndex(2) - .click('#lower-right') - .click('#ok-button') - .windowByIndex(0) - .click('#notf') - .windowByIndex(1).then(() => { - return app.browserWindow.getTitle().should.eventually.equal('Electron') - }); - }); - - it('should check notification position and equal to lower-right', () => { - return app.browserWindow - .getBounds().then((bounds) => { - bounds.x.should.be.above(0); - bounds.y.should.be.above(0); - }); - }); - - it('should change the window', () => { - return app.client - .windowByIndex(0).then(() => { - return app.browserWindow.getTitle().should.eventually.equal('Symphony | Secure Seamless Communication') - }); - }); - - it('should change notification position to upper-right', () => { - return app.client - .click('#open-config-win') - .windowByIndex(2) - .click('#upper-right') - .click('#ok-button') - .windowByIndex(0) - .click('#notf') - .windowByIndex(1).then(() => { - return app.browserWindow.getTitle().should.eventually.equal('Electron') - }); - }); - - it('should check notification position and equal to upper-right', () => { - return app.browserWindow - .getBounds().then((bounds) => { - bounds.x.should.be.above(0); - bounds.y.should.be.above(0); - }); - }); - - it('should change the window to main', () => { - return app.client - .windowByIndex(0).then(() => { - return app.browserWindow.getTitle().should.eventually.equal('Symphony | Secure Seamless Communication') - }); - }); - - it('should open notification and close', () => { - return app.client - .windowByIndex(0) - .click('#notf') - .getWindowCount().should.eventually.equal(3) - .windowByIndex(1).then(() => { - return app.browserWindow.getTitle().should.eventually.equal('Electron') - }); - }); - -}); \ No newline at end of file diff --git a/tests/notificationPosition.test.js b/tests/notificationPosition.test.js new file mode 100644 index 00000000..9dedb6b1 --- /dev/null +++ b/tests/notificationPosition.test.js @@ -0,0 +1,143 @@ +const Application = require('./spectronSetup'); +const path = require('path'); + +describe('Tests for Notification position', () => { + + let originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL; + jasmine.DEFAULT_TIMEOUT_INTERVAL = 60000; + + let app; + + beforeAll(() => { + app = new Application({}); + }); + + afterAll(() => { + if (app && app.isRunning()) { + jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout; + return app.stop(); + } + }); + + it('should launch the app', () => { + return app.startApplication().then((startedApp) => { + app = startedApp; + return app.client.waitUntilWindowLoaded().then(async () => { + const count = await app.client.getWindowCount(); + expect(count === 1).toBeTruthy(); + }) + }); + }); + + it('should load demo html page', () => { + let filePath; + if (process.platform === 'win32') { + filePath = 'file:///' + path.join(__dirname, '..', 'demo/index.html'); + } else { + filePath = 'file://$(pwd)/' + path.join(__dirname, '..', 'demo/index.html') + } + return app.client.url(filePath); + }); + + it('should load demo html', async () => { + return app.client.waitUntilWindowLoaded().then(async () => { + const title = await app.client.getTitle(); + expect(title === '').toBeTruthy(); + }); + }); + + it('should notification configure window', () => { + return app.client + .click('#open-config-win') + .windowByIndex(1) + .click('#upper-left') + .click('#ok-button') + .windowByIndex(0) + .click('#notf') + .windowByIndex(1) + }); + + it('should check notification position', async () => { + const bounds = await app.browserWindow.getBounds(); + expect(bounds.x === 0).toBeTruthy(); + expect(bounds.y > 0).toBeTruthy(); + }); + + it('should change the window', () => { + return app.client.windowByIndex(0).then(async () => { + const title = await app.browserWindow.getTitle(); + expect(title === 'Symphony | Secure Seamless Communication').toBeTruthy(); + }); + }); + + it('should change notification position to lower-right', () => { + return app.client + .click('#open-config-win') + .windowByIndex(2) + .click('#lower-right') + .click('#ok-button') + .windowByIndex(0) + .click('#notf') + .windowByIndex(1).then(async () => { + const title = await app.browserWindow.getTitle(); + expect(title === 'Electron').toBeTruthy(); + }); + }); + + it('should check notification position and equal to lower-right', async () => { + const bounds = await app.browserWindow.getBounds(); + expect(bounds.x > 0).toBeTruthy(); + expect(bounds.y > 0).toBeTruthy(); + }); + + it('should change the window', () => { + return app.client + .windowByIndex(0).then(async () => { + const title = await app.browserWindow.getTitle(); + expect(title === 'Symphony | Secure Seamless Communication').toBeTruthy(); + }); + }); + + it('should change notification position to upper-right', () => { + return app.client + .click('#open-config-win') + .windowByIndex(2) + .click('#upper-right') + .click('#ok-button') + .windowByIndex(0) + .click('#notf') + .windowByIndex(1).then(async () => { + const title = await app.browserWindow.getTitle(); + expect(title === 'Electron').toBeTruthy(); + }); + }); + + it('should check notification position and equal to upper-right', async () => { + const bounds = await app.browserWindow.getBounds(); + expect(bounds.x > 0).toBeTruthy(); + expect(bounds.y > 0).toBeTruthy(); + }); + + it('should change the window to main', () => { + return app.client + .windowByIndex(0).then(async () => { + const title = await app.browserWindow.getTitle(); + expect(title === 'Symphony | Secure Seamless Communication').toBeTruthy(); + }); + }); + + it('should open notification and close', () => { + return app.client + .windowByIndex(0) + .click('#notf') + .getWindowCount().then((count) => { + expect(count === 3).toBeTruthy(); + }) + .windowByIndex(1).then(() => { + return app.browserWindow.getTitle().then((title) => { + expect(title === 'Electron').toBeTruthy(); + }); + }); + }); + +}); \ No newline at end of file diff --git a/spectron/app.js b/tests/spectronSetup.js similarity index 68% rename from spectron/app.js rename to tests/spectronSetup.js index 350f74d0..74729cfc 100644 --- a/spectron/app.js +++ b/tests/spectronSetup.js @@ -1,14 +1,5 @@ const Application = require('spectron').Application; const path = require('path'); -const chai = require('chai'); -const chaiAsPromised = require('chai-as-promised'); -const chaiRoughly = require('chai-roughly'); - -global.before(function () { - chai.should(); - chai.use(chaiAsPromised); - chai.use(chaiRoughly); -}); class App { @@ -26,7 +17,6 @@ class App { startApplication() { return this.app.start().then(() => { - chaiAsPromised.transferPromiseness = this.app.transferPromiseness; return this.app }); } From 0d592f2c221f931c6d538128707350c2f5b0f016 Mon Sep 17 00:00:00 2001 From: Kiran Niranjan Date: Wed, 5 Jul 2017 15:30:11 +0530 Subject: [PATCH 5/5] Electron-90 fixed a typo --- tests/notificationPosition.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/notificationPosition.test.js b/tests/notificationPosition.test.js index 9dedb6b1..c64e4706 100644 --- a/tests/notificationPosition.test.js +++ b/tests/notificationPosition.test.js @@ -46,7 +46,7 @@ describe('Tests for Notification position', () => { }); }); - it('should notification configure window', () => { + it('should open notification configure window', () => { return app.client .click('#open-config-win') .windowByIndex(1)