Merge branch 'master' into backend
This commit is contained in:
@@ -2,7 +2,9 @@
|
||||
/* globals global: false */
|
||||
|
||||
import { JSDOM } from 'jsdom';
|
||||
import { PanelCtrl } from './panelStub';
|
||||
import { PanelCtrl, MetricsPanelCtrl } from './panelStub';
|
||||
|
||||
console.log = () => {};
|
||||
|
||||
// Mock Grafana modules that are not available outside of the core project
|
||||
// Required for loading module.js
|
||||
@@ -26,17 +28,34 @@ jest.mock('grafana/app/features/dashboard/dashboard_srv', () => {
|
||||
return {};
|
||||
}, {virtual: true});
|
||||
|
||||
jest.mock('@grafana/runtime', () => {
|
||||
return {
|
||||
getBackendSrv: () => ({
|
||||
datasourceRequest: jest.fn().mockResolvedValue(),
|
||||
}),
|
||||
};
|
||||
}, {virtual: true});
|
||||
|
||||
jest.mock('grafana/app/core/core_module', () => {
|
||||
return {
|
||||
directive: function() {},
|
||||
};
|
||||
}, {virtual: true});
|
||||
|
||||
let mockPanelCtrl = PanelCtrl;
|
||||
jest.mock('grafana/app/core/core', () => ({
|
||||
contextSrv: {},
|
||||
}), {virtual: true});
|
||||
|
||||
const mockPanelCtrl = PanelCtrl;
|
||||
const mockMetricsPanelCtrl = MetricsPanelCtrl;
|
||||
|
||||
jest.mock('grafana/app/plugins/sdk', () => {
|
||||
return {
|
||||
QueryCtrl: null,
|
||||
PanelCtrl: mockPanelCtrl
|
||||
PanelCtrl: mockPanelCtrl,
|
||||
loadPluginCss: () => {},
|
||||
PanelCtrl: mockPanelCtrl,
|
||||
MetricsPanelCtrl: mockMetricsPanelCtrl,
|
||||
};
|
||||
}, {virtual: true});
|
||||
|
||||
@@ -92,3 +111,7 @@ let dom = new JSDOM('<html><head><script></script></head><body></body></html>');
|
||||
global.window = dom.window;
|
||||
global.document = global.window.document;
|
||||
global.Node = window.Node;
|
||||
|
||||
// Mock Canvas.getContext(), fixes
|
||||
// Error: Not implemented: HTMLCanvasElement.prototype.getContext (without installing the canvas npm package)
|
||||
window.HTMLCanvasElement.prototype.getContext = () => {};
|
||||
|
||||
@@ -1,99 +0,0 @@
|
||||
// JSHint options
|
||||
/* jshint ignore:start */
|
||||
|
||||
export class PanelCtrl {
|
||||
constructor($scope, $injector) {
|
||||
this.$injector = $injector;
|
||||
this.$scope = $scope;
|
||||
this.panel = $scope.panel;
|
||||
this.timing = {};
|
||||
this.events = {
|
||||
on: () => {},
|
||||
emit: () => {}
|
||||
};
|
||||
}
|
||||
|
||||
init() {
|
||||
}
|
||||
|
||||
renderingCompleted() {
|
||||
}
|
||||
|
||||
refresh() {
|
||||
}
|
||||
|
||||
publishAppEvent(evtName, evt) {
|
||||
}
|
||||
|
||||
changeView(fullscreen, edit) {
|
||||
}
|
||||
|
||||
viewPanel() {
|
||||
this.changeView(true, false);
|
||||
}
|
||||
|
||||
editPanel() {
|
||||
this.changeView(true, true);
|
||||
}
|
||||
|
||||
exitFullscreen() {
|
||||
this.changeView(false, false);
|
||||
}
|
||||
|
||||
initEditMode() {
|
||||
}
|
||||
|
||||
changeTab(newIndex) {
|
||||
}
|
||||
|
||||
addEditorTab(title, directiveFn, index) {
|
||||
}
|
||||
|
||||
getMenu() {
|
||||
return [];
|
||||
}
|
||||
|
||||
getExtendedMenu() {
|
||||
return [];
|
||||
}
|
||||
|
||||
otherPanelInFullscreenMode() {
|
||||
return false;
|
||||
}
|
||||
|
||||
calculatePanelHeight() {
|
||||
}
|
||||
|
||||
render(payload) {
|
||||
}
|
||||
|
||||
toggleEditorHelp(index) {
|
||||
}
|
||||
|
||||
duplicate() {
|
||||
}
|
||||
|
||||
updateColumnSpan(span) {
|
||||
}
|
||||
|
||||
removePanel() {
|
||||
}
|
||||
|
||||
editPanelJson() {
|
||||
}
|
||||
|
||||
replacePanel(newPanel, oldPanel) {
|
||||
}
|
||||
|
||||
sharePanel() {
|
||||
}
|
||||
|
||||
getInfoMode() {
|
||||
}
|
||||
|
||||
getInfoContent(options) {
|
||||
}
|
||||
|
||||
openInspector() {
|
||||
}
|
||||
}
|
||||
162
src/test-setup/panelStub.ts
Normal file
162
src/test-setup/panelStub.ts
Normal file
@@ -0,0 +1,162 @@
|
||||
import { PanelEvents } from '@grafana/data';
|
||||
|
||||
export class PanelCtrl {
|
||||
panel: any;
|
||||
error: any;
|
||||
dashboard: any;
|
||||
pluginName: string;
|
||||
pluginId: string;
|
||||
editorTabs: any;
|
||||
$scope: any;
|
||||
$injector: any;
|
||||
$location: any;
|
||||
$timeout: any;
|
||||
editModeInitiated: boolean;
|
||||
height: number;
|
||||
width: number;
|
||||
containerHeight: any;
|
||||
events: any;
|
||||
loading: boolean;
|
||||
timing: any;
|
||||
|
||||
constructor($scope, $injector) {
|
||||
this.$injector = $injector;
|
||||
this.$scope = $scope;
|
||||
this.panel = $scope.panel;
|
||||
this.timing = {};
|
||||
this.events = {
|
||||
on: () => {},
|
||||
emit: () => {}
|
||||
};
|
||||
}
|
||||
|
||||
init() {
|
||||
}
|
||||
|
||||
renderingCompleted() {
|
||||
}
|
||||
|
||||
refresh() {
|
||||
}
|
||||
|
||||
publishAppEvent(evtName, evt) {
|
||||
}
|
||||
|
||||
changeView(fullscreen, edit) {
|
||||
}
|
||||
|
||||
viewPanel() {
|
||||
this.changeView(true, false);
|
||||
}
|
||||
|
||||
editPanel() {
|
||||
this.changeView(true, true);
|
||||
}
|
||||
|
||||
exitFullscreen() {
|
||||
this.changeView(false, false);
|
||||
}
|
||||
|
||||
initEditMode() {
|
||||
}
|
||||
|
||||
changeTab(newIndex) {
|
||||
}
|
||||
|
||||
addEditorTab(title, directiveFn, index) {
|
||||
}
|
||||
|
||||
getMenu() {
|
||||
return [];
|
||||
}
|
||||
|
||||
getExtendedMenu() {
|
||||
return [];
|
||||
}
|
||||
|
||||
otherPanelInFullscreenMode() {
|
||||
return false;
|
||||
}
|
||||
|
||||
calculatePanelHeight() {
|
||||
}
|
||||
|
||||
render(payload) {
|
||||
}
|
||||
|
||||
toggleEditorHelp(index) {
|
||||
}
|
||||
|
||||
duplicate() {
|
||||
}
|
||||
|
||||
updateColumnSpan(span) {
|
||||
}
|
||||
|
||||
removePanel() {
|
||||
}
|
||||
|
||||
editPanelJson() {
|
||||
}
|
||||
|
||||
replacePanel(newPanel, oldPanel) {
|
||||
}
|
||||
|
||||
sharePanel() {
|
||||
}
|
||||
|
||||
getInfoMode() {
|
||||
}
|
||||
|
||||
getInfoContent(options) {
|
||||
}
|
||||
|
||||
openInspector() {
|
||||
}
|
||||
}
|
||||
|
||||
export class MetricsPanelCtrl extends PanelCtrl {
|
||||
scope: any;
|
||||
datasource: any;
|
||||
$timeout: any;
|
||||
contextSrv: any;
|
||||
datasourceSrv: any;
|
||||
timeSrv: any;
|
||||
templateSrv: any;
|
||||
range: any;
|
||||
interval: any;
|
||||
intervalMs: any;
|
||||
resolution: any;
|
||||
timeInfo?: string;
|
||||
skipDataOnInit: boolean;
|
||||
dataList: any[];
|
||||
querySubscription?: any;
|
||||
useDataFrames = false;
|
||||
|
||||
constructor($scope, $injector) {
|
||||
super($scope, $injector);
|
||||
|
||||
this.events.on(PanelEvents.refresh, this.onMetricsPanelRefresh.bind(this));
|
||||
|
||||
this.timeSrv = {
|
||||
timeRange: () => {},
|
||||
};
|
||||
}
|
||||
|
||||
onInitMetricsPanelEditMode() {}
|
||||
onMetricsPanelRefresh() {}
|
||||
setTimeQueryStart() {}
|
||||
setTimeQueryEnd() {}
|
||||
updateTimeRange() {}
|
||||
calculateInterval() {}
|
||||
applyPanelTimeOverrides() {}
|
||||
issueQueries(datasource) {}
|
||||
handleQueryResult(result) {}
|
||||
handleDataStream(stream) {}
|
||||
setDatasource(datasource) {}
|
||||
getAdditionalMenuItems() {}
|
||||
explore() {}
|
||||
addQuery(target) {}
|
||||
removeQuery(target) {}
|
||||
moveQuery(target, direction) {}
|
||||
}
|
||||
Reference in New Issue
Block a user