Rewrite tests with chai-as-promised
This commit is contained in:
@@ -31,6 +31,8 @@
|
|||||||
"babel-core": "^6.7.5",
|
"babel-core": "^6.7.5",
|
||||||
"babel-loader": "^6.2.4",
|
"babel-loader": "^6.2.4",
|
||||||
"babel-preset-react": "^6.5.0",
|
"babel-preset-react": "^6.5.0",
|
||||||
|
"chai": "^3.5.0",
|
||||||
|
"chai-as-promised": "^5.3.0",
|
||||||
"del": "^2.2.0",
|
"del": "^2.2.0",
|
||||||
"electron-builder": "^3.11.0",
|
"electron-builder": "^3.11.0",
|
||||||
"electron-connect": "^0.3.7",
|
"electron-connect": "^0.3.7",
|
||||||
@@ -46,7 +48,6 @@
|
|||||||
"json-loader": "^0.5.4",
|
"json-loader": "^0.5.4",
|
||||||
"mocha": "^2.3.4",
|
"mocha": "^2.3.4",
|
||||||
"mocha-circleci-reporter": "0.0.1",
|
"mocha-circleci-reporter": "0.0.1",
|
||||||
"should": "^8.0.1",
|
|
||||||
"spectron": "~3.0.0",
|
"spectron": "~3.0.0",
|
||||||
"style-loader": "^0.13.0",
|
"style-loader": "^0.13.0",
|
||||||
"through2": "^2.0.1",
|
"through2": "^2.0.1",
|
||||||
|
@@ -1,5 +1,12 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const chai = require('chai');
|
||||||
|
const chaiAsPromised = require('chai-as-promised');
|
||||||
|
|
||||||
|
chai.should();
|
||||||
|
chai.use(chaiAsPromised);
|
||||||
|
|
||||||
|
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const Application = require('spectron').Application;
|
const Application = require('spectron').Application;
|
||||||
|
|
||||||
@@ -21,10 +28,12 @@ module.exports = {
|
|||||||
configFilePath: config_file_path,
|
configFilePath: config_file_path,
|
||||||
mattermostURL: mattermost_url,
|
mattermostURL: mattermost_url,
|
||||||
getSpectronApp: function() {
|
getSpectronApp: function() {
|
||||||
return new Application({
|
const app = new Application({
|
||||||
path: electron_binary_path,
|
path: electron_binary_path,
|
||||||
args: [`${path.join(source_root_dir, 'dist')}`, '--config-file=' + config_file_path]
|
args: [`${path.join(source_root_dir, 'dist')}`, '--config-file=' + config_file_path]
|
||||||
});
|
});
|
||||||
|
chaiAsPromised.transferPromiseness = app.transferPromiseness
|
||||||
|
return app;
|
||||||
},
|
},
|
||||||
shouldTestForPlatforms: function(testCase, platforms) {
|
shouldTestForPlatforms: function(testCase, platforms) {
|
||||||
if (platforms.indexOf(process.platform) !== -1) {
|
if (platforms.indexOf(process.platform) !== -1) {
|
||||||
|
@@ -1,6 +1,5 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const should = require('should');
|
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
@@ -9,10 +8,10 @@ const env = require('../modules/environment');
|
|||||||
describe('application', function() {
|
describe('application', function() {
|
||||||
this.timeout(10000);
|
this.timeout(10000);
|
||||||
|
|
||||||
before(function(done) {
|
beforeEach(function(done) {
|
||||||
this.app = env.getSpectronApp();
|
this.app = env.getSpectronApp();
|
||||||
fs.unlink(env.configFilePath, () => {
|
fs.unlink(env.configFilePath, () => {
|
||||||
done()
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -22,14 +21,19 @@ describe('application', function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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() {
|
it('should show settings.html when there is no config file', function() {
|
||||||
return this.app.start().then(() => {
|
return this.app.start().then(() => {
|
||||||
this.app.client
|
return this.app.client.waitUntilWindowLoaded()
|
||||||
.pause(1000)
|
.getUrl().should.eventually.match(/\/settings.html$/)
|
||||||
.getUrl().then(function(url) {
|
|
||||||
var p = path.parse(url);
|
|
||||||
p.base.should.equal('settings.html');
|
|
||||||
})
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -38,12 +42,8 @@ describe('application', function() {
|
|||||||
url: env.mattermostURL
|
url: env.mattermostURL
|
||||||
}));
|
}));
|
||||||
return this.app.start().then(() => {
|
return this.app.start().then(() => {
|
||||||
this.app.client
|
return this.app.client.waitUntilWindowLoaded()
|
||||||
.pause(1000)
|
.getUrl().should.eventually.match(/\/index.html$/)
|
||||||
.getUrl().then(function(url) {
|
|
||||||
var p = path.parse(url);
|
|
||||||
p.base.should.equal('index.html');
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -53,17 +53,12 @@ describe('application', function() {
|
|||||||
url: env.mattermostURL
|
url: env.mattermostURL
|
||||||
}));
|
}));
|
||||||
return this.app.start().then(() => {
|
return this.app.start().then(() => {
|
||||||
this.app.client
|
return this.app.client.waitUntilWindowLoaded()
|
||||||
.pause(1000)
|
.getUrl().should.eventually.match(/\/index.html$/)
|
||||||
.getUrl().then(function(url) {
|
}).then(function() {
|
||||||
var p = path.parse(url);
|
var str = fs.readFileSync(env.configFilePath, 'utf8');
|
||||||
p.base.should.equal('index.html');
|
var config = JSON.parse(str);
|
||||||
})
|
config.version.should.equal(settings.version);
|
||||||
.end().then(function() {
|
|
||||||
var str = fs.readFileSync(env.configFilePath, 'utf8');
|
|
||||||
var config = JSON.parse(str);
|
|
||||||
config.version.should.equal(settings.version);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -1,6 +1,5 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const should = require('should');
|
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
@@ -20,15 +19,10 @@ describe('browser/index.html', function() {
|
|||||||
}]
|
}]
|
||||||
};
|
};
|
||||||
|
|
||||||
before(function(done) {
|
|
||||||
this.app = env.getSpectronApp();
|
|
||||||
fs.unlink(env.configFilePath, function(err) {
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
fs.writeFileSync(env.configFilePath, JSON.stringify(config));
|
fs.writeFileSync(env.configFilePath, JSON.stringify(config));
|
||||||
|
this.app = env.getSpectronApp();
|
||||||
|
return this.app.start();
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(function() {
|
afterEach(function() {
|
||||||
@@ -41,63 +35,33 @@ describe('browser/index.html', function() {
|
|||||||
fs.writeFileSync(env.configFilePath, JSON.stringify({
|
fs.writeFileSync(env.configFilePath, JSON.stringify({
|
||||||
url: env.mattermostURL
|
url: env.mattermostURL
|
||||||
}));
|
}));
|
||||||
return this.app.start().then(() => {
|
return this.app.restart().then(() => {
|
||||||
this.app.client
|
return this.app.client.waitUntilWindowLoaded()
|
||||||
.init()
|
.isExisting('#tabBar').should.eventually.be.false
|
||||||
.isExisting('#tabBar').then(function(isExisting) {
|
|
||||||
isExisting.should.be.false();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should set src of webview from config file', function() {
|
it('should set src of webview from config file', function() {
|
||||||
return this.app.start().then(() => {
|
return this.app.client.waitUntilWindowLoaded()
|
||||||
this.app.client
|
.getAttribute('#mattermostView0', 'src').should.eventually.equal(config.teams[0].url)
|
||||||
.init()
|
.getAttribute('#mattermostView1', 'src').should.eventually.equal(config.teams[1].url)
|
||||||
.getAttribute('#mattermostView0', 'src').then(function(attribute) {
|
.isExisting('#mattermostView2').should.eventually.be.false
|
||||||
attribute.should.equal(config.teams[0].url);
|
|
||||||
})
|
|
||||||
.getAttribute('#mattermostView1', 'src').then(function(attribute) {
|
|
||||||
attribute.should.equal(config.teams[1].url);
|
|
||||||
})
|
|
||||||
.isExisting('#mattermostView2').then(function(isExisting) {
|
|
||||||
isExisting.should.be.false();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should set name of tab from config file', function() {
|
it('should set name of tab from config file', function() {
|
||||||
return this.app.start().then(() => {
|
return this.app.client.waitUntilWindowLoaded()
|
||||||
this.app.client
|
.getText('#teamTabItem0').should.eventually.equal(config.teams[0].name)
|
||||||
.init()
|
.getText('#teamTabItem1').should.eventually.equal(config.teams[1].name)
|
||||||
.getText('#teamTabItem0').then(function(text) {
|
|
||||||
text.should.equal(config.teams[0].name);
|
|
||||||
})
|
|
||||||
.getText('#teamTabItem1').then(function(text) {
|
|
||||||
text.should.equal(config.teams[1].name);
|
|
||||||
})
|
|
||||||
.isExisting('#teamTabItem2').then(function(isExisting) {
|
|
||||||
isExisting.should.be.false();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should show only the selected team', function() {
|
it('should show only the selected team', function() {
|
||||||
return this.app.start().then(() => {
|
return this.app.client.waitUntilWindowLoaded()
|
||||||
this.app.client
|
.isVisible('#mattermostView0').should.eventually.be.true
|
||||||
.init()
|
.isVisible('#mattermostView1').should.eventually.be.false
|
||||||
.pause(1000)
|
.click('#teamTabItem1')
|
||||||
.waitForVisible('#mattermostView0', 1000)
|
.pause(1000)
|
||||||
.isVisible('#mattermostView1').then(function(visility) {
|
.isVisible('#mattermostView1').should.eventually.be.true
|
||||||
visility.should.be.false();
|
.isVisible('#mattermostView0').should.eventually.be.false
|
||||||
})
|
|
||||||
.click('#teamTabItem1')
|
|
||||||
.pause(1000)
|
|
||||||
.waitForVisible('#mattermostView1', 1000)
|
|
||||||
.isVisible('#mattermostView0').then(function(visility) {
|
|
||||||
visility.should.be.false();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should show error when using incorrect URL', function() {
|
it('should show error when using incorrect URL', function() {
|
||||||
@@ -109,9 +73,8 @@ describe('browser/index.html', function() {
|
|||||||
url: 'http://false'
|
url: 'http://false'
|
||||||
}]
|
}]
|
||||||
}));
|
}));
|
||||||
return this.app.start().then(() => {
|
return this.app.restart().then(() => {
|
||||||
this.app.client
|
return this.app.client.waitUntilWindowLoaded()
|
||||||
.init()
|
|
||||||
.waitForVisible('#mattermostView0-fail', 20000)
|
.waitForVisible('#mattermostView0-fail', 20000)
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -1,6 +1,5 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const should = require('should');
|
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
@@ -8,8 +7,8 @@ const env = require('../../modules/environment');
|
|||||||
|
|
||||||
function initClient(client) {
|
function initClient(client) {
|
||||||
return client
|
return client
|
||||||
.init()
|
.url('file://' + path.join(env.sourceRootDir, 'dist/browser/settings.html'))
|
||||||
.url('file://' + path.join(env.sourceRootDir, 'dist/browser/settings.html'));
|
.waitUntilWindowLoaded();
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('browser/settings.html', function() {
|
describe('browser/settings.html', function() {
|
||||||
@@ -26,17 +25,10 @@ describe('browser/settings.html', function() {
|
|||||||
}]
|
}]
|
||||||
};
|
};
|
||||||
|
|
||||||
var chromedriver;
|
|
||||||
var client;
|
|
||||||
before(function(done) {
|
|
||||||
this.app = env.getSpectronApp();
|
|
||||||
fs.unlink(env.configFilePath, function(err) {
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
fs.writeFileSync(env.configFilePath, JSON.stringify(config));
|
fs.writeFileSync(env.configFilePath, JSON.stringify(config));
|
||||||
|
this.app = env.getSpectronApp();
|
||||||
|
return this.app.start();
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(function() {
|
afterEach(function() {
|
||||||
@@ -46,45 +38,25 @@ describe('browser/settings.html', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should show index.thml when Cancel button is clicked', function() {
|
it('should show index.thml when Cancel button is clicked', function() {
|
||||||
return this.app.start().then(() => {
|
return initClient(this.app.client)
|
||||||
initClient(this.app.client)
|
.click('#btnCancel')
|
||||||
.waitForExist('#btnCancel')
|
.pause(1000)
|
||||||
.click('#btnCancel')
|
.getUrl().should.eventually.match(/\/index.html$/)
|
||||||
.pause(1000)
|
|
||||||
.getUrl().then(function(url) {
|
|
||||||
var url_split = url.split('/');
|
|
||||||
url_split[url_split.length - 1].should.equal('index.html');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should show index.thml when Save button is clicked', function() {
|
it('should show index.thml when Save button is clicked', function() {
|
||||||
return this.app.start().then(() => {
|
return initClient(this.app.client)
|
||||||
initClient(this.app.client)
|
.click('#btnSave')
|
||||||
.waitForExist('#btnSave')
|
.pause(1000)
|
||||||
.click('#btnSave')
|
.getUrl().should.eventually.match(/\/index.html$/)
|
||||||
.pause(1000)
|
|
||||||
.getUrl().then(function(url) {
|
|
||||||
var url_split = url.split('/');
|
|
||||||
url_split[url_split.length - 1].should.equal('index.html');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Options', function() {
|
describe('Options', function() {
|
||||||
describe('Hide Menu Bar', function() {
|
describe('Hide Menu Bar', function() {
|
||||||
it('should appear on win32 or linux', function() {
|
it('should appear on win32 or linux', function() {
|
||||||
return this.app.start().then(() => {
|
const expected = (process.platform === 'win32' || process.platform === 'linux');
|
||||||
initClient(this.app.client)
|
return initClient(this.app.client)
|
||||||
.isExisting('#inputHideMenuBar').then(function(isExisting) {
|
.isExisting('#inputHideMenuBar').should.eventually.equal(expected)
|
||||||
if (process.platform === 'win32' || process.platform === 'linux') {
|
|
||||||
isExisting.should.be.true();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
isExisting.should.be.false();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
[true, false].forEach(function(v) {
|
[true, false].forEach(function(v) {
|
||||||
@@ -94,28 +66,26 @@ describe('browser/settings.html', function() {
|
|||||||
Object.assign(new_config, config);
|
Object.assign(new_config, config);
|
||||||
new_config.hideMenuBar = v;
|
new_config.hideMenuBar = v;
|
||||||
fs.writeFileSync(env.configFilePath, JSON.stringify(new_config));
|
fs.writeFileSync(env.configFilePath, JSON.stringify(new_config));
|
||||||
return this.app.start().then(() => {
|
return this.app.restart().then(() => {
|
||||||
initClient(this.app.client)
|
return initClient(this.app.client)
|
||||||
.isSelected('#inputHideMenuBar input').then(function(value) {
|
.isSelected('#inputHideMenuBar input').should.eventually.equal(v)
|
||||||
value.should.equal(v);
|
.browserWindow.isMenuBarAutoHide().should.eventually.equal(v);
|
||||||
this.app.browserWindow.isMenuBarAutoHide().should.equal(v);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be saved as config.json', function() {
|
it('should be saved as config.json', function() {
|
||||||
env.shouldTestForPlatforms(this, ['win32', 'linux']);
|
env.shouldTestForPlatforms(this, ['win32', 'linux']);
|
||||||
return this.app.start().then(() => {
|
return this.app.restart().then(() => {
|
||||||
initClient(this.app.client)
|
return initClient(this.app.client)
|
||||||
.click('#inputHideMenuBar input')
|
.click('#inputHideMenuBar input')
|
||||||
.click('#btnSave')
|
.click('#btnSave')
|
||||||
.pause(1000)
|
.pause(1000)
|
||||||
.then(function() {
|
})
|
||||||
const saved_config = JSON.parse(fs.readFileSync(env.configFilePath, 'utf8'));
|
.then(() => {
|
||||||
saved_config.hideMenuBar.should.be.true();
|
const saved_config = JSON.parse(fs.readFileSync(env.configFilePath, 'utf8'));
|
||||||
});
|
saved_config.hideMenuBar.should.be.true;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -1,4 +1,3 @@
|
|||||||
const should = require('should');
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const settings = require('../../src/common/settings');
|
const settings = require('../../src/common/settings');
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user