Add test for #378 and #386

This commit is contained in:
Yuya Ochiai
2016-12-27 22:10:53 +09:00
parent 3bf41ca3e5
commit 0e6ba99e36
2 changed files with 49 additions and 5 deletions

View File

@@ -6,6 +6,7 @@ const chaiAsPromised = require('chai-as-promised');
chai.should();
chai.use(chaiAsPromised);
const fs = require('fs');
const path = require('path');
const Application = require('spectron').Application;
@@ -19,12 +20,27 @@ const electronBinaryPath = (() => {
})();
const userDataDir = path.join(sourceRootDir, 'test/testUserData/');
const configFilePath = path.join(userDataDir, 'config.json');
const boundsInfoPath = path.join(userDataDir, 'bounds-info.json');
const mattermostURL = 'http://example.com/team';
module.exports = {
sourceRootDir,
configFilePath,
boundsInfoPath,
mattermostURL,
cleanTestConfig() {
[configFilePath, boundsInfoPath].forEach((file) => {
try {
fs.unlinkSync(file);
} catch (err) {
if (err.code !== 'ENOENT') {
console.error(err);
}
}
});
},
getSpectronApp() {
const app = new Application({
path: electronBinaryPath,

View File

@@ -7,17 +7,18 @@ const env = require('../modules/environment');
describe('application', function desc() {
this.timeout(10000);
beforeEach((done) => {
beforeEach(() => {
env.cleanTestConfig();
this.app = env.getSpectronApp();
fs.unlink(env.configFilePath, () => {
done();
});
});
afterEach(() => {
if (this.app && this.app.isRunning()) {
return this.app.stop();
return this.app.stop().then(() => {
env.cleanTestConfig();
});
}
env.cleanTestConfig();
return true;
});
@@ -31,6 +32,33 @@ describe('application', function desc() {
});
});
it('should restore window bounds', () => {
const expectedBounds = {x: 100, y: 200, width: 300, height: 400};
fs.writeFileSync(env.boundsInfoPath, JSON.stringify(expectedBounds));
return this.app.start().then(() => {
return this.app.browserWindow.getBounds();
}).then((bounds) => {
bounds.should.deep.equal(expectedBounds);
});
});
it('should NOT restore window bounds if the origin is located on outside of viewarea', () => {
const expectedMinusBounds = {x: -100000, y: 200, width: 300, height: 400};
const expectedLargeBounds = {x: 100, y: 200000, width: 300, height: 400};
fs.writeFileSync(env.boundsInfoPath, JSON.stringify(expectedMinusBounds));
return this.app.start().then(() => {
return this.app.browserWindow.getBounds();
}).then((bounds) => {
bounds.should.not.deep.equal(expectedMinusBounds);
}).then(() => {
fs.writeFileSync(env.boundsInfoPath, JSON.stringify(expectedLargeBounds));
return this.app.restart();
}).then((bounds) => {
bounds.should.not.deep.equal(expectedLargeBounds);
});
});
it('should show settings.html when there is no config file', () => {
return this.app.start().then(() => {
return this.app.client.