mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Merge pull request #16184 from grafana/remove-implicit-anys-progress
chore: Removed implicit anys in react container and test helpers
This commit is contained in:
@@ -1,13 +1,15 @@
|
||||
// Libraries
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import { Provider } from 'react-redux';
|
||||
|
||||
// Utils and services
|
||||
import coreModule from 'app/core/core_module';
|
||||
import { store } from 'app/store/store';
|
||||
import { ContextSrv } from 'app/core/services/context_srv';
|
||||
import { provideTheme } from 'app/core/utils/ConfigProvider';
|
||||
|
||||
function WrapInProvider(store, Component, props) {
|
||||
function WrapInProvider(store: any, Component: any, props: any) {
|
||||
return (
|
||||
<Provider store={store}>
|
||||
<Component {...props} />
|
||||
@@ -16,13 +18,13 @@ function WrapInProvider(store, Component, props) {
|
||||
}
|
||||
|
||||
/** @ngInject */
|
||||
export function reactContainer($route, $location, $injector, $rootScope, contextSrv: ContextSrv) {
|
||||
export function reactContainer($route: any, $location: any, $injector: any, $rootScope: any, contextSrv: ContextSrv) {
|
||||
return {
|
||||
restrict: 'E',
|
||||
template: '',
|
||||
link(scope, elem) {
|
||||
link(scope: any, elem: JQuery) {
|
||||
// Check permissions for this component
|
||||
const { roles } = $route.current.locals;
|
||||
const roles: string[] = $route.current.locals.roles;
|
||||
if (roles && roles.length) {
|
||||
if (!roles.some(r => contextSrv.hasRole(r))) {
|
||||
$location.url('/');
|
||||
|
||||
@@ -4,6 +4,7 @@ import * as dateMath from 'app/core/utils/datemath';
|
||||
import { angularMocks, sinon } from '../lib/common';
|
||||
import { PanelModel } from 'app/features/dashboard/state/PanelModel';
|
||||
import { PanelPlugin } from 'app/types';
|
||||
import { RawTimeRange } from '@grafana/ui/src/types';
|
||||
|
||||
export function ControllerTestContext(this: any) {
|
||||
const self = this;
|
||||
@@ -27,8 +28,8 @@ export function ControllerTestContext(this: any) {
|
||||
};
|
||||
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('datasourceSrv', self.datasourceSrv);
|
||||
$provide.value('annotationsSrv', self.annotationsSrv);
|
||||
@@ -36,14 +37,14 @@ export function ControllerTestContext(this: any) {
|
||||
$provide.value('templateSrv', self.templateSrv);
|
||||
$provide.value('$element', self.$element);
|
||||
$provide.value('$sanitize', self.$sanitize);
|
||||
_.each(mocks, (value, key) => {
|
||||
_.each(mocks, (value: any, key: any) => {
|
||||
$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.$location = $location;
|
||||
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.$location = $location;
|
||||
self.$browser = $browser;
|
||||
@@ -115,28 +116,30 @@ export function ServiceTestContext(this: any) {
|
||||
self.backendSrv = {};
|
||||
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]);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
this.createService = name => {
|
||||
this.createService = (name: string) => {
|
||||
// @ts-ignore
|
||||
return angularMocks.inject(($q, $rootScope, $httpBackend, $injector, $location, $timeout) => {
|
||||
self.$q = $q;
|
||||
self.$rootScope = $rootScope;
|
||||
self.$httpBackend = $httpBackend;
|
||||
self.$location = $location;
|
||||
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.$rootScope.onAppEvent = () => {};
|
||||
self.$rootScope.appEvent = () => {};
|
||||
self.$timeout = $timeout;
|
||||
|
||||
self.service = $injector.get(name);
|
||||
});
|
||||
self.service = $injector.get(name);
|
||||
}
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -144,10 +147,16 @@ export function DashboardViewStateStub(this: any) {
|
||||
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) {
|
||||
return this.time;
|
||||
}
|
||||
@@ -155,17 +164,17 @@ export function TimeSrvStub(this: any) {
|
||||
from: dateMath.parse(this.time.from, false),
|
||||
to: dateMath.parse(this.time.to, true),
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
this.setTime = function(time: any) {
|
||||
setTime(time: any) {
|
||||
this.time = time;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export function ContextSrvStub(this: any) {
|
||||
this.hasRole = () => {
|
||||
export class ContextSrvStub {
|
||||
hasRole() {
|
||||
return true;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export function TemplateSrvStub(this: any) {
|
||||
|
||||
Reference in New Issue
Block a user