2018-05-17 20:56:15 +08:00
|
|
|
jest.mock('app/core/core', () => ({}));
|
2018-06-06 17:15:24 +08:00
|
|
|
jest.mock('app/core/config', () => {
|
|
|
|
return {
|
2023-02-14 23:46:42 +08:00
|
|
|
...jest.requireActual('app/core/config'),
|
2018-06-06 17:15:24 +08:00
|
|
|
panels: {
|
|
|
|
test: {
|
|
|
|
id: 'test',
|
|
|
|
name: 'test',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
});
|
2018-05-17 20:56:15 +08:00
|
|
|
|
2019-01-31 15:56:17 +08:00
|
|
|
import { PanelModel } from 'app/features/dashboard/state/PanelModel';
|
2022-04-22 21:33:13 +08:00
|
|
|
|
2018-06-06 17:15:24 +08:00
|
|
|
import { MetricsPanelCtrl } from '../metrics_panel_ctrl';
|
2018-05-17 20:56:15 +08:00
|
|
|
|
|
|
|
describe('MetricsPanelCtrl', () => {
|
2020-02-09 17:53:34 +08:00
|
|
|
describe('can setup', () => {
|
|
|
|
it('should return controller', async () => {
|
|
|
|
const ctrl = setupController({ hasAccessToExplore: true });
|
|
|
|
expect((await ctrl.getAdditionalMenuItems()).length).toBe(0);
|
2019-01-21 15:47:41 +08:00
|
|
|
});
|
2018-05-17 20:56:15 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-01-21 17:50:34 +08:00
|
|
|
function setupController({ hasAccessToExplore } = { hasAccessToExplore: false }) {
|
2018-05-17 20:56:15 +08:00
|
|
|
const injectorStub = {
|
2019-07-18 14:03:04 +08:00
|
|
|
get: (type: any) => {
|
2018-05-17 20:56:15 +08:00
|
|
|
switch (type) {
|
2019-01-21 17:50:34 +08:00
|
|
|
case 'contextSrv': {
|
|
|
|
return { hasAccessToExplore: () => hasAccessToExplore };
|
|
|
|
}
|
2019-09-02 18:47:33 +08:00
|
|
|
case 'timeSrv': {
|
|
|
|
return { timeRangeForUrl: () => {} };
|
|
|
|
}
|
2018-05-17 20:56:15 +08:00
|
|
|
default: {
|
|
|
|
return jest.fn();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2019-07-18 14:03:04 +08:00
|
|
|
const scope: any = {
|
2018-05-17 20:56:15 +08:00
|
|
|
panel: { events: [] },
|
|
|
|
appEvent: jest.fn(),
|
|
|
|
onAppEvent: jest.fn(),
|
|
|
|
$on: jest.fn(),
|
|
|
|
colors: [],
|
2021-03-31 23:03:07 +08:00
|
|
|
$parent: {
|
|
|
|
panel: new PanelModel({ type: 'test' }),
|
|
|
|
dashboard: {},
|
|
|
|
},
|
2018-05-17 20:56:15 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
return new MetricsPanelCtrl(scope, injectorStub);
|
|
|
|
}
|