mattermost-desktop/test/specs/app_test.js
2016-08-21 09:49:14 +02:00

82 lines
2.4 KiB
JavaScript

'use strict';
const path = require('path');
const fs = require('fs');
const env = require('../modules/environment');
describe('application', function() {
this.timeout(10000);
beforeEach(function(done) {
this.app = env.getSpectronApp();
fs.unlink(env.configFilePath, () => {
done();
});
});
afterEach(function() {
if (this.app && this.app.isRunning()) {
return this.app.stop()
}
});
it('should show a window', function() {
return this.app.start().then(() => {
return this.app.client.waitUntilWindowLoaded()
.getWindowCount().should.eventually.equal(1)
.browserWindow.isDevToolsOpened().should.eventually.be.false
.browserWindow.isVisible().should.eventually.be.true
});
});
it('should show settings.html when there is no config file', function() {
return this.app.start().then(() => {
return this.app.client.waitUntilWindowLoaded()
.getUrl().should.eventually.match(/\/settings.html$/)
});
});
it('should show index.html when there is config file', function() {
fs.writeFileSync(env.configFilePath, JSON.stringify({
url: env.mattermostURL
}));
return this.app.start().then(() => {
return this.app.client.waitUntilWindowLoaded()
.getUrl().should.eventually.match(/\/index.html$/)
});
});
it('should upgrade v0 config file', function() {
const settings = require('../../src/common/settings');
fs.writeFileSync(env.configFilePath, JSON.stringify({
url: env.mattermostURL
}));
return this.app.start().then(() => {
return this.app.client.waitUntilWindowLoaded()
.getUrl().should.eventually.match(/\/index.html$/)
}).then(function() {
var str = fs.readFileSync(env.configFilePath, 'utf8');
var config = JSON.parse(str);
config.version.should.equal(settings.version);
});
});
it('should be stopped when the app instance already exists', function(done) {
this.app.start().then(() => {
const secondApp = env.getSpectronApp();
secondApp.start().then(() => {
clearTimeout(timer);
return secondApp.stop();
}).then(() => {
done(new Error('Second app instance exists'));
});
// In the correct case, 'start().then' is not called.
// So need to use setTimeout in order to finish this test.
const timer = setTimeout(() => {
done();
}, 3000);
});
});
});