Skip to content

Commit

Permalink
Conversion to ES6 - Discover tests (#20112) (#20155)
Browse files Browse the repository at this point in the history
Discover Tests conversion to ES6
  • Loading branch information
rashmivkulkarni authored Jun 22, 2018
1 parent a1b5a56 commit 09a0ffe
Show file tree
Hide file tree
Showing 7 changed files with 357 additions and 267 deletions.
79 changes: 33 additions & 46 deletions test/functional/apps/discover/_collapse_expand.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,64 +26,51 @@ export default function ({ getService, getPageObjects }) {
const PageObjects = getPageObjects(['common', 'discover', 'header']);

describe('discover tab', function describeIndexTests() {
before(function () {
before(async function () {
const fromTime = '2015-09-19 06:31:44.000';
const toTime = '2015-09-23 18:31:44.000';

// delete .kibana index and update configDoc
return kibanaServer.uiSettings.replace({
await kibanaServer.uiSettings.replace({
'dateFormat:tz': 'UTC',
'defaultIndex': 'logstash-*'
})
.then(function loadkibanaIndexPattern() {
log.debug('load kibana index with default index pattern');
return esArchiver.load('discover');
})
defaultIndex: 'logstash-*',
});

log.debug('load kibana index with default index pattern');
await esArchiver.load('discover');

// and load a set of makelogs data
.then(function loadIfEmptyMakelogs() {
return esArchiver.loadIfNeeded('logstash_functional');
})
.then(function () {
log.debug('discover');
return PageObjects.common.navigateToApp('discover');
})
.then(function () {
log.debug('setAbsoluteRange');
return PageObjects.header.setAbsoluteRange(fromTime, toTime);
});
await esArchiver.loadIfNeeded('logstash_functional');

log.debug('discover');
await PageObjects.common.navigateToApp('discover');

log.debug('setAbsoluteRange');
await PageObjects.header.setAbsoluteRange(fromTime, toTime);
});

describe('field data', function () {
it('should initially be expanded', function () {
return PageObjects.discover.getSidebarWidth()
.then(function (width) {
log.debug('expanded sidebar width = ' + width);
expect(width > 20).to.be(true);
});
describe('collapse expand', function () {
it('should initially be expanded', async function () {
const width = await PageObjects.discover.getSidebarWidth();
log.debug('expanded sidebar width = ' + width);
expect(width > 20).to.be(true);
});

it('should collapse when clicked', function () {
return PageObjects.discover.toggleSidebarCollapse()
.then(function () {
log.debug('PageObjects.discover.getSidebarWidth()');
return PageObjects.discover.getSidebarWidth();
})
.then(function (width) {
log.debug('collapsed sidebar width = ' + width);
expect(width < 20).to.be(true);
});
it('should collapse when clicked', async function () {
await PageObjects.discover.toggleSidebarCollapse();
log.debug('PageObjects.discover.getSidebarWidth()');
const width = await PageObjects.discover.getSidebarWidth();
log.debug('collapsed sidebar width = ' + width);
expect(width < 20).to.be(true);
});

it('should expand when clicked', function () {
return PageObjects.discover.toggleSidebarCollapse()
.then(function () {
log.debug('PageObjects.discover.getSidebarWidth()');
return PageObjects.discover.getSidebarWidth();
})
.then(function (width) {
log.debug('expanded sidebar width = ' + width);
expect(width > 20).to.be(true);
});
it('should expand when clicked', async function () {
await PageObjects.discover.toggleSidebarCollapse();

log.debug('PageObjects.discover.getSidebarWidth()');
const width = await PageObjects.discover.getSidebarWidth();
log.debug('expanded sidebar width = ' + width);
expect(width > 20).to.be(true);
});
});
});
Expand Down
184 changes: 160 additions & 24 deletions test/functional/apps/discover/_discover.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default function ({ getService, getPageObjects }) {
const PageObjects = getPageObjects(['common', 'discover', 'header']);
const defaultSettings = {
'dateFormat:tz': 'UTC',
'defaultIndex': 'logstash-*'
defaultIndex: 'logstash-*',
};

describe('discover app', function describeIndexTests() {
Expand Down Expand Up @@ -73,20 +73,48 @@ export default function ({ getService, getPageObjects }) {
await PageObjects.discover.loadSavedSearch(queryName1);

await retry.try(async function () {
expect(await PageObjects.discover.getCurrentQueryName()).to.be(queryName1);
expect(await PageObjects.discover.getCurrentQueryName()).to.be(
queryName1
);
});
});

it('should show the correct hit count', async function () {
const expectedHitCount = '14,004';
await retry.try(async function () {
expect(await PageObjects.discover.getHitCount()).to.be(expectedHitCount);
expect(await PageObjects.discover.getHitCount()).to.be(
expectedHitCount
);
});
});

it('should show the correct bar chart', async function () {
const expectedBarChartData = [ 35, 189, 694, 1347, 1285, 704, 176, 29, 39, 189, 640,
1276, 1327, 663, 166, 25, 30, 164, 663, 1320, 1270, 681, 188, 27 ];
const expectedBarChartData = [
35,
189,
694,
1347,
1285,
704,
176,
29,
39,
189,
640,
1276,
1327,
663,
166,
25,
30,
164,
663,
1320,
1270,
681,
188,
27,
];
await verifyChartData(expectedBarChartData);
});

Expand All @@ -107,16 +135,86 @@ export default function ({ getService, getPageObjects }) {
it('should show correct data for chart interval Hourly', async function () {
await PageObjects.discover.setChartInterval('Hourly');

const expectedBarChartData = [ 4, 7, 16, 23, 38, 87, 132, 159, 248, 320, 349, 376, 380,
324, 293, 233, 188, 125, 69, 40, 28, 17, 2, 3, 8, 10, 12, 28, 36, 84, 111, 157, 229, 292,
324, 373, 378, 345, 306, 223, 167, 124, 72, 35, 22, 11, 7, 1, 6, 5, 12, 25, 27, 76, 111, 175,
228, 294, 358, 372, 366, 344, 276, 213, 201, 113, 72, 39, 36, 12, 7, 3 ];
const expectedBarChartData = [
4,
7,
16,
23,
38,
87,
132,
159,
248,
320,
349,
376,
380,
324,
293,
233,
188,
125,
69,
40,
28,
17,
2,
3,
8,
10,
12,
28,
36,
84,
111,
157,
229,
292,
324,
373,
378,
345,
306,
223,
167,
124,
72,
35,
22,
11,
7,
1,
6,
5,
12,
25,
27,
76,
111,
175,
228,
294,
358,
372,
366,
344,
276,
213,
201,
113,
72,
39,
36,
12,
7,
3,
];
await verifyChartData(expectedBarChartData);
});

it('should show correct data for chart interval Daily', async function () {
const chartInterval = 'Daily';
const expectedBarChartData = [ 4757, 4614, 4633 ];
const expectedBarChartData = [4757, 4614, 4633];
await PageObjects.discover.setChartInterval(chartInterval);
await retry.try(async () => {
await verifyChartData(expectedBarChartData);
Expand All @@ -125,7 +223,7 @@ export default function ({ getService, getPageObjects }) {

it('should show correct data for chart interval Weekly', async function () {
const chartInterval = 'Weekly';
const expectedBarChartData = [ 4757, 9247 ];
const expectedBarChartData = [4757, 9247];

await PageObjects.discover.setChartInterval(chartInterval);
await retry.try(async () => {
Expand All @@ -135,7 +233,7 @@ export default function ({ getService, getPageObjects }) {

it('browser back button should show previous interval Daily', async function () {
const expectedChartInterval = 'Daily';
const expectedBarChartData = [ 4757, 4614, 4633 ];
const expectedBarChartData = [4757, 4614, 4633];

await remote.goBack();
await retry.try(async function tryingForTime() {
Expand All @@ -147,24 +245,48 @@ export default function ({ getService, getPageObjects }) {

it('should show correct data for chart interval Monthly', async function () {
const chartInterval = 'Monthly';
const expectedBarChartData = [ 13129 ];
const expectedBarChartData = [13129];

await PageObjects.discover.setChartInterval(chartInterval);
await verifyChartData(expectedBarChartData);
});

it('should show correct data for chart interval Yearly', async function () {
const chartInterval = 'Yearly';
const expectedBarChartData = [ 13129 ];
const expectedBarChartData = [13129];

await PageObjects.discover.setChartInterval(chartInterval);
await verifyChartData(expectedBarChartData);
});

it('should show correct data for chart interval Auto', async function () {
const chartInterval = 'Auto';
const expectedBarChartData = [ 35, 189, 694, 1347, 1285, 704, 176, 29, 39, 189,
640, 1276, 1327, 663, 166, 25, 30, 164, 663, 1320, 1270, 681, 188, 27 ];
const expectedBarChartData = [
35,
189,
694,
1347,
1285,
704,
176,
29,
39,
189,
640,
1276,
1327,
663,
166,
25,
30,
164,
663,
1320,
1270,
681,
188,
27,
];

await PageObjects.discover.setChartInterval(chartInterval);
await verifyChartData(expectedBarChartData);
Expand All @@ -190,9 +312,19 @@ export default function ({ getService, getPageObjects }) {
let stringResults = '';
let hasFailure = false;
for (let 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)) {
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;
}
}
Expand All @@ -201,7 +333,9 @@ export default function ({ getService, getPageObjects }) {
log.debug(paths);
}
for (let x = 0; x < expectedBarChartData.length; x++) {
expect(Math.abs(expectedBarChartData[x] - paths[x]) < barHeightTolerance).to.be.ok();
expect(
Math.abs(expectedBarChartData[x] - paths[x]) < barHeightTolerance
).to.be.ok();
}
});
}
Expand All @@ -213,8 +347,7 @@ export default function ({ getService, getPageObjects }) {

before(() => {
log.debug('setAbsoluteRangeForAnotherQuery');
return PageObjects.header
.setAbsoluteRange(fromTime, toTime);
return PageObjects.header.setAbsoluteRange(fromTime, toTime);
});

it('should show "no results"', async () => {
Expand Down Expand Up @@ -257,12 +390,15 @@ export default function ({ getService, getPageObjects }) {
it('should have correct data-shared-item title and description', async () => {
const expected = {
title: 'A Saved Search',
description: 'A Saved Search Description'
description: 'A Saved Search Description',
};

await retry.try(async () => {
await PageObjects.discover.loadSavedSearch(expected.title);
const { title, description } = await PageObjects.common.getSharedItemTitleAndDescription();
const {
title,
description,
} = await PageObjects.common.getSharedItemTitleAndDescription();
expect(title).to.eql(expected.title);
expect(description).to.eql(expected.description);
});
Expand Down
4 changes: 3 additions & 1 deletion test/functional/apps/discover/_errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ export default function ({ getService, getPageObjects }) {

describe('invalid scripted field error', () => {
it('is rendered', async () => {
const isFetchErrorVisible = await testSubjects.exists('discoverFetchError');
const isFetchErrorVisible = await testSubjects.exists(
'discoverFetchError'
);
expect(isFetchErrorVisible).to.be(true);
});
});
Expand Down
Loading

0 comments on commit 09a0ffe

Please sign in to comment.