|
@@ -4,6 +4,7 @@ import * as dateMath from 'app/core/utils/datemath';
|
|
|
import { angularMocks, sinon } from '../lib/common';
|
|
import { angularMocks, sinon } from '../lib/common';
|
|
|
import { PanelModel } from 'app/features/dashboard/state/PanelModel';
|
|
import { PanelModel } from 'app/features/dashboard/state/PanelModel';
|
|
|
import { PanelPlugin } from 'app/types';
|
|
import { PanelPlugin } from 'app/types';
|
|
|
|
|
+import { RawTimeRange } from '@grafana/ui/src/types';
|
|
|
|
|
|
|
|
export function ControllerTestContext(this: any) {
|
|
export function ControllerTestContext(this: any) {
|
|
|
const self = this;
|
|
const self = this;
|
|
@@ -27,8 +28,8 @@ export function ControllerTestContext(this: any) {
|
|
|
};
|
|
};
|
|
|
this.isUtc = false;
|
|
this.isUtc = false;
|
|
|
|
|
|
|
|
- this.providePhase = mocks => {
|
|
|
|
|
- return angularMocks.module($provide => {
|
|
|
|
|
|
|
+ this.providePhase = (mocks: any) => {
|
|
|
|
|
+ return angularMocks.module(($provide: any) => {
|
|
|
$provide.value('contextSrv', self.contextSrv);
|
|
$provide.value('contextSrv', self.contextSrv);
|
|
|
$provide.value('datasourceSrv', self.datasourceSrv);
|
|
$provide.value('datasourceSrv', self.datasourceSrv);
|
|
|
$provide.value('annotationsSrv', self.annotationsSrv);
|
|
$provide.value('annotationsSrv', self.annotationsSrv);
|
|
@@ -36,14 +37,14 @@ export function ControllerTestContext(this: any) {
|
|
|
$provide.value('templateSrv', self.templateSrv);
|
|
$provide.value('templateSrv', self.templateSrv);
|
|
|
$provide.value('$element', self.$element);
|
|
$provide.value('$element', self.$element);
|
|
|
$provide.value('$sanitize', self.$sanitize);
|
|
$provide.value('$sanitize', self.$sanitize);
|
|
|
- _.each(mocks, (value, key) => {
|
|
|
|
|
|
|
+ _.each(mocks, (value: any, key: any) => {
|
|
|
$provide.value(key, value);
|
|
$provide.value(key, value);
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- this.createPanelController = Ctrl => {
|
|
|
|
|
- return angularMocks.inject(($controller, $rootScope, $q, $location, $browser) => {
|
|
|
|
|
|
|
+ this.createPanelController = (Ctrl: any) => {
|
|
|
|
|
+ return angularMocks.inject(($controller: any, $rootScope: any, $q: any, $location: any, $browser: any) => {
|
|
|
self.scope = $rootScope.$new();
|
|
self.scope = $rootScope.$new();
|
|
|
self.$location = $location;
|
|
self.$location = $location;
|
|
|
self.$browser = $browser;
|
|
self.$browser = $browser;
|
|
@@ -75,8 +76,8 @@ export function ControllerTestContext(this: any) {
|
|
|
});
|
|
});
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- this.createControllerPhase = controllerName => {
|
|
|
|
|
- return angularMocks.inject(($controller, $rootScope, $q, $location, $browser) => {
|
|
|
|
|
|
|
+ this.createControllerPhase = (controllerName: string) => {
|
|
|
|
|
+ return angularMocks.inject(($controller: any, $rootScope: any, $q: any, $location: any, $browser: any) => {
|
|
|
self.scope = $rootScope.$new();
|
|
self.scope = $rootScope.$new();
|
|
|
self.$location = $location;
|
|
self.$location = $location;
|
|
|
self.$browser = $browser;
|
|
self.$browser = $browser;
|
|
@@ -115,28 +116,30 @@ export function ServiceTestContext(this: any) {
|
|
|
self.backendSrv = {};
|
|
self.backendSrv = {};
|
|
|
self.$routeParams = {};
|
|
self.$routeParams = {};
|
|
|
|
|
|
|
|
- this.providePhase = mocks => {
|
|
|
|
|
- return angularMocks.module($provide => {
|
|
|
|
|
- _.each(mocks, key => {
|
|
|
|
|
|
|
+ this.providePhase = (mocks: any) => {
|
|
|
|
|
+ return angularMocks.module(($provide: any) => {
|
|
|
|
|
+ _.each(mocks, (key: string) => {
|
|
|
$provide.value(key, self[key]);
|
|
$provide.value(key, self[key]);
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- this.createService = name => {
|
|
|
|
|
|
|
+ this.createService = (name: string) => {
|
|
|
// @ts-ignore
|
|
// @ts-ignore
|
|
|
- return angularMocks.inject(($q, $rootScope, $httpBackend, $injector, $location, $timeout) => {
|
|
|
|
|
- self.$q = $q;
|
|
|
|
|
- self.$rootScope = $rootScope;
|
|
|
|
|
- self.$httpBackend = $httpBackend;
|
|
|
|
|
- self.$location = $location;
|
|
|
|
|
-
|
|
|
|
|
- self.$rootScope.onAppEvent = () => {};
|
|
|
|
|
- self.$rootScope.appEvent = () => {};
|
|
|
|
|
- self.$timeout = $timeout;
|
|
|
|
|
-
|
|
|
|
|
- self.service = $injector.get(name);
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ return angularMocks.inject(
|
|
|
|
|
+ ($q: any, $rootScope: any, $httpBackend: any, $injector: any, $location: any, $timeout: any) => {
|
|
|
|
|
+ self.$q = $q;
|
|
|
|
|
+ self.$rootScope = $rootScope;
|
|
|
|
|
+ self.$httpBackend = $httpBackend;
|
|
|
|
|
+ self.$location = $location;
|
|
|
|
|
+
|
|
|
|
|
+ self.$rootScope.onAppEvent = () => {};
|
|
|
|
|
+ self.$rootScope.appEvent = () => {};
|
|
|
|
|
+ self.$timeout = $timeout;
|
|
|
|
|
+
|
|
|
|
|
+ self.service = $injector.get(name);
|
|
|
|
|
+ }
|
|
|
|
|
+ );
|
|
|
};
|
|
};
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -144,10 +147,16 @@ export function DashboardViewStateStub(this: any) {
|
|
|
this.registerPanel = () => {};
|
|
this.registerPanel = () => {};
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-export function TimeSrvStub(this: any) {
|
|
|
|
|
- this.init = () => {};
|
|
|
|
|
- this.time = { from: 'now-1h', to: 'now' };
|
|
|
|
|
- this.timeRange = function(parse: boolean) {
|
|
|
|
|
|
|
+export class TimeSrvStub {
|
|
|
|
|
+ time: RawTimeRange;
|
|
|
|
|
+
|
|
|
|
|
+ constructor() {
|
|
|
|
|
+ this.time = { from: 'now-1h', to: 'now' };
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ init() {}
|
|
|
|
|
+
|
|
|
|
|
+ timeRange(parse: boolean) {
|
|
|
if (parse === false) {
|
|
if (parse === false) {
|
|
|
return this.time;
|
|
return this.time;
|
|
|
}
|
|
}
|
|
@@ -155,17 +164,17 @@ export function TimeSrvStub(this: any) {
|
|
|
from: dateMath.parse(this.time.from, false),
|
|
from: dateMath.parse(this.time.from, false),
|
|
|
to: dateMath.parse(this.time.to, true),
|
|
to: dateMath.parse(this.time.to, true),
|
|
|
};
|
|
};
|
|
|
- };
|
|
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- this.setTime = function(time: any) {
|
|
|
|
|
|
|
+ setTime(time: any) {
|
|
|
this.time = time;
|
|
this.time = time;
|
|
|
- };
|
|
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-export function ContextSrvStub(this: any) {
|
|
|
|
|
- this.hasRole = () => {
|
|
|
|
|
|
|
+export class ContextSrvStub {
|
|
|
|
|
+ hasRole() {
|
|
|
return true;
|
|
return true;
|
|
|
- };
|
|
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export function TemplateSrvStub(this: any) {
|
|
export function TemplateSrvStub(this: any) {
|