[Discover] Fix ignoring uiSetting discover:searchOnPageLoad (#61393) (#61570)

* Add checks for changed query and update in $scope.updateQuery

* Add functional test by counting fetches
This commit is contained in:
Matthias Wilhelm 2020-03-27 10:31:16 +01:00 committed by GitHub
parent b863c0fb80
commit 1381864f8d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 5 deletions

View file

@ -1,4 +1,4 @@
<discover-app class="app-container">
<discover-app class="app-container" data-fetch-counter="{{fetchCounter}}">
<h1 class="euiScreenReaderOnly">{{screenTitle}}</h1>
<!-- Local nav. -->

View file

@ -194,6 +194,8 @@ function discoverController(
const savedSearch = $route.current.locals.savedObjects.savedSearch;
$scope.searchSource = savedSearch.searchSource;
$scope.indexPattern = resolveIndexPatternLoading();
//used for functional testing
$scope.fetchCounter = 0;
const getTimeField = () => {
return isDefaultType($scope.indexPattern) ? $scope.indexPattern.timeFieldName : undefined;
@ -784,7 +786,7 @@ function discoverController(
$scope.opts.fetch = $scope.fetch = function() {
// ignore requests to fetch before the app inits
if (!init.complete) return;
$scope.fetchCounter++;
$scope.fetchError = undefined;
// Abort any in-progress requests before fetching again
@ -821,9 +823,11 @@ function discoverController(
});
};
$scope.updateQuery = function({ query }) {
setAppState({ query });
$fetchObservable.next();
$scope.updateQuery = function({ query }, isUpdate = true) {
if (!_.isEqual(query, appStateContainer.getState().query) || isUpdate === false) {
setAppState({ query });
$fetchObservable.next();
}
};
$scope.updateSavedQueryId = newSavedQueryId => {

View file

@ -224,5 +224,22 @@ export default function({ getService, getPageObjects }) {
expect(rowData.startsWith('Sep 22, 2015 @ 16:50:13.253')).to.be.ok();
});
});
describe('usage of discover:searchOnPageLoad', () => {
it('should fetch data from ES initially when discover:searchOnPageLoad is false', async function() {
await kibanaServer.uiSettings.replace({ 'discover:searchOnPageLoad': false });
await PageObjects.common.navigateToApp('discover');
await PageObjects.header.awaitKibanaChrome();
expect(await PageObjects.discover.getNrOfFetches()).to.be(0);
});
it('should not fetch data from ES initially when discover:searchOnPageLoad is true', async function() {
await kibanaServer.uiSettings.replace({ 'discover:searchOnPageLoad': true });
await PageObjects.common.navigateToApp('discover');
await PageObjects.header.awaitKibanaChrome();
expect(await PageObjects.discover.getNrOfFetches()).to.be(1);
});
});
});
}

View file

@ -300,6 +300,11 @@ export function DiscoverPageProvider({ getService, getPageObjects }: FtrProvider
'true'
);
}
public async getNrOfFetches() {
const el = await find.byCssSelector('[data-fetch-counter]');
const nr = await el.getAttribute('data-fetch-counter');
return Number(nr);
}
}
return new DiscoverPage();