Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
e3d33e6c
Commit
e3d33e6c
authored
Mar 24, 2019
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: Removed implicit anys in react container and test helpers
parent
090b3f6c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
37 deletions
+48
-37
public/app/routes/ReactContainer.tsx
+6
-4
public/test/specs/helpers.ts
+42
-33
No files found.
public/app/routes/ReactContainer.tsx
View file @
e3d33e6c
// 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
.
local
s
;
const
roles
:
string
[]
=
$route
.
current
.
locals
.
role
s
;
if
(
roles
&&
roles
.
length
)
{
if
(
!
roles
.
some
(
r
=>
contextSrv
.
hasRole
(
r
)))
{
$location
.
url
(
'/'
);
...
...
public/test/specs/helpers.ts
View file @
e3d33e6c
...
...
@@ -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
,
ke
y
)
=>
{
_
.
each
(
mocks
,
(
value
:
any
,
key
:
an
y
)
=>
{
$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
;
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
=
()
=>
{};
}
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
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment