[Discover] Fix broken setting of bucketInterval (#62939) (#63547)

* Fix broken setting of bucketInterval, remove $watch

* Fix and adapt functional tests
This commit is contained in:
Matthias Wilhelm 2020-04-15 13:03:18 +02:00 committed by GitHub
parent f081cedf2c
commit 103ef928bd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 21 deletions

View file

@ -139,6 +139,7 @@
position="'top'"
></icon-tip>
<span
data-test-subj="discoverIntervalSelectScaledToDesc"
i18n-id="kbn.discover.scaledToDescription"
i18n-default-message="Scaled to {bucketIntervalDescription}"
i18n-values="{

View file

@ -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() {
@ -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;

View file

@ -66,9 +66,8 @@ 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();
@ -76,24 +75,25 @@ export default function({ getService, getPageObjects }) {
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');
});
});
}

View file

@ -161,6 +161,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();