grafana/public/app/angular/panel/specs/metrics_panel_ctrl.test.ts

63 lines
1.4 KiB
TypeScript
Raw Normal View History

2018-05-17 07:56:15 -05:00
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',
},
};
});
2018-05-17 07:56:15 -05:00
import { PanelModel } from 'app/features/dashboard/state/PanelModel';
import { MetricsPanelCtrl } from '../metrics_panel_ctrl';
2018-05-17 07:56:15 -05:00
describe('MetricsPanelCtrl', () => {
describe('can setup', () => {
it('should return controller', async () => {
const ctrl = setupController({ hasAccessToExplore: true });
expect((await ctrl.getAdditionalMenuItems()).length).toBe(0);
});
2018-05-17 07:56:15 -05:00
});
});
function setupController({ hasAccessToExplore } = { hasAccessToExplore: false }) {
2018-05-17 07:56:15 -05:00
const injectorStub = {
get: (type: any) => {
2018-05-17 07:56:15 -05:00
switch (type) {
case 'contextSrv': {
return { hasAccessToExplore: () => hasAccessToExplore };
}
case 'timeSrv': {
return { timeRangeForUrl: () => {} };
}
2018-05-17 07:56:15 -05:00
default: {
return jest.fn();
}
}
},
};
const scope: any = {
2018-05-17 07:56:15 -05:00
panel: { events: [] },
appEvent: jest.fn(),
onAppEvent: jest.fn(),
$on: jest.fn(),
colors: [],
$parent: {
panel: new PanelModel({ type: 'test' }),
dashboard: {},
},
2018-05-17 07:56:15 -05:00
};
return new MetricsPanelCtrl(scope, injectorStub);
}