Electron-90 Moved the Notification test to Jest from mocha

This commit is contained in:
Kiran Niranjan
2017-07-05 14:03:52 +05:30
committed by Kiran Niranjan
parent f96b04c1a9
commit 9ee4b76d37
4 changed files with 143 additions and 146 deletions

View File

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

34
tests/spectronSetup.js Normal file
View File

@@ -0,0 +1,34 @@
const Application = require('spectron').Application;
const path = require('path');
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(() => {
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;