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