@@ -6,6 +6,7 @@ const chaiAsPromised = require('chai-as-promised');
|
|||||||
chai.should();
|
chai.should();
|
||||||
chai.use(chaiAsPromised);
|
chai.use(chaiAsPromised);
|
||||||
|
|
||||||
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const Application = require('spectron').Application;
|
const Application = require('spectron').Application;
|
||||||
|
|
||||||
@@ -19,12 +20,27 @@ const electronBinaryPath = (() => {
|
|||||||
})();
|
})();
|
||||||
const userDataDir = path.join(sourceRootDir, 'test/testUserData/');
|
const userDataDir = path.join(sourceRootDir, 'test/testUserData/');
|
||||||
const configFilePath = path.join(userDataDir, 'config.json');
|
const configFilePath = path.join(userDataDir, 'config.json');
|
||||||
|
const boundsInfoPath = path.join(userDataDir, 'bounds-info.json');
|
||||||
const mattermostURL = 'http://example.com/team';
|
const mattermostURL = 'http://example.com/team';
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
sourceRootDir,
|
sourceRootDir,
|
||||||
configFilePath,
|
configFilePath,
|
||||||
|
boundsInfoPath,
|
||||||
mattermostURL,
|
mattermostURL,
|
||||||
|
|
||||||
|
cleanTestConfig() {
|
||||||
|
[configFilePath, boundsInfoPath].forEach((file) => {
|
||||||
|
try {
|
||||||
|
fs.unlinkSync(file);
|
||||||
|
} catch (err) {
|
||||||
|
if (err.code !== 'ENOENT') {
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
getSpectronApp() {
|
getSpectronApp() {
|
||||||
const app = new Application({
|
const app = new Application({
|
||||||
path: electronBinaryPath,
|
path: electronBinaryPath,
|
||||||
|
@@ -7,17 +7,18 @@ const env = require('../modules/environment');
|
|||||||
describe('application', function desc() {
|
describe('application', function desc() {
|
||||||
this.timeout(10000);
|
this.timeout(10000);
|
||||||
|
|
||||||
beforeEach((done) => {
|
beforeEach(() => {
|
||||||
|
env.cleanTestConfig();
|
||||||
this.app = env.getSpectronApp();
|
this.app = env.getSpectronApp();
|
||||||
fs.unlink(env.configFilePath, () => {
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
if (this.app && this.app.isRunning()) {
|
if (this.app && this.app.isRunning()) {
|
||||||
return this.app.stop();
|
return this.app.stop().then(() => {
|
||||||
|
env.cleanTestConfig();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
env.cleanTestConfig();
|
||||||
return true;
|
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', () => {
|
it('should show settings.html when there is no config file', () => {
|
||||||
return this.app.start().then(() => {
|
return this.app.start().then(() => {
|
||||||
return this.app.client.
|
return this.app.client.
|
||||||
|
Reference in New Issue
Block a user