Skip to content

Commit

Permalink
[Discover] Fix broken setting of bucketInterval (elastic#62939)
Browse files Browse the repository at this point in the history
* Fix broken setting of bucketInterval, remove $watch

* Fix and adapt functional tests
  • Loading branch information
kertal committed Apr 15, 2020
1 parent 34e2b0f commit 7ad3558
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ <h1 class="euiScreenReaderOnly">{{screenTitle}}</h1>
position="'top'"
></icon-tip>
<span
data-test-subj="discoverIntervalSelectScaledToDesc"
i18n-id="kbn.discover.scaledToDescription"
i18n-default-message="Scaled to {bucketIntervalDescription}"
i18n-values="{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -675,17 +675,6 @@ function discoverController(
}
});

$scope.$watch('vis.aggs', function() {
// no timefield, no vis, nothing to update
if (!getTimeField() || !$scope.vis) return;

const buckets = $scope.vis.data.aggs.byTypeName('buckets');

if (buckets && buckets.length === 1) {
$scope.bucketInterval = buckets[0].buckets.getInterval();
}
});

$scope.$watchMulti(
['rows', 'fetchStatus'],
(function updateResultState() {
Expand Down Expand Up @@ -891,6 +880,9 @@ function discoverController(
tabifiedData,
getDimensions($scope.vis.data.aggs.aggs, $scope.timeRange)
);
if ($scope.vis.data.aggs.aggs[1]) {
$scope.bucketInterval = $scope.vis.data.aggs.aggs[1].buckets.getInterval();
}
}

$scope.hits = resp.hits.total;
Expand Down
20 changes: 10 additions & 10 deletions test/functional/apps/discover/_discover_histogram.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,34 +66,34 @@ export default function({ getService, getPageObjects }) {
});

it('should visualize monthly data with different day intervals', async () => {
//Nov 1, 2017 @ 01:00:00.000 - Mar 21, 2018 @ 02:00:00.000
const fromTime = '2017-11-01 00:00:00.000';
const toTime = '2018-03-21 00:00:00.000';
const fromTime = 'Nov 01, 2017 @ 00:00:00.000';
const toTime = 'Mar 21, 2018 @ 00:00:00.000';
await PageObjects.timePicker.setAbsoluteRange(fromTime, toTime);
await PageObjects.discover.setChartInterval('Monthly');
await PageObjects.header.waitUntilLoadingHasFinished();
const chartCanvasExist = await elasticChart.canvasExists();
expect(chartCanvasExist).to.be(true);
});
it('should visualize weekly data with within DST changes', async () => {
//Nov 1, 2017 @ 01:00:00.000 - Mar 21, 2018 @ 02:00:00.000
const fromTime = '2018-03-01 00:00:00.000';
const toTime = '2018-05-01 00:00:00.000';
const fromTime = 'Mar 01, 2018 @ 00:00:00.000';
const toTime = 'May 01, 2018 @ 00:00:00.000';
await PageObjects.timePicker.setAbsoluteRange(fromTime, toTime);
await PageObjects.discover.setChartInterval('Weekly');
await PageObjects.header.waitUntilLoadingHasFinished();
const chartCanvasExist = await elasticChart.canvasExists();
expect(chartCanvasExist).to.be(true);
});
it('should visualize monthly data with different years Scaled to 30d', async () => {
//Nov 1, 2017 @ 01:00:00.000 - Mar 21, 2018 @ 02:00:00.000
const fromTime = '2010-01-01 00:00:00.000';
const toTime = '2018-03-21 00:00:00.000';
it('should visualize monthly data with different years Scaled to 30 days', async () => {
const fromTime = 'Jan 01, 2010 @ 00:00:00.000';
const toTime = 'Mar 21, 2019 @ 00:00:00.000';

await PageObjects.timePicker.setAbsoluteRange(fromTime, toTime);
await PageObjects.discover.setChartInterval('Daily');
await PageObjects.header.waitUntilLoadingHasFinished();
const chartCanvasExist = await elasticChart.canvasExists();
expect(chartCanvasExist).to.be(true);
const chartIntervalScaledDesc = await PageObjects.discover.getChartIntervalScaledToDesc();
expect(chartIntervalScaledDesc).to.be('Scaled to 30 days');
});
});
}
5 changes: 5 additions & 0 deletions test/functional/page_objects/discover_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ export function DiscoverPageProvider({ getService, getPageObjects }: FtrProvider
return selectedOption.getVisibleText();
}

public async getChartIntervalScaledToDesc() {
await header.waitUntilLoadingHasFinished();
return await testSubjects.getVisibleText('discoverIntervalSelectScaledToDesc');
}

public async setChartInterval(interval: string) {
const optionElement = await find.byCssSelector(`option[label="${interval}"]`, 5000);
await optionElement.click();
Expand Down

0 comments on commit 7ad3558

Please sign in to comment.