mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* Refactor: initial commit * wip * Refactor: getting into a simpler model * Refactor: adds some comments * Refactor: renames statuses according to PR comments * Refactor: adds more comments * Tests: adds tests for FetchQueue * Tests: adds tests for ResponseQueue * Tests: adds tests for FetchQueueWorker * Tests: simplified the tests for ResponseQueue * Refactor: adds http2 scenario * Refactor: using Cfg instead of global variable Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com> * Refactor: reverted change in frontendsettings.go * Tests: fix test mocks * Fix: changes how cfg.Protocol gets its value Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com>
66 lines
1.5 KiB
TypeScript
66 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: [],
|
|
};
|
|
|
|
MetricsPanelCtrl.prototype.panel = new PanelModel({ type: 'test' });
|
|
|
|
return new MetricsPanelCtrl(scope, injectorStub);
|
|
}
|