grafana/public/app/core/specs/impression_srv.test.ts
Leo 64967325b2
Search: Migrated impressions to use dashboardUID (#53090)
* used dashboarduid in impressions

* handle scenario to convert all ids saved in storage to uids
2022-08-08 11:13:19 +02:00

46 lines
1.6 KiB
TypeScript

const mockBackendSrv = jest.fn();
import impressionSrv from '../services/impression_srv';
jest.mock('@grafana/runtime', () => {
const originalRuntime = jest.requireActual('@grafana/runtime');
return {
...originalRuntime,
getBackendSrv: mockBackendSrv,
config: {
...originalRuntime.config,
bootData: {
...originalRuntime.config.bootData,
user: {
...originalRuntime.config.bootData.user,
orgId: 'testOrgId',
},
},
},
};
});
describe('ImpressionSrv', () => {
beforeEach(() => {
window.localStorage.removeItem(impressionSrv.impressionKey());
});
describe('getDashboardOpened', () => {
it('should return list of dashboard uids', async () => {
window.localStorage.setItem(impressionSrv.impressionKey(), JSON.stringify(['five', 'four', 1, 2, 3]));
mockBackendSrv.mockImplementation(() => ({ get: jest.fn().mockResolvedValue(['one', 'two', 'three']) }));
const result1 = await impressionSrv.getDashboardOpened();
expect(result1).toEqual(['five', 'four', 'one', 'two', 'three']);
window.localStorage.setItem(impressionSrv.impressionKey(), JSON.stringify(['three', 'four']));
const result2 = await impressionSrv.getDashboardOpened();
expect(result2).toEqual(['three', 'four']);
window.localStorage.setItem(impressionSrv.impressionKey(), JSON.stringify([1, 2, 3]));
mockBackendSrv.mockImplementation(() => ({ get: jest.fn().mockResolvedValue(['one', 'two', 'three']) }));
const result3 = await impressionSrv.getDashboardOpened();
expect(result3).toEqual(['one', 'two', 'three']);
});
});
});