Fix for failed tests

This commit is contained in:
Yuya Ochiai
2015-12-23 19:25:14 +09:00
parent d010d09ef4
commit 62b6e4c51b
4 changed files with 40 additions and 11 deletions

View File

@@ -8,7 +8,7 @@
"scripts": { "scripts": {
"postinstall": "cd src && npm install", "postinstall": "cd src && npm install",
"start": "gulp build && electron src", "start": "gulp build && electron src",
"test": "mocha" "test": "gulp build && mocha"
}, },
"devDependencies": { "devDependencies": {
"babel-preset-react": "^6.3.13", "babel-preset-react": "^6.3.13",

View File

@@ -166,13 +166,17 @@ var MattermostView = React.createClass({
// 'disablewebsecurity' is necessary to display external images. // 'disablewebsecurity' is necessary to display external images.
// However, it allows also CSS/JavaScript. // However, it allows also CSS/JavaScript.
// So webview should use 'allowDisplayingInsecureContent' as same as BrowserWindow. // So webview should use 'allowDisplayingInsecureContent' as same as BrowserWindow.
return (<webview style={ this.props.style } preload="webview/mattermost.js" src={ this.props.src } ref="webview"></webview>); return (<webview className="mattermostView" style={ this.props.style } preload="webview/mattermost.js" src={ this.props.src } ref="webview"></webview>);
} }
}); });
var config;
try {
var configFile = remote.getGlobal('config-file'); var configFile = remote.getGlobal('config-file');
var config = settings.readFileSync(configFile); config = settings.readFileSync(configFile);
} catch (e) {
window.location = 'settings.html';
}
var contextMenu = require('./menus/context'); var contextMenu = require('./menus/context');
var menu = contextMenu.createDefault(); var menu = contextMenu.createDefault();

View File

@@ -8,6 +8,7 @@ const Tray = electron.Tray;
const ipc = electron.ipcMain; const ipc = electron.ipcMain;
const fs = require('fs'); const fs = require('fs');
var settings = require('./common/settings');
var appMenu = require('./menus/app'); var appMenu = require('./menus/app');
var argv = require('yargs').argv; var argv = require('yargs').argv;
@@ -27,6 +28,18 @@ else {
global['config-file'] = app.getPath('userData') + '/config.json' global['config-file'] = app.getPath('userData') + '/config.json'
} }
try {
var configFile = global['config-file'];
var config = settings.readFileSync(configFile);
if (config.version != settings.version) {
config = settings.upgrade(config);
settings.writeFileSync(configFile, config);
}
}
catch (e) {
console.log('Failed to read or upgrade config.json');
}
// Keep a global reference of the window object, if you don't, the window will // Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected. // be closed automatically when the JavaScript object is garbage collected.
var mainWindow = null; var mainWindow = null;

View File

@@ -80,18 +80,30 @@ describe('electron-mattermost', function() {
}); });
describe('index.html', function() { describe('index.html', function() {
before(function() { const config = {
fs.writeFileSync(config_file_path, JSON.stringify({ version: 1,
teams: [{
name: 'example_1',
url: mattermost_url url: mattermost_url
})); }, {
name: 'example_2',
url: mattermost_url
}]
};
before(function() {
fs.writeFileSync(config_file_path, JSON.stringify(config));
}); });
it('should set src of #mainWebview from config file', function(done) { it('should set src of webview from config file', function(done) {
var client = webdriverio.remote(options); var client = webdriverio.remote(options);
client client
.init() .init()
.getAttribute('#mainWebview', 'src').then(function(attribute) { .getAttribute('.mattermostView', 'src').then(function(attribute) {
attribute.should.equal(mattermost_url); console.log(attribute);
attribute.forEach(function(attr, index) {
attr.should.equal(config.teams[index].url);
});
}) })
.end().then(function() { .end().then(function() {
done(); done();