mirror of
https://github.com/grafana/grafana.git
synced 2025-02-13 00:55:47 -06:00
* Babel: Updates babel dependencies to latest version * Fixed problem introduced by babel where calling super with prefedefined this is not supported * fixing test * Fixed tests * Improve fix for QueryCtrl * Fixed more tests * Updated tests
68 lines
1.5 KiB
TypeScript
68 lines
1.5 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',
|
|
},
|
|
};
|
|
});
|
|
|
|
// @ts-ignore
|
|
import q from 'q';
|
|
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 '$q': {
|
|
return q;
|
|
}
|
|
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);
|
|
}
|