mirror of
https://github.com/grafana/grafana.git
synced 2024-11-30 12:44:10 -06:00
64967325b2
* used dashboarduid in impressions * handle scenario to convert all ids saved in storage to uids
46 lines
1.6 KiB
TypeScript
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']);
|
|
});
|
|
});
|
|
});
|