The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/public/app/core/specs/impression_srv.test.ts

45 lines
1.6 KiB

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