provide safe methods for app navigation

also change the way getUrl works
This commit is contained in:
Joe Fleming 2015-11-05 14:39:01 -07:00
parent f2e55d672d
commit df19392033
6 changed files with 129 additions and 16 deletions

View file

@ -2,7 +2,6 @@ define(function (require) {
var bdd = require('intern!bdd');
var expect = require('intern/dojo/node!expect.js');
var config = require('intern').config;
var getUrl = require('intern/dojo/node!../../utils/getUrl');
var Common = require('../../support/pages/Common');
bdd.describe('status page', function () {
@ -10,11 +9,8 @@ define(function (require) {
bdd.before(function () {
common = new Common(this.remote);
});
bdd.beforeEach(function () {
// load the status page
return this.remote.get(getUrl(config.servers.kibana, 'status'));
return common.navigateToApp('statusPage', false);
});
bdd.it('should show the kibana plugin as ready', function () {

View file

@ -1,3 +1,5 @@
var kibanaURL = '/app/kibana';
module.exports = {
servers: {
webdriver: {
@ -15,5 +17,26 @@ module.exports = {
hostname: process.env.TEST_UI_ES_HOSTNAME || 'localhost',
port: parseInt(process.env.TEST_UI_ES_PORT, 10) || 9220
}
},
apps: {
statusPage: {
pathname: 'status'
},
discover: {
pathname: kibanaURL,
hash: '/discover',
},
visualize: {
pathname: kibanaURL,
hash: '/visualize',
},
dashboard: {
pathname: kibanaURL,
hash: '/dashboard',
},
settings: {
pathname: kibanaURL,
hash: '/settings'
}
}
};

View file

@ -3,6 +3,7 @@ define(function (require) {
var config = require('intern').config;
var Promise = require('bluebird');
var moment = require('moment');
var getUrl = require('intern/dojo/node!../../utils/getUrl');
var fs = require('intern/dojo/node!fs');
var path = require('intern/dojo/node!path');
@ -13,6 +14,74 @@ define(function (require) {
Common.prototype = {
constructor: Common,
navigateToApp: function (appName, testStatusPage) {
var self = this;
var urlTimeout = 10000;
var appUrl = getUrl(config.servers.kibana, config.apps[appName]);
var doNavigation = function (url) {
return self.tryForTime(urlTimeout, function () {
// since we're using hash URLs, always reload first to force re-render
return self.remote.refresh()
.then(function () {
return self.remote.get(url)
})
.then(function () {
if (testStatusPage !== false) {
return self.checkForStatusPage()
.then(function (onStatusPage) {
if (onStatusPage) throw new Error('Hit status page, retrying');
});
}
})
.then(function () {
return self.remote.getCurrentUrl();
})
.then(function (currentUrl) {
var navSuccessful = new RegExp(appUrl).test(currentUrl);
if (!navSuccessful) throw new Error('App failed to load: ' + appName);
})
});
};
return doNavigation(appUrl)
.then(function () {
return self.remote.getCurrentUrl();
})
.then(function (currentUrl) {
var lastUrl = currentUrl;
return self.tryForTime(urlTimeout, function () {
// give the app time to update the URL
return self.sleep(1000)
.then(function () {
return self.remote.getCurrentUrl();
})
.then(function (currentUrl) {
if (lastUrl !== currentUrl) {
lastUrl = currentUrl;
throw new Error('URL changed, waiting for it to settle');
}
});
});
});
},
checkForStatusPage: function () {
var self = this;
self.debug('Checking for status page');
return self.remote.setFindTimeout(2000)
.findByCssSelector('.application .container h1').getVisibleText()
.then(function (text) {
if (text.match(/status\:/i)) return true;
return false;
})
.catch(function (err) {
self.debug('Status page title not found');
return false;
});
},
tryForTime: function tryForTime(timeout, block) {
var self = this;
var start = Date.now();

View file

@ -17,6 +17,10 @@ define(function (require) {
SettingsPage.prototype = {
constructor: SettingsPage,
navigateTo: function () {
return common.navigateToApp('settings');
},
getTimeBasedEventsCheckbox: function getTimeBasedEventsCheckbox() {
return this.remote.setFindTimeout(defaultTimeout)
.findByCssSelector('input[ng-model="index.isTimeBased"]');

View file

@ -2,17 +2,36 @@ var expect = require('expect.js');
var getUrl = require('../getUrl');
describe('getUrl', function () {
it('should be able to convert a config and a path to a url', function () {
expect(getUrl({
it('should convert to a url', function () {
var url = getUrl({
protocol: 'http',
hostname: 'localhost',
}, {
pathname: 'foo'
});
expect(url).to.be('http://localhost:9220/foo');
});
it('should convert to a secure url with port', function () {
var url = getUrl({
protocol: 'http',
hostname: 'localhost',
port: 9220
}, 'foo')).to.be('http://localhost:9220/foo');
}, {
pathname: 'foo'
});
expect(url).to.be('http://localhost:9220/foo');
});
it('should convert to a secure hashed url', function () {
expect(getUrl({
protocol: 'https',
hostname: 'localhost',
}, 'foo')).to.be('https://localhost/foo');
}, {
pathname: 'foo',
hash: 'bar'
})).to.be('https://localhost/foo#bar');
});
});

View file

@ -1,7 +1,6 @@
var _ = require('lodash');
var url = require('url');
/**
* Converts a config and a pathname to a url
* @param {object} config A url config
@ -11,11 +10,14 @@ var url = require('url');
* hostname: 'localhost',
* port: 9220
* }
* @param {string} pathname The requested path
* @param {object} app The params to append
* example:
* {
* pathname: 'app/kibana',
* hash: '/discover'
* }
* @return {string}
*/
module.exports = function getPage(config, pathname) {
return url.format(_.assign(config, {
pathname: pathname
}));
module.exports = function getPage(config, app) {
return url.format(_.assign(config, app));
};