Electron-90

1. Spectron tests for notification position
2. Added Spectron
This commit is contained in:
Kiran Niranjan 2017-07-02 21:52:10 +05:30 committed by Kiran Niranjan
parent a4b79ac998
commit c99681e53a
3 changed files with 172 additions and 1 deletions

View File

@ -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",

44
spectron/app.js Normal file
View File

@ -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;

View File

@ -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)
});
});