diff --git a/public/app/features/explore/spec/helper/assert.ts b/public/app/features/explore/spec/helper/assert.ts index f0f950bb7b1..1a2cb4acf71 100644 --- a/public/app/features/explore/spec/helper/assert.ts +++ b/public/app/features/explore/spec/helper/assert.ts @@ -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') => { const selector = withinExplore(exploreId); await waitFor(() => { diff --git a/public/app/features/explore/spec/queryHistory.test.tsx b/public/app/features/explore/spec/queryHistory.test.tsx index a8331525fe8..1b0eff9d6c3 100644 --- a/public/app/features/explore/spec/queryHistory.test.tsx +++ b/public/app/features/explore/spec/queryHistory.test.tsx @@ -15,6 +15,7 @@ import { assertQueryHistoryExists, assertQueryHistoryIsStarred, assertQueryHistoryTabIsSelected, + assertQueryHistoryIsEmpty, } from './helper/assert'; import { commentQueryHistory, @@ -211,6 +212,31 @@ describe('Explore: Query History', () => { 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 () => { // open settings page setupExplore();