From 6fe23cb13660a29f2658cf9b143666dee5cd15b4 Mon Sep 17 00:00:00 2001 From: Yuya Ochiai Date: Sat, 20 Aug 2016 20:18:08 +0900 Subject: [PATCH] Add tests for window title --- test/modules/test.html | 4 ++ test/specs/browser/index_test.js | 95 +++++++++++++++++++++++++++++++- 2 files changed, 98 insertions(+), 1 deletion(-) diff --git a/test/modules/test.html b/test/modules/test.html index 80647694..e4ff592e 100644 --- a/test/modules/test.html +++ b/test/modules/test.html @@ -1,5 +1,9 @@ + + Mattermost Desktop testing html + +

window.open() test

diff --git a/test/specs/browser/index_test.js b/test/specs/browser/index_test.js index 8147294c..329af298 100644 --- a/test/specs/browser/index_test.js +++ b/test/specs/browser/index_test.js @@ -1,7 +1,8 @@ 'use strict'; -const path = require('path'); const fs = require('fs'); +const http = require('http'); +const path = require('path'); const env = require('../../modules/environment'); @@ -19,6 +20,17 @@ describe('browser/index.html', function() { }] }; + const serverPort = 8181; + + before(function() { + this.server = http.createServer(function(req, res) { + res.writeHead(200, { + 'Content-Type': 'text/html' + }); + res.end(fs.readFileSync(path.resolve(env.sourceRootDir, 'test/modules/test.html'), 'utf-8')); + }).listen(serverPort, '127.0.0.1'); + }); + beforeEach(function() { fs.writeFileSync(env.configFilePath, JSON.stringify(config)); this.app = env.getSpectronApp(); @@ -31,6 +43,10 @@ describe('browser/index.html', function() { } }); + after(function(done) { + this.server.close(done); + }) + it('should NOT show tabs when there is one team', function() { fs.writeFileSync(env.configFilePath, JSON.stringify({ url: env.mattermostURL @@ -78,4 +94,81 @@ describe('browser/index.html', function() { .waitForVisible('#mattermostView0-fail', 20000) }); }); + + it('should set window title by using webview\'s one', function() { + fs.writeFileSync(env.configFilePath, JSON.stringify({ + version: 1, + teams: [{ + name: 'title_test', + url: `http://localhost:${serverPort}` + }] + })); + return this.app.restart().then(() => { + return this.app.client.waitUntilWindowLoaded().pause(500); + }) + .then(() => { + return this.app.browserWindow.getTitle().should.eventually.equal('Mattermost Desktop testing html'); + }); + }); + + it('should update window title when the activated tab\'s title is updated', function() { + fs.writeFileSync(env.configFilePath, JSON.stringify({ + version: 1, + teams: [{ + name: 'title_test_0', + url: `http://localhost:${serverPort}` + }, { + name: 'title_test_1', + url: `http://localhost:${serverPort}` + }] + })); + return this.app.restart().then(() => { + return this.app.client.waitUntilWindowLoaded().pause(500); + }) + .then(() => { + return this.app.client + .windowByIndex(1) + .execute(function() { + document.title = 'Title 0'; + }) + .windowByIndex(0) + .browserWindow.getTitle().should.eventually.equal('Title 0') + .windowByIndex(2) + .execute(function() { + document.title = 'Title 1'; + }) + .windowByIndex(0) + .browserWindow.getTitle().should.eventually.equal('Title 0') + }); + }); + + it('should update window title when a tab is selected', function() { + fs.writeFileSync(env.configFilePath, JSON.stringify({ + version: 1, + teams: [{ + name: 'title_test_0', + url: `http://localhost:${serverPort}` + }, { + name: 'title_test_1', + url: `http://localhost:${serverPort}` + }] + })); + return this.app.restart().then(() => { + return this.app.client + .waitUntilWindowLoaded() + .pause(500) + .windowByIndex(1) + .execute(function() { + document.title = 'Title 0'; + }) + .windowByIndex(2) + .execute(function() { + document.title = 'Title 1'; + }) + .windowByIndex(0) + .browserWindow.getTitle().should.eventually.equal('Title 0') + .click('#teamTabItem1') + .browserWindow.getTitle().should.eventually.equal('Title 1'); + }); + }); });