Explore: Test deleting comments in query history (#70934)

* Working test
This commit is contained in:
Haris Rozajac 2023-07-10 08:09:42 -06:00 committed by GitHub
parent 276c63a656
commit 4b3050e02e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 0 deletions

View File

@ -21,6 +21,13 @@ export const assertQueryHistory = async (expectedQueryTexts: string[], exploreId
}); });
}; };
export const assertQueryHistoryIsEmpty = async (exploreId = 'left') => {
const selector = withinExplore(exploreId);
const queryTexts = selector.queryAllByLabelText('Query text');
expect(await queryTexts).toHaveLength(0);
};
export const assertQueryHistoryComment = async (expectedQueryComments: string[], exploreId = 'left') => { export const assertQueryHistoryComment = async (expectedQueryComments: string[], exploreId = 'left') => {
const selector = withinExplore(exploreId); const selector = withinExplore(exploreId);
await waitFor(() => { await waitFor(() => {

View File

@ -15,6 +15,7 @@ import {
assertQueryHistoryExists, assertQueryHistoryExists,
assertQueryHistoryIsStarred, assertQueryHistoryIsStarred,
assertQueryHistoryTabIsSelected, assertQueryHistoryTabIsSelected,
assertQueryHistoryIsEmpty,
} from './helper/assert'; } from './helper/assert';
import { import {
commentQueryHistory, commentQueryHistory,
@ -211,6 +212,31 @@ describe('Explore: Query History', () => {
await assertQueryHistoryComment(['test comment'], 'left'); await assertQueryHistoryComment(['test comment'], 'left');
}); });
it('removes the query item from the history panel when user deletes a regular query', 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();
// queries in history
await assertQueryHistory(['{"expr":"query #1"}'], 'left');
// delete query
await deleteQueryHistory(0, 'left');
// there was only one query in history so assert that query history is empty
await assertQueryHistoryIsEmpty('left');
});
it('updates query history settings', async () => { it('updates query history settings', async () => {
// open settings page // open settings page
setupExplore(); setupExplore();