From 4bf5fa2ad2ab9689610a3231d28d7af5fb29fc81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Farkas?= Date: Thu, 21 Oct 2021 09:49:38 +0200 Subject: [PATCH] explore: rich-history: add test for old-mode conversion code (#40714) --- public/app/core/utils/richHistory.test.ts | 32 +++++++++++++++++++++++ public/app/core/utils/richHistory.ts | 1 - 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/public/app/core/utils/richHistory.test.ts b/public/app/core/utils/richHistory.test.ts index 80e95a3b663..08be5c3ec1b 100644 --- a/public/app/core/utils/richHistory.test.ts +++ b/public/app/core/utils/richHistory.test.ts @@ -1,5 +1,6 @@ import { addToRichHistory, + getRichHistory, updateStarredInRichHistory, updateCommentInRichHistory, mapNumbertoTimeInSlider, @@ -274,4 +275,35 @@ describe('richHistory', () => { expect(heading).toEqual(mock.storedHistory[0].datasourceName); }); }); + + describe('getRichHistory', () => { + afterEach(() => { + deleteAllFromRichHistory(); + expect(store.exists(key)).toBeFalsy(); + }); + it('should load from localStorage data in old format', () => { + const oldHistoryItem = { ...mock.storedHistory[0], queries: ['test query 1', 'test query 2', 'test query 3'] }; + store.setObject(key, [oldHistoryItem]); + const expectedHistoryItem = { + ...mock.storedHistory[0], + queries: [ + { + expr: 'test query 1', + refId: 'A', + }, + { + expr: 'test query 2', + refId: 'B', + }, + { + expr: 'test query 3', + refId: 'C', + }, + ], + }; + + const result = getRichHistory(); + expect(result).toStrictEqual([expectedHistoryItem]); + }); + }); }); diff --git a/public/app/core/utils/richHistory.ts b/public/app/core/utils/richHistory.ts index 1ab0dd0604c..b0d995f94bb 100644 --- a/public/app/core/utils/richHistory.ts +++ b/public/app/core/utils/richHistory.ts @@ -394,7 +394,6 @@ export function filterAndSortQueries( return sortQueries(filteredQueriesToBeSorted, sortOrder); } -/* These functions are created to migrate string queries (from 6.7 release) to DataQueries. They can be removed after 7.1 release. */ function migrateRichHistory(richHistory: RichHistoryQuery[]) { const transformedRichHistory = richHistory.map((query) => { const transformedQueries: DataQuery[] = query.queries.map((q, index) => createDataQuery(query, q, index));