mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Explore: rich history: add more tests (#40769)
* explore: rich history: add unit test * explore: rich-history: added info comment * improved comment * better test names
This commit is contained in:
@@ -281,29 +281,57 @@ describe('richHistory', () => {
|
||||
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',
|
||||
},
|
||||
],
|
||||
};
|
||||
describe('should load from localStorage data in old formats', () => {
|
||||
it('should load when queries are strings', () => {
|
||||
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]);
|
||||
const result = getRichHistory();
|
||||
expect(result).toStrictEqual([expectedHistoryItem]);
|
||||
});
|
||||
|
||||
it('should load when queries are json-encoded strings', () => {
|
||||
const oldHistoryItem = {
|
||||
...mock.storedHistory[0],
|
||||
queries: ['{"refId":"A","key":"key1","metrics":[]}', '{"refId":"B","key":"key2","metrics":[]}'],
|
||||
};
|
||||
store.setObject(key, [oldHistoryItem]);
|
||||
const expectedHistoryItem = {
|
||||
...mock.storedHistory[0],
|
||||
queries: [
|
||||
{
|
||||
refId: 'A',
|
||||
key: 'key1',
|
||||
metrics: [],
|
||||
},
|
||||
{
|
||||
refId: 'B',
|
||||
key: 'key2',
|
||||
metrics: [],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const result = getRichHistory();
|
||||
expect(result).toStrictEqual([expectedHistoryItem]);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -406,10 +406,13 @@ function migrateRichHistory(richHistory: RichHistoryQuery[]) {
|
||||
function createDataQuery(query: RichHistoryQuery, individualQuery: DataQuery | string, index: number) {
|
||||
const letters = 'ABCDEFGHIJKLMNOPQRSTUVXYZ';
|
||||
if (typeof individualQuery === 'object') {
|
||||
// the current format
|
||||
return individualQuery;
|
||||
} else if (isParsable(individualQuery)) {
|
||||
// ElasticSearch (maybe other datasoures too) before grafana7
|
||||
return JSON.parse(individualQuery);
|
||||
}
|
||||
// prometehus (maybe other datasources too) before grafana7
|
||||
return { expr: individualQuery, refId: letters[index] };
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user