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
751f68ab
Unverified
Commit
751f68ab
authored
Jul 26, 2018
by
Marcus Efraimsson
Committed by
GitHub
Jul 26, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #12723 from dehrax/12224-variable-srv
Karma to Jest: variable_srv_init
parents
48d9b375
35cc85bf
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
83 additions
and
61 deletions
+83
-61
public/app/features/templating/specs/variable_srv_init.jest.ts
+83
-61
No files found.
public/app/features/templating/specs/variable_srv_init
_specs
.ts
→
public/app/features/templating/specs/variable_srv_init
.jest
.ts
View file @
751f68ab
import
{
describe
,
beforeEach
,
it
,
sinon
,
expect
,
angularMocks
}
from
'test/lib/common'
;
import
'../all'
;
import
_
from
'lodash'
;
import
helpers
from
'test/specs/helpers
'
;
import
{
Emitter
}
from
'app/core/core
'
;
import
{
VariableSrv
}
from
'../variable_srv
'
;
import
$q
from
'q
'
;
describe
(
'VariableSrv init'
,
function
()
{
var
ctx
=
new
helpers
.
ControllerTestContext
();
beforeEach
(
angularMocks
.
module
(
'grafana.core'
));
beforeEach
(
angularMocks
.
module
(
'grafana.controllers'
));
beforeEach
(
angularMocks
.
module
(
'grafana.services'
));
beforeEach
(
angularMocks
.
module
(
function
(
$compileProvider
)
{
$compileProvider
.
preAssignBindingsEnabled
(
true
);
})
);
beforeEach
(
ctx
.
providePhase
([
'datasourceSrv'
,
'timeSrv'
,
'templateSrv'
,
'$location'
]));
beforeEach
(
angularMocks
.
inject
((
$rootScope
,
$q
,
$location
,
$injector
)
=>
{
ctx
.
$q
=
$q
;
ctx
.
$rootScope
=
$rootScope
;
ctx
.
$location
=
$location
;
ctx
.
variableSrv
=
$injector
.
get
(
'variableSrv'
);
ctx
.
$rootScope
.
$digest
();
})
);
let
templateSrv
=
{
init
:
vars
=>
{
this
.
variables
=
vars
;
},
variableInitialized
:
()
=>
{},
updateTemplateData
:
()
=>
{},
replace
:
str
=>
str
.
replace
(
this
.
regex
,
match
=>
{
return
match
;
}),
};
let
$injector
=
<
any
>
{};
let
$rootscope
=
{
$on
:
()
=>
{},
};
let
ctx
=
<
any
>
{};
function
describeInitScenario
(
desc
,
fn
)
{
describe
(
desc
,
function
()
{
describe
(
desc
,
()
=>
{
var
scenario
:
any
=
{
urlParams
:
{},
setup
:
setupFn
=>
{
...
...
@@ -38,22 +33,34 @@ describe('VariableSrv init', function() {
},
};
beforeEach
(
function
()
{
beforeEach
(
async
()
=>
{
scenario
.
setupFn
();
ctx
.
datasource
=
{};
ctx
.
datasource
.
metricFindQuery
=
sinon
.
stub
().
returns
(
ctx
.
$q
.
when
(
scenario
.
queryResult
));
ctx
=
{
datasource
:
{
metricFindQuery
:
jest
.
fn
(()
=>
Promise
.
resolve
(
scenario
.
queryResult
)),
},
datasourceSrv
:
{
get
:
()
=>
Promise
.
resolve
(
ctx
.
datasource
),
getMetricSources
:
()
=>
scenario
.
metricSources
,
},
templateSrv
,
};
ctx
.
datasourceSrv
.
get
=
sinon
.
stub
().
returns
(
ctx
.
$q
.
when
(
ctx
.
datasource
));
ctx
.
datasourceSrv
.
getMetricSources
=
sinon
.
stub
().
returns
(
scenario
.
metricSources
);
ctx
.
variableSrv
=
new
VariableSrv
(
$rootscope
,
$q
,
{},
$injector
,
templateSrv
);
ctx
.
$location
.
search
=
sinon
.
stub
().
returns
(
scenario
.
urlParams
);
ctx
.
dashboard
=
{
$injector
.
instantiate
=
(
variable
,
model
)
=>
{
return
getVarMockConstructor
(
variable
,
model
,
ctx
);
};
ctx
.
variableSrv
.
datasource
=
ctx
.
datasource
;
ctx
.
variableSrv
.
datasourceSrv
=
ctx
.
datasourceSrv
;
ctx
.
variableSrv
.
$location
.
search
=
()
=>
scenario
.
urlParams
;
ctx
.
variableSrv
.
dashboard
=
{
templating
:
{
list
:
scenario
.
variables
},
events
:
new
Emitter
(),
};
ctx
.
variableSrv
.
init
(
ctx
.
dashboard
);
ctx
.
$rootScope
.
$digest
();
await
ctx
.
variableSrv
.
init
(
ctx
.
variableSrv
.
dashboard
);
scenario
.
variables
=
ctx
.
variableSrv
.
variables
;
});
...
...
@@ -78,8 +85,8 @@ describe('VariableSrv init', function() {
});
it
(
'should update current value'
,
()
=>
{
expect
(
scenario
.
variables
[
0
].
current
.
value
).
to
.
b
e
(
'new'
);
expect
(
scenario
.
variables
[
0
].
current
.
text
).
to
.
b
e
(
'new'
);
expect
(
scenario
.
variables
[
0
].
current
.
value
).
to
B
e
(
'new'
);
expect
(
scenario
.
variables
[
0
].
current
.
text
).
to
B
e
(
'new'
);
});
});
});
...
...
@@ -111,12 +118,12 @@ describe('VariableSrv init', function() {
});
it
(
'should update child variable'
,
()
=>
{
expect
(
scenario
.
variables
[
1
].
options
.
length
).
to
.
b
e
(
2
);
expect
(
scenario
.
variables
[
1
].
current
.
text
).
to
.
b
e
(
'google-server1'
);
expect
(
scenario
.
variables
[
1
].
options
.
length
).
to
B
e
(
2
);
expect
(
scenario
.
variables
[
1
].
current
.
text
).
to
B
e
(
'google-server1'
);
});
it
(
'should only update it once'
,
()
=>
{
expect
(
ctx
.
datasource
.
metricFindQuery
.
callCount
).
to
.
be
(
1
);
expect
(
ctx
.
variableSrv
.
datasource
.
metricFindQuery
).
toHaveBeenCalledTimes
(
1
);
});
});
});
...
...
@@ -140,9 +147,9 @@ describe('VariableSrv init', function() {
];
});
it
(
'should update current value'
,
function
()
{
it
(
'should update current value'
,
()
=>
{
var
variable
=
ctx
.
variableSrv
.
variables
[
0
];
expect
(
variable
.
options
.
length
).
to
.
b
e
(
2
);
expect
(
variable
.
options
.
length
).
to
B
e
(
2
);
});
});
...
...
@@ -164,19 +171,19 @@ describe('VariableSrv init', function() {
scenario
.
urlParams
[
'var-apps'
]
=
[
'val2'
,
'val1'
];
});
it
(
'should update current value'
,
function
()
{
it
(
'should update current value'
,
()
=>
{
var
variable
=
ctx
.
variableSrv
.
variables
[
0
];
expect
(
variable
.
current
.
value
.
length
).
to
.
b
e
(
2
);
expect
(
variable
.
current
.
value
[
0
]).
to
.
b
e
(
'val2'
);
expect
(
variable
.
current
.
value
[
1
]).
to
.
b
e
(
'val1'
);
expect
(
variable
.
current
.
text
).
to
.
b
e
(
'val2 + val1'
);
expect
(
variable
.
options
[
0
].
selected
).
to
.
b
e
(
true
);
expect
(
variable
.
options
[
1
].
selected
).
to
.
b
e
(
true
);
expect
(
variable
.
current
.
value
.
length
).
to
B
e
(
2
);
expect
(
variable
.
current
.
value
[
0
]).
to
B
e
(
'val2'
);
expect
(
variable
.
current
.
value
[
1
]).
to
B
e
(
'val1'
);
expect
(
variable
.
current
.
text
).
to
B
e
(
'val2 + val1'
);
expect
(
variable
.
options
[
0
].
selected
).
to
B
e
(
true
);
expect
(
variable
.
options
[
1
].
selected
).
to
B
e
(
true
);
});
it
(
'should set options that are not in value to selected false'
,
function
()
{
it
(
'should set options that are not in value to selected false'
,
()
=>
{
var
variable
=
ctx
.
variableSrv
.
variables
[
0
];
expect
(
variable
.
options
[
2
].
selected
).
to
.
b
e
(
false
);
expect
(
variable
.
options
[
2
].
selected
).
to
B
e
(
false
);
});
});
...
...
@@ -198,19 +205,34 @@ describe('VariableSrv init', function() {
scenario
.
urlParams
[
'var-apps'
]
=
[
'val2'
,
'val1'
];
});
it
(
'should update current value'
,
function
()
{
it
(
'should update current value'
,
()
=>
{
var
variable
=
ctx
.
variableSrv
.
variables
[
0
];
expect
(
variable
.
current
.
value
.
length
).
to
.
b
e
(
2
);
expect
(
variable
.
current
.
value
[
0
]).
to
.
b
e
(
'val2'
);
expect
(
variable
.
current
.
value
[
1
]).
to
.
b
e
(
'val1'
);
expect
(
variable
.
current
.
text
).
to
.
b
e
(
'Val2 + Val1'
);
expect
(
variable
.
options
[
0
].
selected
).
to
.
b
e
(
true
);
expect
(
variable
.
options
[
1
].
selected
).
to
.
b
e
(
true
);
expect
(
variable
.
current
.
value
.
length
).
to
B
e
(
2
);
expect
(
variable
.
current
.
value
[
0
]).
to
B
e
(
'val2'
);
expect
(
variable
.
current
.
value
[
1
]).
to
B
e
(
'val1'
);
expect
(
variable
.
current
.
text
).
to
B
e
(
'Val2 + Val1'
);
expect
(
variable
.
options
[
0
].
selected
).
to
B
e
(
true
);
expect
(
variable
.
options
[
1
].
selected
).
to
B
e
(
true
);
});
it
(
'should set options that are not in value to selected false'
,
function
()
{
it
(
'should set options that are not in value to selected false'
,
()
=>
{
var
variable
=
ctx
.
variableSrv
.
variables
[
0
];
expect
(
variable
.
options
[
2
].
selected
).
to
.
b
e
(
false
);
expect
(
variable
.
options
[
2
].
selected
).
to
B
e
(
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
.
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