diff --git a/test/modules/environment.js b/test/modules/environment.js index 2b509da8..f45e8d3b 100644 --- a/test/modules/environment.js +++ b/test/modules/environment.js @@ -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, diff --git a/test/specs/app_test.js b/test/specs/app_test.js index c61959c5..e917687b 100644 --- a/test/specs/app_test.js +++ b/test/specs/app_test.js @@ -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.