mirror of
https://github.com/grafana/grafana.git
synced 2025-09-21 03:33:12 +08:00

* fix any's in tests * fix more any's in tests * more test type fixes * fixing any's in tests part 3 * more test type fixes * fixing test any's p5 * some tidy up * fix template_srv
64 lines
1.4 KiB
TypeScript
64 lines
1.4 KiB
TypeScript
jest.mock('app/core/core', () => ({}));
|
|
jest.mock('app/core/config', () => {
|
|
return {
|
|
...jest.requireActual('app/core/config'),
|
|
bootData: {
|
|
user: {},
|
|
},
|
|
panels: {
|
|
test: {
|
|
id: 'test',
|
|
name: 'test',
|
|
},
|
|
},
|
|
config: {
|
|
appSubUrl: 'test',
|
|
},
|
|
};
|
|
});
|
|
|
|
import { PanelModel } from 'app/features/dashboard/state/PanelModel';
|
|
|
|
import { MetricsPanelCtrl } from '../metrics_panel_ctrl';
|
|
|
|
describe('MetricsPanelCtrl', () => {
|
|
describe('can setup', () => {
|
|
it('should return controller', async () => {
|
|
const ctrl = setupController({ hasAccessToExplore: true });
|
|
expect((await ctrl.getAdditionalMenuItems()).length).toBe(0);
|
|
});
|
|
});
|
|
});
|
|
|
|
function setupController({ hasAccessToExplore } = { hasAccessToExplore: false }) {
|
|
const injectorStub = {
|
|
get: (type: any) => {
|
|
switch (type) {
|
|
case 'contextSrv': {
|
|
return { hasAccessToExplore: () => hasAccessToExplore };
|
|
}
|
|
case 'timeSrv': {
|
|
return { timeRangeForUrl: () => {} };
|
|
}
|
|
default: {
|
|
return jest.fn();
|
|
}
|
|
}
|
|
},
|
|
};
|
|
|
|
const scope: any = {
|
|
panel: { events: [] },
|
|
appEvent: jest.fn(),
|
|
onAppEvent: jest.fn(),
|
|
$on: jest.fn(),
|
|
colors: [],
|
|
$parent: {
|
|
panel: new PanelModel({ type: 'test' }),
|
|
dashboard: {},
|
|
},
|
|
};
|
|
|
|
return new MetricsPanelCtrl(scope, injectorStub);
|
|
}
|