Fix eslint errors

This commit is contained in:
Yuya Ochiai
2016-09-25 23:14:01 +09:00
parent 16a18e64e6
commit 16788b5a6f
21 changed files with 1282 additions and 1078 deletions

View File

@@ -1,81 +1,86 @@
'use strict';
const path = require('path');
const fs = require('fs');
const env = require('../modules/environment');
describe('application', function() {
describe('application', function desc() {
this.timeout(10000);
beforeEach(function(done) {
beforeEach((done) => {
this.app = env.getSpectronApp();
fs.unlink(env.configFilePath, () => {
done();
});
});
afterEach(function() {
afterEach(() => {
if (this.app && this.app.isRunning()) {
return this.app.stop()
return this.app.stop();
}
return true;
});
it('should show a window', function() {
it('should show a window', () => {
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
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', () => {
return this.app.start().then(() => {
return this.app.client.waitUntilWindowLoaded()
.getUrl().should.eventually.match(/\/settings.html$/)
return this.app.client.
waitUntilWindowLoaded().
getUrl().should.eventually.match(/\/settings.html$/);
});
});
it('should show index.html when there is config file', function() {
it('should show index.html when there is config file', () => {
fs.writeFileSync(env.configFilePath, JSON.stringify({
url: env.mattermostURL
}));
return this.app.start().then(() => {
return this.app.client.waitUntilWindowLoaded()
.getUrl().should.eventually.match(/\/index.html$/)
return this.app.client.
waitUntilWindowLoaded().
getUrl().should.eventually.match(/\/index.html$/);
});
});
it('should upgrade v0 config file', function() {
it('should upgrade v0 config file', () => {
const settings = require('../../src/common/settings');
fs.writeFileSync(env.configFilePath, JSON.stringify({
url: env.mattermostURL
}));
return this.app.start().then(() => {
return this.app.client.waitUntilWindowLoaded()
.getUrl().should.eventually.match(/\/index.html$/)
}).then(function() {
return this.app.client.
waitUntilWindowLoaded().
getUrl().should.eventually.match(/\/index.html$/);
}).then(() => {
var str = fs.readFileSync(env.configFilePath, 'utf8');
var config = JSON.parse(str);
config.version.should.equal(settings.version);
});
});
it.skip('should be stopped when the app instance already exists', function(done) {
it.skip('should be stopped when the app instance already exists', (done) => {
this.app.start().then(() => {
const secondApp = env.getSpectronApp();
// In the correct case, 'start().then' is not called.
// So need to use setTimeout in order to finish this test.
const timer = setTimeout(() => {
done();
}, 3000);
secondApp.start().then(() => {
clearTimeout(timer);
return secondApp.stop();
}).then(() => {
done(new Error('Second app instance exists'));
});
// In the correct case, 'start().then' is not called.
// So need to use setTimeout in order to finish this test.
const timer = setTimeout(() => {
done();
}, 3000);
});
});
});

View File

@@ -6,7 +6,7 @@ const path = require('path');
const env = require('../../modules/environment');
describe('browser/index.html', function() {
describe('browser/index.html', function desc() {
this.timeout(10000);
const config = {
@@ -22,66 +22,68 @@ describe('browser/index.html', function() {
const serverPort = 8181;
before(function() {
this.server = http.createServer(function(req, res) {
before(() => {
function serverCallback(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');
}
this.server = http.createServer(serverCallback).listen(serverPort, '127.0.0.1');
});
beforeEach(function() {
beforeEach(() => {
fs.writeFileSync(env.configFilePath, JSON.stringify(config));
this.app = env.getSpectronApp();
return this.app.start();
});
afterEach(function() {
afterEach(() => {
if (this.app && this.app.isRunning()) {
return this.app.stop()
return this.app.stop();
}
return true;
});
after(function(done) {
after((done) => {
this.server.close(done);
})
});
it('should NOT show tabs when there is one team', function() {
it('should NOT show tabs when there is one team', () => {
fs.writeFileSync(env.configFilePath, JSON.stringify({
url: env.mattermostURL
}));
return this.app.restart().then(() => {
return this.app.client.waitUntilWindowLoaded()
.isExisting('#tabBar').should.eventually.be.false
return this.app.client.waitUntilWindowLoaded().
isExisting('#tabBar').should.eventually.be.false;
});
});
it('should set src of webview from config file', function() {
return this.app.client.waitUntilWindowLoaded()
.getAttribute('#mattermostView0', 'src').should.eventually.equal(config.teams[0].url)
.getAttribute('#mattermostView1', 'src').should.eventually.equal(config.teams[1].url)
.isExisting('#mattermostView2').should.eventually.be.false
it('should set src of webview from config file', () => {
return this.app.client.waitUntilWindowLoaded().
getAttribute('#mattermostView0', 'src').should.eventually.equal(config.teams[0].url).
getAttribute('#mattermostView1', 'src').should.eventually.equal(config.teams[1].url).
isExisting('#mattermostView2').should.eventually.be.false;
});
it('should set name of tab from config file', function() {
return this.app.client.waitUntilWindowLoaded()
.getText('#teamTabItem0').should.eventually.equal(config.teams[0].name)
.getText('#teamTabItem1').should.eventually.equal(config.teams[1].name)
it('should set name of tab from config file', () => {
return this.app.client.waitUntilWindowLoaded().
getText('#teamTabItem0').should.eventually.equal(config.teams[0].name).
getText('#teamTabItem1').should.eventually.equal(config.teams[1].name);
});
it('should show only the selected team', function() {
return this.app.client.waitUntilWindowLoaded()
.isVisible('#mattermostView0').should.eventually.be.true
.isVisible('#mattermostView1').should.eventually.be.false
.click('#teamTabItem1')
.pause(1000)
.isVisible('#mattermostView1').should.eventually.be.true
.isVisible('#mattermostView0').should.eventually.be.false
it('should show only the selected team', () => {
return this.app.client.waitUntilWindowLoaded().
isVisible('#mattermostView0').should.eventually.be.true.
isVisible('#mattermostView1').should.eventually.be.false.
click('#teamTabItem1').
pause(1000).
isVisible('#mattermostView1').should.eventually.be.true.
isVisible('#mattermostView0').should.eventually.be.false;
});
it('should show error when using incorrect URL', function() {
this.timeout(30000)
it('should show error when using incorrect URL', () => {
this.timeout(30000);
fs.writeFileSync(env.configFilePath, JSON.stringify({
version: 1,
teams: [{
@@ -90,12 +92,12 @@ describe('browser/index.html', function() {
}]
}));
return this.app.restart().then(() => {
return this.app.client.waitUntilWindowLoaded()
.waitForVisible('#mattermostView0-fail', 20000)
return this.app.client.waitUntilWindowLoaded().
waitForVisible('#mattermostView0-fail', 20000);
});
});
it('should set window title by using webview\'s one', function() {
it('should set window title by using webview\'s one', () => {
fs.writeFileSync(env.configFilePath, JSON.stringify({
version: 1,
teams: [{
@@ -104,14 +106,13 @@ describe('browser/index.html', function() {
}]
}));
return this.app.restart().then(() => {
return this.app.client.waitUntilWindowLoaded().pause(1000);
})
.then(() => {
return this.app.browserWindow.getTitle().should.eventually.equal('Mattermost Desktop testing html');
});
return this.app.client.waitUntilWindowLoaded().pause(1000);
}).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() {
it('should update window title when the activated tab\'s title is updated', () => {
fs.writeFileSync(env.configFilePath, JSON.stringify({
version: 1,
teams: [{
@@ -123,52 +124,51 @@ describe('browser/index.html', function() {
}]
}));
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() {
return this.app.client.waitUntilWindowLoaded().pause(500);
}).then(() => {
return this.app.client.
windowByIndex(1).
execute(() => {
document.title = 'Title 0';
})
.windowByIndex(2)
.execute(function() {
}).
windowByIndex(0).
browserWindow.getTitle().should.eventually.equal('Title 0').
windowByIndex(2).
execute(() => {
document.title = 'Title 1';
})
.windowByIndex(0)
.browserWindow.getTitle().should.eventually.equal('Title 0')
.click('#teamTabItem1')
.browserWindow.getTitle().should.eventually.equal('Title 1');
}).
windowByIndex(0).
browserWindow.getTitle().should.eventually.equal('Title 0');
});
});
it('should update window title when a tab is selected', () => {
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(() => {
document.title = 'Title 0';
}).
windowByIndex(2).
execute(() => {
document.title = 'Title 1';
}).
windowByIndex(0).
browserWindow.getTitle().should.eventually.equal('Title 0').
click('#teamTabItem1').
browserWindow.getTitle().should.eventually.equal('Title 1');
});
});
});

View File

@@ -1,11 +1,10 @@
'use strict';
const path = require('path');
const fs = require('fs');
const env = require('../../modules/environment');
describe('browser/settings.html', function() {
describe('browser/settings.html', function desc() {
this.timeout(10000);
const config = {
@@ -19,177 +18,174 @@ describe('browser/settings.html', function() {
}]
};
beforeEach(function() {
beforeEach(() => {
fs.writeFileSync(env.configFilePath, JSON.stringify(config));
this.app = env.getSpectronApp();
return this.app.start();
});
afterEach(function() {
afterEach(() => {
if (this.app && this.app.isRunning()) {
return this.app.stop()
return this.app.stop();
}
return true;
});
it('should show index.html when Cancel button is clicked', function() {
it('should show index.html when Cancel button is clicked', () => {
env.addClientCommands(this.app.client);
return this.app.client
.loadSettingsPage()
.click('#btnCancel')
.pause(1000)
.getUrl().should.eventually.match(/\/index.html$/)
return this.app.client.
loadSettingsPage().
click('#btnCancel').
pause(1000).
getUrl().should.eventually.match(/\/index.html$/);
});
it('should show index.html when Save button is clicked', function() {
it('should show index.html when Save button is clicked', () => {
env.addClientCommands(this.app.client);
return this.app.client
.loadSettingsPage()
.click('#btnSave')
.pause(1000)
.getUrl().should.eventually.match(/\/index.html$/)
return this.app.client.
loadSettingsPage().
click('#btnSave').
pause(1000).
getUrl().should.eventually.match(/\/index.html$/);
});
describe('Options', function() {
describe('Hide Menu Bar', function() {
it('should appear on win32 or linux', function() {
describe('Options', () => {
describe('Hide Menu Bar', () => {
it('should appear on win32 or linux', () => {
const expected = (process.platform === 'win32' || process.platform === 'linux');
env.addClientCommands(this.app.client);
return this.app.client
.loadSettingsPage()
.isExisting('#inputHideMenuBar').should.eventually.equal(expected)
return this.app.client.
loadSettingsPage().
isExisting('#inputHideMenuBar').should.eventually.equal(expected);
});
[true, false].forEach(function(v) {
env.shouldTest(it, env.isOneOf(['win32', 'linux']))
(`should be saved and loaded: ${v}`, function() {
env.addClientCommands(this.app.client);
return this.app.client
.loadSettingsPage()
.scroll('#inputHideMenuBar')
.isSelected('#inputHideMenuBar input').then((isSelected) => {
if (isSelected !== v) {
return this.app.client.click('#inputHideMenuBar input')
}
})
.click('#btnSave')
.pause(1000).then(() => {
const saved_config = JSON.parse(fs.readFileSync(env.configFilePath, 'utf8'));
saved_config.hideMenuBar.should.equal(v);
})
// confirm actual behavior
.browserWindow.isMenuBarAutoHide().should.eventually.equal(v).then(() => {
return this.app.restart();
}).then(() => {
env.addClientCommands(this.app.client);
return this.app.client
// confirm actual behavior
.browserWindow.isMenuBarAutoHide().should.eventually.equal(v)
.loadSettingsPage()
.isSelected('#inputHideMenuBar input').should.eventually.equal(v);
});
});
});
});
describe('Allow mixed content', function() {
[true, false].forEach(function(v) {
it(`should be saved and loaded: ${v}`, function() {
[true, false].forEach((v) => {
env.shouldTest(it, env.isOneOf(['win32', 'linux']))(`should be saved and loaded: ${v}`, () => {
env.addClientCommands(this.app.client);
return this.app.client
.loadSettingsPage()
.scroll('#inputDisableWebSecurity')
.isSelected('#inputDisableWebSecurity input').then((isSelected) => {
return this.app.client.
loadSettingsPage().
scroll('#inputHideMenuBar').
isSelected('#inputHideMenuBar input').then((isSelected) => {
if (isSelected !== v) {
return this.app.client.click('#inputDisableWebSecurity input')
return this.app.client.click('#inputHideMenuBar input');
}
})
.click('#btnSave')
.pause(1000).then(() => {
const saved_config = JSON.parse(fs.readFileSync(env.configFilePath, 'utf8'));
saved_config.disablewebsecurity.should.equal(v);
})
// confirm actual behavior
.getAttribute('.mattermostView', 'disablewebsecurity').then((disablewebsecurity) => {
// disablewebsecurity is an array of String
disablewebsecurity.forEach((d) => {
v.toString().should.equal(d);
})
}).then(() => {
return true;
}).
click('#btnSave').
pause(1000).then(() => {
const savedConfig = JSON.parse(fs.readFileSync(env.configFilePath, 'utf8'));
savedConfig.hideMenuBar.should.equal(v);
}).
browserWindow.isMenuBarAutoHide().should.eventually.equal(v).then(() => { // confirm actual behavior
return this.app.restart();
}).then(() => {
env.addClientCommands(this.app.client);
return this.app.client
// confirm actual behavior
.getAttribute('.mattermostView', 'disablewebsecurity').then((disablewebsecurity) => {
// disablewebsecurity is an array of String
disablewebsecurity.forEach((d) => {
v.toString().should.equal(d);
})
})
.loadSettingsPage()
.isSelected('#inputDisableWebSecurity input').should.eventually.equal(v);
return this.app.client. // confirm actual behavior
browserWindow.isMenuBarAutoHide().should.eventually.equal(v).
loadSettingsPage().
isSelected('#inputHideMenuBar input').should.eventually.equal(v);
});
});
});
});
describe('Start app on login', function() {
it('should appear on win32 or linux', function() {
describe('Allow mixed content', () => {
[true, false].forEach((v) => {
it(`should be saved and loaded: ${v}`, () => {
env.addClientCommands(this.app.client);
return this.app.client.
loadSettingsPage().
scroll('#inputDisableWebSecurity').
isSelected('#inputDisableWebSecurity input').then((isSelected) => {
if (isSelected !== v) {
return this.app.client.click('#inputDisableWebSecurity input');
}
return true;
}).
click('#btnSave').
pause(1000).then(() => {
const savedConfig = JSON.parse(fs.readFileSync(env.configFilePath, 'utf8'));
savedConfig.disablewebsecurity.should.equal(v);
}).
getAttribute('.mattermostView', 'disablewebsecurity').then((disablewebsecurity) => { // confirm actual behavior
// disablewebsecurity is an array of String
disablewebsecurity.forEach((d) => {
v.toString().should.equal(d);
});
}).then(() => {
return this.app.restart();
}).then(() => {
env.addClientCommands(this.app.client);
return this.app.client. // confirm actual behavior
getAttribute('.mattermostView', 'disablewebsecurity').then((disablewebsecurity) => { // disablewebsecurity is an array of String
disablewebsecurity.forEach((d) => {
v.toString().should.equal(d);
});
}).
loadSettingsPage().
isSelected('#inputDisableWebSecurity input').should.eventually.equal(v);
});
});
});
});
describe('Start app on login', () => {
it('should appear on win32 or linux', () => {
const expected = (process.platform === 'win32' || process.platform === 'linux');
env.addClientCommands(this.app.client);
return this.app.client
.loadSettingsPage()
.isExisting('#inputAutoStart').should.eventually.equal(expected)
return this.app.client.
loadSettingsPage().
isExisting('#inputAutoStart').should.eventually.equal(expected);
});
});
describe('Show tray icon', function() {
it('should appear on darwin or linux', function() {
describe('Show tray icon', () => {
it('should appear on darwin or linux', () => {
const expected = (process.platform === 'darwin' || process.platform === 'linux');
env.addClientCommands(this.app.client);
return this.app.client
.loadSettingsPage()
.isExisting('#inputShowTrayIcon').should.eventually.equal(expected)
return this.app.client.
loadSettingsPage().
isExisting('#inputShowTrayIcon').should.eventually.equal(expected);
});
});
describe('Minimize to tray', function() {
it('should appear on darwin or linux', function() {
describe('Minimize to tray', () => {
it('should appear on darwin or linux', () => {
const expected = (process.platform === 'darwin' || process.platform === 'linux');
env.addClientCommands(this.app.client);
return this.app.client
.loadSettingsPage()
.isExisting('#inputMinimizeToTray').should.eventually.equal(expected)
return this.app.client.
loadSettingsPage().
isExisting('#inputMinimizeToTray').should.eventually.equal(expected);
});
});
describe('Toggle window visibility when clicking on the tray icon', function() {
it('should appear on win32', function() {
describe('Toggle window visibility when clicking on the tray icon', () => {
it('should appear on win32', () => {
const expected = (process.platform === 'win32');
env.addClientCommands(this.app.client);
return this.app.client
.loadSettingsPage()
.isExisting('#inputToggleWindowOnTrayIconClick').should.eventually.equal(expected)
return this.app.client.
loadSettingsPage().
isExisting('#inputToggleWindowOnTrayIconClick').should.eventually.equal(expected);
});
});
describe('Flash taskbar icon on new messages', function() {
it('should appear on win32 and linux', function() {
describe('Flash taskbar icon on new messages', () => {
it('should appear on win32 and linux', () => {
const expected = (process.platform === 'win32' || process.platform === 'linux');
env.addClientCommands(this.app.client);
return this.app.client
.loadSettingsPage()
.isExisting('#inputflashWindow').should.eventually.equal(expected)
return this.app.client.
loadSettingsPage().
isExisting('#inputflashWindow').should.eventually.equal(expected);
});
});
describe('Show red icon for unread', function() {
it('should appear on darwin or win32', function() {
describe('Show red icon for unread', () => {
it('should appear on darwin or win32', () => {
const expected = (process.platform === 'darwin' || process.platform === 'win32');
env.addClientCommands(this.app.client);
return this.app.client
.loadSettingsPage()
.isExisting('#inputShowUnreadBadge').should.eventually.equal(expected)
return this.app.client.
loadSettingsPage().
isExisting('#inputShowUnreadBadge').should.eventually.equal(expected);
});
});
});

View File

@@ -6,11 +6,11 @@ const http = require('http');
const env = require('../modules/environment');
describe('application', function() {
describe('application', function desc() {
this.timeout(10000);
const serverPort = 8181;
const testURL = `http://localhost:${serverPort}`
const testURL = `http://localhost:${serverPort}`;
const config = {
version: 1,
@@ -23,8 +23,8 @@ describe('application', function() {
}]
};
before(function() {
this.server = http.createServer(function(req, res) {
before(() => {
this.server = http.createServer((req, res) => {
res.writeHead(200, {
'Content-Type': 'text/html'
});
@@ -32,66 +32,68 @@ describe('application', function() {
}).listen(serverPort, '127.0.0.1');
});
beforeEach(function() {
beforeEach(() => {
fs.writeFileSync(env.configFilePath, JSON.stringify(config));
this.app = env.getSpectronApp();
return this.app.start();
});
afterEach(function() {
afterEach(() => {
if (this.app && this.app.isRunning()) {
return this.app.stop()
return this.app.stop();
}
return true;
});
after(function(done) {
after((done) => {
this.server.close(done);
})
});
it('should NOT be able to call Node.js API in webview', function() {
it('should NOT be able to call Node.js API in webview', () => {
env.addClientCommands(this.app.client);
return this.app.client
.getAttribute('webview', 'nodeintegration').then((nodeintegration) => {
return this.app.client.
getAttribute('webview', 'nodeintegration').then((nodeintegration) => {
// nodeintegration is an array of string
nodeintegration.forEach((n) => {
n.should.equal('false');
});
})
}).
// webview is handled as a window by chromedriver.
.windowByIndex(1).isNodeEnabled().should.eventually.be.false
.windowByIndex(2).isNodeEnabled().should.eventually.be.false;
windowByIndex(1).isNodeEnabled().should.eventually.be.false.
windowByIndex(2).isNodeEnabled().should.eventually.be.false;
});
it('should NOT be able to call Node.js API in a new window', function() {
it('should NOT be able to call Node.js API in a new window', () => {
env.addClientCommands(this.app.client);
const client = this.app.client;
return this.app.client
.windowByIndex(1) // in the first webview
.execute(function() {
return this.app.client.
windowByIndex(1). // in the first webview
execute(() => {
open_window();
})
.waitUntil(function async() {
}).
waitUntil(() => {
return client.windowHandles().then((handles) => {
return handles.value.length === 4;
});
}, 5000, 'expected a new window')
.windowByIndex(3).isNodeEnabled().should.eventually.be.false;
}, 5000, 'expected a new window').
windowByIndex(3).isNodeEnabled().should.eventually.be.false;
});
it('should NOT be able to call eval() in any window', function() {
it('should NOT be able to call eval() in any window', () => {
env.addClientCommands(this.app.client);
const tryEval = (index) => {
return this.app.client
.windowByIndex(index)
.execute(function() {
return this.app.client.
windowByIndex(index).
execute(() => {
return eval('1 + 1');
}).should.eventually.be.rejected;
};
const tryEvalInSettingsPage = () => {
return this.app.client
.windowByIndex(0)
.loadSettingsPage()
.execute(function() {
return this.app.client.
windowByIndex(0).
loadSettingsPage().
execute(() => {
return eval('1 + 1');
}).should.eventually.be.rejected;
};

View File

@@ -1,18 +1,13 @@
const fs = require('fs');
const settings = require('../../src/common/settings');
const env = require('../modules/environment');
//const env.configFilePath = '../../test_config.json'
describe('common/settings.js', function() {
it('should upgrade v0 config file', function() {
const v0_config = {
describe('common/settings.js', () => {
it('should upgrade v0 config file', () => {
const v0Config = {
url: 'https://example.com/team'
};
config = settings.upgrade(v0_config);
const config = settings.upgrade(v0Config);
config.teams.length.should.equal(1);
config.teams[0].url.should.equal(v0_config.url);
config.teams[0].url.should.equal(v0Config.url);
config.version.should.equal(settings.version);
});
});