explore: rich-history: add test for old-mode conversion code (#40714)

This commit is contained in:
Gábor Farkas 2021-10-21 09:49:38 +02:00 committed by GitHub
parent bb738e35cf
commit 4bf5fa2ad2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 1 deletions

View File

@ -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]);
});
});
});

View File

@ -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));