Explore: Add tests around query history errors (#86810)

* WIP build tests

* Fix one test :D

* Unskip, remove console logging, fix limit test

* Add back whitespace
pull/86977/head^2
Kristina 1 year ago committed by GitHub
parent eaad38e492
commit e6f51536bf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      public/app/core/history/RichHistoryLocalStorage.ts
  2. 51
      public/app/features/explore/spec/queryHistory.test.tsx

@ -185,7 +185,7 @@ function cleanUp(richHistory: RichHistoryLocalStorageDTO[]): RichHistoryLocalSto
* Ensures the entry can be added. Throws an error if current limit has been hit. * Ensures the entry can be added. Throws an error if current limit has been hit.
* Returns queries that should be saved back giving space for one extra query. * Returns queries that should be saved back giving space for one extra query.
*/ */
function checkLimits(queriesToKeep: RichHistoryLocalStorageDTO[]): { export function checkLimits(queriesToKeep: RichHistoryLocalStorageDTO[]): {
queriesToKeep: RichHistoryLocalStorageDTO[]; queriesToKeep: RichHistoryLocalStorageDTO[];
limitExceeded: boolean; limitExceeded: boolean;
} { } {

@ -4,8 +4,10 @@ import { Props } from 'react-virtualized-auto-sizer';
import { EventBusSrv, serializeStateToUrlParam } from '@grafana/data'; import { EventBusSrv, serializeStateToUrlParam } from '@grafana/data';
import { config } from '@grafana/runtime'; import { config } from '@grafana/runtime';
import { DataQuery } from '@grafana/schema'; import { DataQuery } from '@grafana/schema';
import store from 'app/core/store';
import { silenceConsoleOutput } from '../../../../test/core/utils/silenceConsoleOutput'; import { silenceConsoleOutput } from '../../../../test/core/utils/silenceConsoleOutput';
import * as localStorage from '../../../core/history/RichHistoryLocalStorage';
import { import {
assertDataSourceFilterVisibility, assertDataSourceFilterVisibility,
@ -142,6 +144,55 @@ describe('Explore: Query History', () => {
await assertQueryHistory(['{"expr":"query #2"}', '{"expr":"query #1"}']); await assertQueryHistory(['{"expr":"query #2"}', '{"expr":"query #1"}']);
}); });
it('does not add query if quota exceeded error is reached', async () => {
const urlParams = {
left: serializeStateToUrlParam({
datasource: 'loki',
queries: [{ refId: 'A', expr: 'query #1' }],
range: { from: 'now-1h', to: 'now' },
}),
};
const { datasources } = setupExplore({ urlParams });
jest.mocked(datasources.loki.query).mockReturnValueOnce(makeLogsQueryResponse());
await waitForExplore();
await openQueryHistory();
const storeSpy = jest.spyOn(store, 'setObject').mockImplementation(() => {
const error = new Error('QuotaExceededError');
error.name = 'QuotaExceededError';
throw error;
});
await inputQuery('query #2');
await runQuery();
await assertQueryHistory(['{"expr":"query #1"}']);
storeSpy.mockRestore();
});
it('does add query if limit exceeded error is reached', async () => {
const urlParams = {
left: serializeStateToUrlParam({
datasource: 'loki',
queries: [{ refId: 'A', expr: 'query #1' }],
range: { from: 'now-1h', to: 'now' },
}),
};
const { datasources } = setupExplore({ urlParams });
jest.mocked(datasources.loki.query).mockReturnValueOnce(makeLogsQueryResponse());
await waitForExplore();
await openQueryHistory();
jest.spyOn(localStorage, 'checkLimits').mockImplementationOnce((queries) => {
return { queriesToKeep: queries, limitExceeded: true };
});
await inputQuery('query #2');
await runQuery();
await assertQueryHistory(['{"expr":"query #2"}', '{"expr":"query #1"}']);
});
it('add comments to query history', async () => { it('add comments to query history', async () => {
const urlParams = { const urlParams = {
left: serializeStateToUrlParam({ left: serializeStateToUrlParam({

Loading…
Cancel
Save