grafana/public/app/angular/panel/specs/metrics_panel_ctrl.test.ts
renovate[bot] d87cd6f26c
Update dependency prettier to v2.5.1 (#43473)
* Update dependency prettier to v2.5.1

* prettier fixes

* chore(toolkit): bump prettier to 2.5.1

* style(eslint): bump grafana config to 2.5.2 in core and toolkit

* style(mssql-datasource): fix no-inferrable-types eslint errors

Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: Ashley Harrison <ashley.harrison@grafana.com>
Co-authored-by: Jack Westbrook <jack.westbrook@gmail.com>
2022-02-02 12:02:32 +00:00

63 lines
1.4 KiB
TypeScript

jest.mock('app/core/core', () => ({}));
jest.mock('app/core/config', () => {
return {
...(jest.requireActual('app/core/config') as unknown as object),
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);
}