Skip to content

Commit

Permalink
fixing date_histogram to correctly work inside plugins without global…
Browse files Browse the repository at this point in the history
… time picker (#21955)
  • Loading branch information
ppisljar authored Aug 22, 2018
1 parent 4d9bc2f commit c38e948
Show file tree
Hide file tree
Showing 8 changed files with 476 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/ui/public/agg_types/buckets/date_histogram.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function getInterval(agg) {
}

function getBounds(vis) {
if (vis.API.timeFilter.isTimeRangeSelectorEnabled && vis.filters && vis.filters.timeRange) {
if (vis.filters && vis.filters.timeRange) {
return vis.API.timeFilter.calculateBounds(vis.filters.timeRange);
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/functional/apps/visualize/_data_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default function ({ getService, getPageObjects }) {
expect(isApplyButtonEnabled).to.be(true);
});

it('should allow resseting changed params', async () => {
it('should allow reseting changed params', async () => {
await PageObjects.visualize.clickReset();
const interval = await PageObjects.visualize.getInputTypeParam('interval');
expect(interval).to.be('2000');
Expand Down
177 changes: 177 additions & 0 deletions test/functional/apps/visualize/_data_table_nontimeindex.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import expect from 'expect.js';

export default function ({ getService, getPageObjects }) {
const log = getService('log');
const retry = getService('retry');
const filterBar = getService('filterBar');
const renderable = getService('renderable');
const PageObjects = getPageObjects(['common', 'visualize', 'header']);

describe('data table with index without time filter', function indexPatternCreation() {
const vizName1 = 'Visualization DataTable without time filter';

before(async function () {
log.debug('navigateToApp visualize');
await PageObjects.visualize.navigateToNewVisualization();
log.debug('clickDataTable');
await PageObjects.visualize.clickDataTable();
log.debug('clickNewSearch');
await PageObjects.visualize.clickNewSearch(PageObjects.visualize.index.LOGSTASH_NON_TIME_BASED);
log.debug('Bucket = Split Rows');
await PageObjects.common.sleep(500);
await PageObjects.visualize.clickBucket('Split Rows');
log.debug('Aggregation = Histogram');
await PageObjects.visualize.selectAggregation('Histogram');
log.debug('Field = bytes');
await PageObjects.visualize.selectField('bytes');
log.debug('Interval = 2000');
await PageObjects.visualize.setNumericInterval('2000');
await PageObjects.visualize.clickGo();
});

it('should allow applying changed params', async () => {
await PageObjects.visualize.setNumericInterval('1', { append: true });
const interval = await PageObjects.visualize.getInputTypeParam('interval');
expect(interval).to.be('20001');
const isApplyButtonEnabled = await PageObjects.visualize.isApplyEnabled();
expect(isApplyButtonEnabled).to.be(true);
});

it('should allow reseting changed params', async () => {
await PageObjects.visualize.clickReset();
const interval = await PageObjects.visualize.getInputTypeParam('interval');
expect(interval).to.be('2000');
});

it('should be able to save and load', async function () {
await PageObjects.visualize.saveVisualization(vizName1);
const pageTitle = await PageObjects.common.getBreadcrumbPageTitle();
log.debug(`Save viz page title is ${pageTitle}`);
expect(pageTitle).to.contain(vizName1);
await PageObjects.visualize.waitForVisualizationSavedToastGone();
await PageObjects.visualize.loadSavedVisualization(vizName1);
await PageObjects.visualize.waitForVisualization();
});

it('should have inspector enabled', async function () {
const spyToggleExists = await PageObjects.visualize.isInspectorButtonEnabled();
expect(spyToggleExists).to.be(true);
});

it('should show correct data', function () {
const expectedChartData = [
[ '0B', '2,088' ],
[ '1.953KB', '2,748' ],
[ '3.906KB', '2,707' ],
[ '5.859KB', '2,876' ],
[ '7.813KB', '2,863' ],
[ '9.766KB', '147' ],
[ '11.719KB', '148' ],
[ '13.672KB', '129' ],
[ '15.625KB', '161' ],
[ '17.578KB', '137' ]
];

return retry.try(async function () {
await PageObjects.visualize.openInspector();
const data = await PageObjects.visualize.getInspectorTableData();
await PageObjects.visualize.closeInspector();
log.debug(data);
expect(data).to.eql(expectedChartData);
});
});

it('should show correct data when using average pipeline aggregation', async () => {
await PageObjects.visualize.navigateToNewVisualization();
await PageObjects.visualize.clickDataTable();
await PageObjects.visualize.clickNewSearch(PageObjects.visualize.index.LOGSTASH_NON_TIME_BASED);
await PageObjects.visualize.clickAddMetric();
await PageObjects.visualize.clickBucket('Metric');
await PageObjects.visualize.selectAggregation('Average Bucket', 'metrics');
await PageObjects.visualize.selectAggregation('Terms', 'metrics', 'buckets');
await PageObjects.visualize.selectField('geo.src', 'metrics', 'buckets');
await PageObjects.visualize.clickGo();
const data = await PageObjects.visualize.getTableVisData();
log.debug(data.split('\n'));
expect(data.trim().split('\n')).to.be.eql(['14,004 1,412.6']);
});

it('should show correct data for a data table with date histogram', async () => {
await PageObjects.visualize.navigateToNewVisualization();
await PageObjects.visualize.clickDataTable();
await PageObjects.visualize.clickNewSearch(PageObjects.visualize.index.LOGSTASH_NON_TIME_BASED);
await PageObjects.common.sleep(500);
await PageObjects.visualize.clickBucket('Split Rows');
await PageObjects.visualize.selectAggregation('Date Histogram');
await PageObjects.visualize.selectField('@timestamp');
await PageObjects.visualize.setInterval('Daily');
await PageObjects.visualize.clickGo();
await PageObjects.header.waitUntilLoadingHasFinished();
const data = await PageObjects.visualize.getTableVisData();
log.debug(data.split('\n'));
expect(data.trim().split('\n')).to.be.eql([
'2015-09-20', '4,757',
'2015-09-21', '4,614',
'2015-09-22', '4,633',
]);
});

it('should show correct data for a data table with date histogram', async () => {
await PageObjects.visualize.navigateToNewVisualization();
await PageObjects.visualize.clickDataTable();
await PageObjects.visualize.clickNewSearch(PageObjects.visualize.index.LOGSTASH_NON_TIME_BASED);
await PageObjects.common.sleep(500);
await PageObjects.visualize.clickBucket('Split Rows');
await PageObjects.visualize.selectAggregation('Date Histogram');
await PageObjects.visualize.selectField('@timestamp');
await PageObjects.visualize.setInterval('Daily');
await PageObjects.visualize.clickGo();
await PageObjects.header.waitUntilLoadingHasFinished();
const data = await PageObjects.visualize.getTableVisData();
expect(data.trim().split('\n')).to.be.eql([
'2015-09-20', '4,757',
'2015-09-21', '4,614',
'2015-09-22', '4,633',
]);
});

it('should correctly filter for applied time filter on the main timefield', async () => {
await filterBar.addFilter('@timestamp', 'is between', '2015-09-19', '2015-09-21');
await PageObjects.header.waitUntilLoadingHasFinished();
await renderable.waitForRender();
const data = await PageObjects.visualize.getTableVisData();
expect(data.trim().split('\n')).to.be.eql([
'2015-09-20', '4,757',
]);
});

it('should correctly filter for pinned filters', async () => {
await filterBar.toggleFilterPinned('@timestamp');
await PageObjects.header.waitUntilLoadingHasFinished();
await renderable.waitForRender();
const data = await PageObjects.visualize.getTableVisData();
expect(data.trim().split('\n')).to.be.eql([
'2015-09-20', '4,757',
]);
});
});
}
8 changes: 4 additions & 4 deletions test/functional/apps/visualize/_input_control_vis.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default function ({ getService, getPageObjects }) {
await PageObjects.header.setAbsoluteRange('2017-01-01', '2017-01-02');
await PageObjects.visualize.clickVisEditorTab('controls');
await PageObjects.visualize.addInputControl();
await comboBox.set('indexPatternSelect-0', 'logstash');
await comboBox.set('indexPatternSelect-0', 'logstash- ');
await comboBox.set('fieldSelect-0', FIELD_NAME);
await PageObjects.visualize.clickGo();
await PageObjects.header.waitUntilLoadingHasFinished();
Expand Down Expand Up @@ -190,7 +190,7 @@ export default function ({ getService, getPageObjects }) {
await PageObjects.visualize.clickVisEditorTab('controls');

await PageObjects.visualize.addInputControl();
await comboBox.set('indexPatternSelect-0', 'logstash');
await comboBox.set('indexPatternSelect-0', 'logstash- ');
await comboBox.set('fieldSelect-0', 'geo.src');

await PageObjects.visualize.clickGo();
Expand Down Expand Up @@ -233,11 +233,11 @@ export default function ({ getService, getPageObjects }) {
await PageObjects.visualize.clickVisEditorTab('controls');

await PageObjects.visualize.addInputControl();
await comboBox.set('indexPatternSelect-0', 'logstash');
await comboBox.set('indexPatternSelect-0', 'logstash- ');
await comboBox.set('fieldSelect-0', 'geo.src');

await PageObjects.visualize.addInputControl();
await comboBox.set('indexPatternSelect-1', 'logstash');
await comboBox.set('indexPatternSelect-1', 'logstash- ');
await comboBox.set('fieldSelect-1', 'clientip');
await PageObjects.visualize.setSelectByOptionText('parentSelect-1', 'geo.src');

Expand Down
Loading

0 comments on commit c38e948

Please sign in to comment.