mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
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
This commit is contained in:
parent
eaad38e492
commit
e6f51536bf
@ -185,7 +185,7 @@ function cleanUp(richHistory: RichHistoryLocalStorageDTO[]): RichHistoryLocalSto
|
||||
* 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.
|
||||
*/
|
||||
function checkLimits(queriesToKeep: RichHistoryLocalStorageDTO[]): {
|
||||
export function checkLimits(queriesToKeep: RichHistoryLocalStorageDTO[]): {
|
||||
queriesToKeep: RichHistoryLocalStorageDTO[];
|
||||
limitExceeded: boolean;
|
||||
} {
|
||||
|
@ -4,8 +4,10 @@ import { Props } from 'react-virtualized-auto-sizer';
|
||||
import { EventBusSrv, serializeStateToUrlParam } from '@grafana/data';
|
||||
import { config } from '@grafana/runtime';
|
||||
import { DataQuery } from '@grafana/schema';
|
||||
import store from 'app/core/store';
|
||||
|
||||
import { silenceConsoleOutput } from '../../../../test/core/utils/silenceConsoleOutput';
|
||||
import * as localStorage from '../../../core/history/RichHistoryLocalStorage';
|
||||
|
||||
import {
|
||||
assertDataSourceFilterVisibility,
|
||||
@ -142,6 +144,55 @@ describe('Explore: Query History', () => {
|
||||
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 () => {
|
||||
const urlParams = {
|
||||
left: serializeStateToUrlParam({
|
||||
|
Loading…
Reference in New Issue
Block a user