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
034ca696
Commit
034ca696
authored
Aug 01, 2018
by
Tobias Skarhed
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add mock constructor
parent
7f4723a9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
18 deletions
+41
-18
public/app/features/templating/specs/variable_srv.jest.ts
+41
-18
No files found.
public/app/features/templating/specs/variable_srv.jest.ts
View file @
034ca696
...
...
@@ -19,8 +19,14 @@ describe('VariableSrv', function() {
},
templateSrv
:
{
setGrafanaVariable
:
jest
.
fn
(),
init
:
()
=>
{},
init
:
vars
=>
{
this
.
variables
=
vars
;
},
updateTemplateData
:
()
=>
{},
replace
:
str
=>
str
.
replace
(
this
.
regex
,
match
=>
{
return
match
;
}),
},
$location
:
{
search
:
()
=>
{},
...
...
@@ -54,17 +60,20 @@ describe('VariableSrv', function() {
scenario
.
setupFn
();
var
ds
:
any
=
{};
ds
.
metricFindQuery
=
Promise
.
resolve
(
scenario
.
queryResult
);
ds
.
metricFindQuery
=
()
=>
Promise
.
resolve
(
scenario
.
queryResult
);
ctx
.
variableSrv
=
new
VariableSrv
(
ctx
.
$rootScope
,
$q
,
ctx
.
$location
,
ctx
.
$injector
,
ctx
.
templateSrv
);
ctx
.
variableSrv
.
timeSrv
=
ctx
.
timeSrv
;
console
.
log
(
ctx
.
variableSrv
.
timeSrv
);
ctx
.
variableSrv
.
datasourceSrv
=
{
get
:
Promise
.
resolve
(
ds
),
ctx
.
datasourceSrv
=
{
get
:
()
=>
Promise
.
resolve
(
ds
),
getMetricSources
:
()
=>
scenario
.
metricSources
,
};
ctx
.
$injector
.
instantiate
=
(
ctr
,
model
)
=>
{
return
getVarMockConstructor
(
ctr
,
model
,
ctx
);
};
ctx
.
variableSrv
.
init
({
templating
:
{
list
:
[]
},
updateSubmenuVisibility
:
()
=>
{},
...
...
@@ -74,7 +83,6 @@ describe('VariableSrv', function() {
ctx
.
variableSrv
.
addVariable
(
scenario
.
variable
);
ctx
.
variableSrv
.
updateOptions
(
scenario
.
variable
);
// ctx.$rootScope.$digest();
});
fn
(
scenario
);
...
...
@@ -128,17 +136,17 @@ describe('VariableSrv', function() {
});
it
(
'should set $__auto_interval_test'
,
function
()
{
var
call
=
ctx
.
templateSrv
.
setGrafanaVariable
.
firstCall
;
expect
(
call
.
args
[
0
]).
toBe
(
'$__auto_interval_test'
);
expect
(
call
.
args
[
1
]).
toBe
(
'12h'
);
var
call
=
ctx
.
templateSrv
.
setGrafanaVariable
.
mock
.
calls
[
0
]
;
expect
(
call
[
0
]).
toBe
(
'$__auto_interval_test'
);
expect
(
call
[
1
]).
toBe
(
'12h'
);
});
// updateAutoValue() gets called twice: once directly once via VariableSrv.validateVariableSelectionState()
// So use lastCall instead of a specific call number
it
(
'should set $__auto_interval'
,
function
()
{
var
call
=
ctx
.
templateSrv
.
setGrafanaVariable
.
lastCall
;
expect
(
call
.
args
[
0
]).
toBe
(
'$__auto_interval'
);
expect
(
call
.
args
[
1
]).
toBe
(
'12h'
);
var
call
=
ctx
.
templateSrv
.
setGrafanaVariable
.
mock
.
calls
.
pop
()
;
expect
(
call
[
0
]).
toBe
(
'$__auto_interval'
);
expect
(
call
[
1
]).
toBe
(
'12h'
);
});
});
...
...
@@ -547,7 +555,7 @@ describe('VariableSrv', function() {
ctx
.
variableSrv
.
updateOptions
(
variable1
);
ctx
.
variableSrv
.
updateOptions
(
variable2
);
ctx
.
$rootScope
.
$digest
();
//
ctx.$rootScope.$digest();
});
it
(
'should update options array'
,
function
()
{
...
...
@@ -568,7 +576,7 @@ describe('VariableSrv', function() {
// So check that all calls are valid rather than expect a specific number and/or ordering of calls
for
(
var
i
=
0
;
i
<
ctx
.
templateSrv
.
setGrafanaVariable
.
mock
.
calls
.
length
;
i
++
)
{
var
call
=
ctx
.
templateSrv
.
setGrafanaVariable
.
mock
.
calls
[
i
];
switch
(
call
.
args
[
0
])
{
switch
(
call
[
0
])
{
case
'$__auto_interval_variable1'
:
expect
(
call
[
1
]).
toBe
(
'12h'
);
variable1Set
=
true
;
...
...
@@ -586,10 +594,25 @@ describe('VariableSrv', function() {
break
;
}
}
expect
(
variable1Set
).
to
Be
.
e
qual
(
true
);
expect
(
variable2Set
).
to
Be
.
e
qual
(
true
);
expect
(
legacySet
).
to
Be
.
e
qual
(
true
);
expect
(
unknownSet
).
to
Be
.
e
qual
(
false
);
expect
(
variable1Set
).
to
E
qual
(
true
);
expect
(
variable2Set
).
to
E
qual
(
true
);
expect
(
legacySet
).
to
E
qual
(
true
);
expect
(
unknownSet
).
to
E
qual
(
false
);
});
});
});
function
getVarMockConstructor
(
variable
,
model
,
ctx
)
{
switch
(
model
.
model
.
type
)
{
case
'datasource'
:
return
new
variable
(
model
.
model
,
ctx
.
datasourceSrv
,
ctx
.
variableSrv
,
ctx
.
templateSrv
);
case
'query'
:
return
new
variable
(
model
.
model
,
ctx
.
datasourceSrv
,
ctx
.
templateSrv
,
ctx
.
variableSrv
);
case
'interval'
:
return
new
variable
(
model
.
model
,
ctx
.
timeSrv
,
ctx
.
templateSrv
,
ctx
.
variableSrv
);
case
'custom'
:
return
new
variable
(
model
.
model
,
ctx
.
variableSrv
);
default
:
return
new
variable
(
model
.
model
);
}
}
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