Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discover shared link tests 4x merge from #6010 #6023

Merged
merged 5 commits into from
Jan 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/functional/apps/discover/_discover.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ define(function (require) {
var hasFailure = false;
for (var y = 0; y < expectedBarChartData.length; y++) {
stringResults += y + ': expected = ' + expectedBarChartData[y] + ', actual = ' + paths[y] +
', Pass = ' + (Math.abs(expectedBarChartData[y] - paths[y]) < barHeightTolerance);
', Pass = ' + (Math.abs(expectedBarChartData[y] - paths[y]) < barHeightTolerance) + '\n';
if ((Math.abs(expectedBarChartData[y] - paths[y]) > barHeightTolerance)) {
hasFailure = true;
};
Expand Down
140 changes: 140 additions & 0 deletions test/functional/apps/discover/_shared_links.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
define(function (require) {
var Common = require('../../../support/pages/Common');
var HeaderPage = require('../../../support/pages/HeaderPage');
var SettingsPage = require('../../../support/pages/settings_page');
var DiscoverPage = require('../../../support/pages/DiscoverPage');
var expect = require('intern/dojo/node!expect.js');

return function (bdd, scenarioManager) {
bdd.describe('shared links', function describeIndexTests() {
var common;
var headerPage;
var settingsPage;
var discoverPage;
var baseUrl;
// The message changes for Firefox < 41 and Firefox >= 41
// var expectedToastMessage = 'Share search: URL selected. Press Ctrl+C to copy.';
// var expectedToastMessage = 'Share search: URL copied to clipboard.';
// Pass either one.
var expectedToastMessage = /Share search: URL (selected. Press Ctrl+C to copy.|copied to clipboard.)/;

bdd.before(function () {
common = new Common(this.remote);
headerPage = new HeaderPage(this.remote);
settingsPage = new SettingsPage(this.remote);
discoverPage = new DiscoverPage(this.remote);

baseUrl = common.getHostPort();

var fromTime = '2015-09-19 06:31:44.000';
var toTime = '2015-09-23 18:31:44.000';

// start each test with an empty kibana index
return scenarioManager.reload('emptyKibana')
// and load a set of makelogs data
.then(function loadIfEmptyMakelogs() {
return scenarioManager.loadIfEmpty('logstashFunctional');
})
.then(function (navigateTo) {
common.debug('navigateTo');
return settingsPage.navigateTo();
})
.then(function () {
common.debug('createIndexPattern');
return settingsPage.createIndexPattern();
})
.then(function () {
common.debug('discover');
return common.navigateToApp('discover');
})
.then(function () {
common.debug('setAbsoluteRange');
return headerPage.setAbsoluteRange(fromTime, toTime);
})
.catch(common.handleError(this));
});


bdd.describe('shared link', function () {

bdd.it('should show "Share a link" caption', function () {
var expectedCaption = 'Share a link';
return discoverPage.clickShare()
.then(function () {
return discoverPage.getShareCaption();
})
.then(function (actualCaption) {
expect(actualCaption).to.be(expectedCaption);
})
.catch(common.handleError(this));
});


bdd.it('should show the correct formatted URL', function () {
var expectedUrl = baseUrl
+ '/app/kibana?_t=1453775307251#'
+ '/discover?_g=(refreshInterval:(display:Off,pause:!f,value:0),time'
+ ':(from:%272015-09-19T06:31:44.000Z%27,mode:absolute,to:%272015-09'
+ '-23T18:31:44.000Z%27))&_a=(columns:!(_source),index:%27logstash-'
+ '*%27,interval:auto,query:(query_string:(analyze_wildcard:!t,query'
+ ':%27*%27)),sort:!(%27@timestamp%27,desc))';
return discoverPage.getSharedUrl()
.then(function (actualUrl) {
// strip the timestamp out of each URL
expect(actualUrl.replace(/_t=\d{13}/,'_t=TIMESTAMP'))

.to.be(expectedUrl.replace(/_t=\d{13}/,'_t=TIMESTAMP'));
})
.catch(common.handleError(this));
});

bdd.it('should show toast message for copy to clipboard', function () {
return discoverPage.clickCopyToClipboard()
.then(function () {
return headerPage.getToastMessage();
})
.then(function (toastMessage) {
expect(toastMessage).to.match(expectedToastMessage);
})
.then(function () {
return headerPage.waitForToastMessageGone();
})
.catch(common.handleError(this));
});

// TODO: verify clipboard contents

bdd.it('shorten URL button should produce a short URL', function () {
var re = new RegExp(baseUrl + '/goto/[0-9a-f]{32}$');
return discoverPage.clickShortenUrl()
.then(function () {
return common.tryForTime(20 * 1000, function tryingForTime() {
return discoverPage.getShortenedUrl()
.then(function (actualUrl) {
expect(actualUrl).to.match(re);
});
});
})
.catch(common.handleError(this));
});

// NOTE: This test has to run immediately after the test above
bdd.it('should show toast message for copy to clipboard', function () {
return discoverPage.clickCopyToClipboard()
.then(function () {
return headerPage.getToastMessage();
})
.then(function (toastMessage) {
expect(toastMessage).to.match(expectedToastMessage);
})
.then(function () {
return headerPage.waitForToastMessageGone();
})
.catch(common.handleError(this));
});


});
});
};
});
3 changes: 3 additions & 0 deletions test/functional/apps/discover/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ define(function (require) {
var ScenarioManager = require('intern/dojo/node!../../../fixtures/scenarioManager');
var discoverTest = require('./_discover');
var fieldData = require('./_field_data');
var sharedLinks = require('./_shared_links');

bdd.describe('discover app', function () {
var scenarioManager;
Expand All @@ -25,5 +26,7 @@ define(function (require) {

fieldData(bdd, scenarioManager);

sharedLinks(bdd, scenarioManager);

});
});
4 changes: 4 additions & 0 deletions test/support/pages/Common.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ define(function (require) {
Common.prototype = {
constructor: Common,

getHostPort: function getHostPort() {
return getUrl.baseUrl(config.servers.kibana);
},

navigateToApp: function (appName, testStatusPage) {
var self = this;
// navUrl includes user:password@ for use with Shield
Expand Down
36 changes: 36 additions & 0 deletions test/support/pages/DiscoverPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,42 @@ define(function (require) {
return thisTime
.findAllByCssSelector('mark')
.getVisibleText();
},

clickShare: function clickShare() {
return thisTime
.findByCssSelector('button[aria-label="Share Search"]')
.click();
},

clickShortenUrl: function clickShortenUrl() {
return thisTime
.findByCssSelector('button.shorten-button')
.click();
},

clickCopyToClipboard: function clickCopyToClipboard() {
return thisTime
.findByCssSelector('button.clipboard-button')
.click();
},

getShareCaption: function getShareCaption() {
return thisTime
.findByCssSelector('div.form-group > label')
.getVisibleText();
},

getSharedUrl: function getSharedUrl() {
return thisTime
.findByCssSelector('.url')
.getProperty('baseURI');
},

getShortenedUrl: function getShortenedUrl() {
return thisTime
.findByCssSelector('.url')
.getProperty('value');
}

};
Expand Down
7 changes: 6 additions & 1 deletion test/utils/getUrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ var url = require('url');
* {
* protocol: 'http',
* hostname: 'localhost',
* port: 9220
* port: 9220,
* auth: shield.kibanaUser.username + ':' + shield.kibanaUser.password
* }
* @param {object} app The params to append
* example:
Expand All @@ -31,3 +32,7 @@ getUrl.noAuth = function getUrlNoAuth(config, app) {
});
return getUrl(config, app);
};

getUrl.baseUrl = function getBaseUrl(config) {
return url.format(_.pick(config, 'protocol', 'hostname', 'port'));
};