mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
Improve readability of some functional tests
Consistently use async/await and bring tests more in line with "Arrange, Act, Assert".
This commit is contained in:
parent
ab5f6cbd31
commit
db775687f2
1 changed files with 115 additions and 171 deletions
|
@ -11,120 +11,90 @@ import {
|
|||
import PageObjects from '../../../support/page_objects';
|
||||
|
||||
bdd.describe('discover app', function describeIndexTests() {
|
||||
bdd.before(function () {
|
||||
var fromTime = '2015-09-19 06:31:44.000';
|
||||
var toTime = '2015-09-23 18:31:44.000';
|
||||
var fromTime = '2015-09-19 06:31:44.000';
|
||||
var fromTimeString = 'September 19th 2015, 06:31:44.000';
|
||||
var toTime = '2015-09-23 18:31:44.000';
|
||||
var toTimeString = 'September 23rd 2015, 18:31:44.000';
|
||||
|
||||
bdd.before(async function () {
|
||||
// delete .kibana index and update configDoc
|
||||
return esClient.deleteAndUpdateConfigDoc({'dateFormat:tz':'UTC', 'defaultIndex':'logstash-*'})
|
||||
.then(function loadkibanaIndexPattern() {
|
||||
PageObjects.common.debug('load kibana index with default index pattern');
|
||||
return elasticDump.elasticLoad('visualize','.kibana');
|
||||
})
|
||||
// and load a set of makelogs data
|
||||
.then(function loadIfEmptyMakelogs() {
|
||||
return scenarioManager.loadIfEmpty('logstashFunctional');
|
||||
})
|
||||
.then(function () {
|
||||
PageObjects.common.debug('discover');
|
||||
return PageObjects.common.navigateToApp('discover');
|
||||
})
|
||||
.then(function () {
|
||||
PageObjects.common.debug('setAbsoluteRange');
|
||||
return PageObjects.header.setAbsoluteRange(fromTime, toTime);
|
||||
});
|
||||
});
|
||||
await esClient.deleteAndUpdateConfigDoc({'dateFormat:tz':'UTC', 'defaultIndex':'logstash-*'});
|
||||
PageObjects.common.debug('load kibana index with default index pattern');
|
||||
await elasticDump.elasticLoad('visualize','.kibana');
|
||||
|
||||
// and load a set of makelogs data
|
||||
await scenarioManager.loadIfEmpty('logstashFunctional');
|
||||
PageObjects.common.debug('discover');
|
||||
await PageObjects.common.navigateToApp('discover');
|
||||
PageObjects.common.debug('setAbsoluteRange');
|
||||
await PageObjects.header.setAbsoluteRange(fromTime, toTime);
|
||||
});
|
||||
|
||||
bdd.describe('query', function () {
|
||||
var queryName1 = 'Query # 1';
|
||||
var fromTimeString = 'September 19th 2015, 06:31:44.000';
|
||||
var toTimeString = 'September 23rd 2015, 18:31:44.000';
|
||||
|
||||
bdd.it('should show correct time range string by timepicker', function () {
|
||||
var expectedTimeRangeString = fromTimeString + ' to ' + toTimeString;
|
||||
return PageObjects.discover.getTimespanText()
|
||||
.then(function (actualTimeString) {
|
||||
expect(actualTimeString).to.be(expectedTimeRangeString);
|
||||
});
|
||||
bdd.it('should show correct time range string by timepicker', async function () {
|
||||
var actualTimeString = await PageObjects.discover.getTimespanText();
|
||||
|
||||
expect(actualTimeString).to.be(`${fromTimeString} to ${toTimeString}`);
|
||||
});
|
||||
|
||||
bdd.it('save query should show toast message and display query name', function () {
|
||||
var expectedSavedQueryMessage = 'Discover: Saved Data Source "' + queryName1 + '"';
|
||||
return PageObjects.discover.saveSearch(queryName1)
|
||||
.then(function () {
|
||||
return PageObjects.header.getToastMessage();
|
||||
})
|
||||
.then(function (toastMessage) {
|
||||
PageObjects.common.saveScreenshot('Discover-save-query-toast');
|
||||
expect(toastMessage).to.be(expectedSavedQueryMessage);
|
||||
})
|
||||
.then(function () {
|
||||
return PageObjects.header.waitForToastMessageGone();
|
||||
})
|
||||
.then(function () {
|
||||
return PageObjects.discover.getCurrentQueryName();
|
||||
})
|
||||
.then(function (actualQueryNameString) {
|
||||
expect(actualQueryNameString).to.be(queryName1);
|
||||
});
|
||||
bdd.it('save query should show toast message and display query name', async function () {
|
||||
await PageObjects.discover.saveSearch(queryName1);
|
||||
var toastMessage = await PageObjects.header.getToastMessage();
|
||||
await PageObjects.common.saveScreenshot('Discover-save-query-toast');
|
||||
|
||||
expect(toastMessage).to.be(`Discover: Saved Data Source "${queryName1}"`);
|
||||
|
||||
await PageObjects.header.waitForToastMessageGone();
|
||||
var actualQueryNameString = await PageObjects.discover.getCurrentQueryName();
|
||||
|
||||
expect(actualQueryNameString).to.be(queryName1);
|
||||
});
|
||||
|
||||
bdd.it('load query should show query name', function () {
|
||||
return PageObjects.discover.loadSavedSearch(queryName1)
|
||||
.then(function () {
|
||||
return PageObjects.common.sleep(3000);
|
||||
})
|
||||
.then(function () {
|
||||
return PageObjects.discover.getCurrentQueryName();
|
||||
})
|
||||
.then(function (actualQueryNameString) {
|
||||
PageObjects.common.saveScreenshot('Discover-load-query');
|
||||
expect(actualQueryNameString).to.be(queryName1);
|
||||
});
|
||||
bdd.it('load query should show query name', async function () {
|
||||
await PageObjects.discover.loadSavedSearch(queryName1);
|
||||
await PageObjects.common.sleep(3000);
|
||||
|
||||
var actualQueryNameString = await PageObjects.discover.getCurrentQueryName();
|
||||
await PageObjects.common.saveScreenshot('Discover-load-query');
|
||||
expect(actualQueryNameString).to.be(queryName1);
|
||||
});
|
||||
|
||||
bdd.it('should show the correct hit count', function () {
|
||||
var expectedHitCount = '14,004';
|
||||
return PageObjects.common.try(function tryingForTime() {
|
||||
return PageObjects.discover.getHitCount()
|
||||
.then(function compareData(hitCount) {
|
||||
expect(hitCount).to.be(expectedHitCount);
|
||||
});
|
||||
});
|
||||
bdd.it('should show the correct hit count', async function () {
|
||||
var hitCount = await PageObjects.discover.getHitCount();
|
||||
|
||||
expect(hitCount).to.be('14,004');
|
||||
});
|
||||
|
||||
bdd.it('should show the correct bar chart', function () {
|
||||
bdd.it('should show the correct bar chart', async function () {
|
||||
await PageObjects.common.sleep(4000);
|
||||
|
||||
var expectedBarChartData = [ '3.237',
|
||||
'17.674', '64.75', '125.737', '119.962', '65.712', '16.449',
|
||||
'2.712', '3.675', '17.674', '59.762', '119.087', '123.812',
|
||||
'61.862', '15.487', '2.362', '2.800', '15.312', '61.862', '123.2',
|
||||
'118.562', '63.524', '17.587', '2.537'
|
||||
];
|
||||
return PageObjects.common.sleep(4000)
|
||||
.then(function () {
|
||||
return verifyChartData(expectedBarChartData);
|
||||
});
|
||||
await verifyChartData(expectedBarChartData);
|
||||
});
|
||||
|
||||
bdd.it('should show correct time range string in chart', function () {
|
||||
var expectedTimeRangeString = fromTimeString + ' - ' + toTimeString;
|
||||
return PageObjects.discover.getChartTimespan()
|
||||
.then(function (actualTimeString) {
|
||||
expect(actualTimeString).to.be(expectedTimeRangeString);
|
||||
});
|
||||
bdd.it('should show correct time range string in chart', async function () {
|
||||
var actualTimeString = await PageObjects.discover.getChartTimespan();
|
||||
|
||||
expect(actualTimeString).to.be(`${fromTimeString} - ${toTimeString}`);
|
||||
});
|
||||
|
||||
bdd.it('should show correct initial chart interval of 3 hours', function () {
|
||||
var expectedChartInterval = 'by 3 hours';
|
||||
return PageObjects.discover.getChartInterval()
|
||||
.then(function (actualInterval) {
|
||||
expect(actualInterval).to.be(expectedChartInterval);
|
||||
});
|
||||
bdd.it('should show correct initial chart interval of 3 hours', async function () {
|
||||
var actualInterval = await PageObjects.discover.getChartInterval();
|
||||
|
||||
expect(actualInterval).to.be('by 3 hours');
|
||||
});
|
||||
|
||||
bdd.it('should show correct data for chart interval Hourly', function () {
|
||||
var chartInterval = 'Hourly';
|
||||
bdd.it('should show correct data for chart interval Hourly', async function () {
|
||||
await PageObjects.discover.setChartInterval('Hourly');
|
||||
await PageObjects.common.sleep(4000);
|
||||
|
||||
var expectedBarChartData = [ '1.527', '2.290',
|
||||
'5.599', '7.890', '13.236', '30.290', '46.072', '55.490', '86.8',
|
||||
'112', '122.181', '131.6', '132.872', '113.527', '102.581',
|
||||
|
@ -138,13 +108,7 @@ bdd.describe('discover app', function describeIndexTests() {
|
|||
'120.4', '96.472', '74.581', '70.509', '39.709', '25.199', '13.490',
|
||||
'12.472', '4.072', '2.290', '1.018'
|
||||
];
|
||||
return PageObjects.discover.setChartInterval(chartInterval)
|
||||
.then(function () {
|
||||
return PageObjects.common.sleep(4000);
|
||||
})
|
||||
.then(function () {
|
||||
return verifyChartData(expectedBarChartData);
|
||||
});
|
||||
await verifyChartData(expectedBarChartData);
|
||||
});
|
||||
|
||||
bdd.it('should show correct data for chart interval Daily', async function () {
|
||||
|
@ -161,56 +125,46 @@ bdd.describe('discover app', function describeIndexTests() {
|
|||
bdd.it('should show correct data for chart interval Weekly', async function () {
|
||||
var chartInterval = 'Weekly';
|
||||
var expectedBarChartData = [ '66.598', '129.458'];
|
||||
|
||||
await PageObjects.discover.setChartInterval(chartInterval);
|
||||
await PageObjects.common.try(async () => {
|
||||
await verifyChartData(expectedBarChartData);
|
||||
});
|
||||
});
|
||||
|
||||
bdd.it('browser back button should show previous interval Daily', function () {
|
||||
bdd.it('browser back button should show previous interval Daily', async function () {
|
||||
var expectedChartInterval = 'Daily';
|
||||
var expectedBarChartData = [
|
||||
'133.196', '129.192', '129.724'
|
||||
];
|
||||
return this.remote.goBack()
|
||||
.then(function () {
|
||||
return PageObjects.common.try(function tryingForTime() {
|
||||
return PageObjects.discover.getChartInterval()
|
||||
.then(function (actualInterval) {
|
||||
expect(actualInterval).to.be(expectedChartInterval);
|
||||
});
|
||||
});
|
||||
})
|
||||
.then(function () {
|
||||
return verifyChartData(expectedBarChartData);
|
||||
|
||||
await this.remote.goBack();
|
||||
await PageObjects.common.try(async function tryingForTime() {
|
||||
var actualInterval = await PageObjects.discover.getChartInterval();
|
||||
expect(actualInterval).to.be(expectedChartInterval);
|
||||
});
|
||||
await verifyChartData(expectedBarChartData);
|
||||
});
|
||||
|
||||
bdd.it('should show correct data for chart interval Monthly', function () {
|
||||
bdd.it('should show correct data for chart interval Monthly', async function () {
|
||||
var chartInterval = 'Monthly';
|
||||
var expectedBarChartData = [ '122.535'];
|
||||
return PageObjects.discover.setChartInterval(chartInterval)
|
||||
.then(function () {
|
||||
return PageObjects.common.sleep(2000);
|
||||
})
|
||||
.then(function () {
|
||||
return verifyChartData(expectedBarChartData);
|
||||
});
|
||||
|
||||
await PageObjects.discover.setChartInterval(chartInterval);
|
||||
await PageObjects.common.sleep(2000);
|
||||
await verifyChartData(expectedBarChartData);
|
||||
});
|
||||
|
||||
bdd.it('should show correct data for chart interval Yearly', function () {
|
||||
bdd.it('should show correct data for chart interval Yearly', async function () {
|
||||
var chartInterval = 'Yearly';
|
||||
var expectedBarChartData = [ '122.535'];
|
||||
return PageObjects.discover.setChartInterval(chartInterval)
|
||||
.then(function () {
|
||||
return PageObjects.common.sleep(2000);
|
||||
})
|
||||
.then(function () {
|
||||
return verifyChartData(expectedBarChartData);
|
||||
});
|
||||
|
||||
await PageObjects.discover.setChartInterval(chartInterval);
|
||||
await PageObjects.common.sleep(2000);
|
||||
await verifyChartData(expectedBarChartData);
|
||||
});
|
||||
|
||||
bdd.it('should show correct data for chart interval Auto', function () {
|
||||
bdd.it('should show correct data for chart interval Auto', async function () {
|
||||
var chartInterval = 'Auto';
|
||||
var expectedBarChartData = [ '3.237',
|
||||
'17.674', '64.75', '125.737', '119.962', '65.712', '16.449',
|
||||
|
@ -218,54 +172,46 @@ bdd.describe('discover app', function describeIndexTests() {
|
|||
'61.862', '15.487', '2.362', '2.800', '15.312', '61.862', '123.2',
|
||||
'118.562', '63.524', '17.587', '2.537'
|
||||
];
|
||||
return PageObjects.discover.setChartInterval(chartInterval)
|
||||
.then(function () {
|
||||
return PageObjects.common.sleep(4000);
|
||||
})
|
||||
.then(function () {
|
||||
return verifyChartData(expectedBarChartData);
|
||||
});
|
||||
|
||||
await PageObjects.discover.setChartInterval(chartInterval);
|
||||
await PageObjects.common.sleep(4000);
|
||||
await verifyChartData(expectedBarChartData);
|
||||
});
|
||||
|
||||
bdd.it('should show Auto chart interval of 3 hours', function () {
|
||||
bdd.it('should show Auto chart interval of 3 hours', async function () {
|
||||
var expectedChartInterval = 'by 3 hours';
|
||||
return PageObjects.discover.getChartInterval()
|
||||
.then(function (actualInterval) {
|
||||
expect(actualInterval).to.be(expectedChartInterval);
|
||||
});
|
||||
|
||||
var actualInterval = await PageObjects.discover.getChartInterval();
|
||||
expect(actualInterval).to.be(expectedChartInterval);
|
||||
});
|
||||
|
||||
bdd.it('should not show "no results"', () => {
|
||||
return PageObjects.discover.hasNoResults().then(visible => {
|
||||
expect(visible).to.be(false);
|
||||
});
|
||||
bdd.it('should not show "no results"', async () => {
|
||||
var isVisible = await PageObjects.discover.hasNoResults();
|
||||
expect(isVisible).to.be(false);
|
||||
});
|
||||
|
||||
function verifyChartData(expectedBarChartData) {
|
||||
return PageObjects.common.try(function tryingForTime() {
|
||||
return PageObjects.discover.getBarChartData()
|
||||
.then(function compareData(paths) {
|
||||
// the largest bars are over 100 pixels high so this is less than 1% tolerance
|
||||
var barHeightTolerance = 1;
|
||||
var stringResults = '';
|
||||
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) + '\n';
|
||||
if ((Math.abs(expectedBarChartData[y] - paths[y]) > barHeightTolerance)) {
|
||||
hasFailure = true;
|
||||
};
|
||||
async function verifyChartData(expectedBarChartData) {
|
||||
await PageObjects.common.try(async function tryingForTime() {
|
||||
var paths = await PageObjects.discover.getBarChartData();
|
||||
// the largest bars are over 100 pixels high so this is less than 1% tolerance
|
||||
var barHeightTolerance = 1;
|
||||
var stringResults = '';
|
||||
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) + '\n';
|
||||
if ((Math.abs(expectedBarChartData[y] - paths[y]) > barHeightTolerance)) {
|
||||
hasFailure = true;
|
||||
};
|
||||
if (hasFailure) {
|
||||
PageObjects.common.log(stringResults);
|
||||
PageObjects.common.log(paths);
|
||||
}
|
||||
for (var x = 0; x < expectedBarChartData.length; x++) {
|
||||
expect(Math.abs(expectedBarChartData[x] - paths[x]) < barHeightTolerance).to.be.ok();
|
||||
}
|
||||
});
|
||||
};
|
||||
if (hasFailure) {
|
||||
PageObjects.common.log(stringResults);
|
||||
PageObjects.common.log(paths);
|
||||
}
|
||||
for (var x = 0; x < expectedBarChartData.length; x++) {
|
||||
expect(Math.abs(expectedBarChartData[x] - paths[x]) < barHeightTolerance).to.be.ok();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
@ -280,17 +226,15 @@ bdd.describe('discover app', function describeIndexTests() {
|
|||
.setAbsoluteRange(fromTime, toTime);
|
||||
});
|
||||
|
||||
bdd.it('should show "no results"', () => {
|
||||
return PageObjects.discover.hasNoResults().then(visible => {
|
||||
PageObjects.common.saveScreenshot('Discover-no-results');
|
||||
expect(visible).to.be(true);
|
||||
});
|
||||
bdd.it('should show "no results"', async () => {
|
||||
var isVisible = await PageObjects.discover.hasNoResults();
|
||||
await PageObjects.common.saveScreenshot('Discover-no-results');
|
||||
expect(isVisible).to.be(true);
|
||||
});
|
||||
|
||||
bdd.it('should suggest a new time range is picked', () => {
|
||||
return PageObjects.discover.hasNoResultsTimepicker().then(visible => {
|
||||
expect(visible).to.be(true);
|
||||
});
|
||||
bdd.it('should suggest a new time range is picked', async () => {
|
||||
var isVisible = await PageObjects.discover.hasNoResultsTimepicker();
|
||||
expect(isVisible).to.be(true);
|
||||
});
|
||||
|
||||
bdd.it('should open and close the time picker', () => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue