diff --git a/public/app/features/explore/hooks/useStateSync/migrators/v1.test.ts b/public/app/features/explore/hooks/useStateSync/migrators/v1.test.ts index 810d8800d65..5cbfee69aba 100644 --- a/public/app/features/explore/hooks/useStateSync/migrators/v1.test.ts +++ b/public/app/features/explore/hooks/useStateSync/migrators/v1.test.ts @@ -105,6 +105,107 @@ describe('v1 migrator', () => { }, }); }); + + it('correctly parses state with queryRef', () => { + expect( + v1Migrator.parse({ + panes: `{ + "aaa": { + "datasource": "my-ds", + "queries": [ + { + "refId": "A" + } + ], + "range": { + "from": "now", + "to": "now-5m" + }, + "queryRef": "library-query-123" + } + }`, + }).to + ).toMatchObject({ + panes: { + aaa: { + datasource: 'my-ds', + queries: [{ refId: 'A' }], + range: { + from: 'now', + to: 'now-5m', + }, + queryRef: 'library-query-123', + }, + }, + }); + }); + + it('ignores queryRef if it is not a string', () => { + expect( + v1Migrator.parse({ + panes: `{ + "aaa": { + "datasource": "my-ds", + "queries": [ + { + "refId": "A" + } + ], + "range": { + "from": "now", + "to": "now-5m" + }, + "queryRef": 123 + } + }`, + }).to + ).toMatchObject({ + panes: { + aaa: { + datasource: 'my-ds', + queries: [{ refId: 'A' }], + range: { + from: 'now', + to: 'now-5m', + }, + }, + }, + }); + }); + + it('handles empty string queryRef', () => { + expect( + v1Migrator.parse({ + panes: `{ + "aaa": { + "datasource": "my-ds", + "queries": [ + { + "refId": "A" + } + ], + "range": { + "from": "now", + "to": "now-5m" + }, + "queryRef": "" + } + }`, + }).to + ).toMatchObject({ + panes: { + aaa: { + datasource: 'my-ds', + queries: [{ refId: 'A' }], + range: { + from: 'now', + to: 'now-5m', + }, + queryRef: '', + }, + }, + }); + }); }); describe('migrate', () => {