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