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
35cc85bf
Commit
35cc85bf
authored
Jul 26, 2018
by
Tobias Skarhed
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
All tests passing. Remove Karma test.
parent
931b944c
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
234 deletions
+13
-234
public/app/features/templating/specs/variable_srv_init.jest.ts
+13
-18
public/app/features/templating/specs/variable_srv_init_specs.ts
+0
-216
No files found.
public/app/features/templating/specs/variable_srv_init.jest.ts
View file @
35cc85bf
...
...
@@ -3,7 +3,6 @@ import '../all';
import
_
from
'lodash'
;
import
{
VariableSrv
}
from
'../variable_srv'
;
import
$q
from
'q'
;
// import { TemplateSrv } from '../template_srv';
describe
(
'VariableSrv init'
,
function
()
{
let
templateSrv
=
{
...
...
@@ -12,22 +11,21 @@ describe('VariableSrv init', function() {
},
variableInitialized
:
()
=>
{},
updateTemplateData
:
()
=>
{},
replace
:
()
=>
' /pee$/'
,
replace
:
str
=>
str
.
replace
(
this
.
regex
,
match
=>
{
return
match
;
}),
};
// let templateSrv = new TemplateSrv();
let
$injector
=
<
any
>
{};
let
$rootscope
=
{
$on
:
()
=>
{},
};
let
ctx
=
<
any
>
{
datasourceSrv
:
{},
$location
:
{},
dashboard
:
{},
};
let
ctx
=
<
any
>
{};
function
describeInitScenario
(
desc
,
fn
)
{
describe
(
desc
,
function
()
{
describe
(
desc
,
()
=>
{
var
scenario
:
any
=
{
urlParams
:
{},
setup
:
setupFn
=>
{
...
...
@@ -43,7 +41,7 @@ describe('VariableSrv init', function() {
},
datasourceSrv
:
{
get
:
()
=>
Promise
.
resolve
(
ctx
.
datasource
),
getMetricSources
:
()
=>
Promise
.
resolve
(
scenario
.
metricSources
)
,
getMetricSources
:
()
=>
scenario
.
metricSources
,
},
templateSrv
,
};
...
...
@@ -87,7 +85,6 @@ describe('VariableSrv init', function() {
});
it
(
'should update current value'
,
()
=>
{
console
.
log
(
type
);
expect
(
scenario
.
variables
[
0
].
current
.
value
).
toBe
(
'new'
);
expect
(
scenario
.
variables
[
0
].
current
.
text
).
toBe
(
'new'
);
});
...
...
@@ -150,8 +147,7 @@ describe('VariableSrv init', function() {
];
});
it
(
'should update current value'
,
function
()
{
console
.
log
(
ctx
.
variableSrv
.
variables
[
0
].
options
);
it
(
'should update current value'
,
()
=>
{
var
variable
=
ctx
.
variableSrv
.
variables
[
0
];
expect
(
variable
.
options
.
length
).
toBe
(
2
);
});
...
...
@@ -175,7 +171,7 @@ 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
).
toBe
(
2
);
expect
(
variable
.
current
.
value
[
0
]).
toBe
(
'val2'
);
...
...
@@ -185,7 +181,7 @@ describe('VariableSrv init', function() {
expect
(
variable
.
options
[
1
].
selected
).
toBe
(
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
).
toBe
(
false
);
});
...
...
@@ -209,7 +205,7 @@ 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
).
toBe
(
2
);
expect
(
variable
.
current
.
value
[
0
]).
toBe
(
'val2'
);
...
...
@@ -219,7 +215,7 @@ describe('VariableSrv init', function() {
expect
(
variable
.
options
[
1
].
selected
).
toBe
(
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
).
toBe
(
false
);
});
...
...
@@ -227,7 +223,6 @@ describe('VariableSrv init', function() {
});
function
getVarMockConstructor
(
variable
,
model
,
ctx
)
{
// console.log(model.model.type);
switch
(
model
.
model
.
type
)
{
case
'datasource'
:
return
new
variable
(
model
.
model
,
ctx
.
datasourceSrv
,
ctx
.
variableSrv
,
ctx
.
templateSrv
);
...
...
public/app/features/templating/specs/variable_srv_init_specs.ts
deleted
100644 → 0
View file @
931b944c
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'
;
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
();
})
);
function
describeInitScenario
(
desc
,
fn
)
{
describe
(
desc
,
function
()
{
var
scenario
:
any
=
{
urlParams
:
{},
setup
:
setupFn
=>
{
scenario
.
setupFn
=
setupFn
;
},
};
beforeEach
(
function
()
{
scenario
.
setupFn
();
ctx
.
datasource
=
{};
ctx
.
datasource
.
metricFindQuery
=
sinon
.
stub
().
returns
(
ctx
.
$q
.
when
(
scenario
.
queryResult
));
ctx
.
datasourceSrv
.
get
=
sinon
.
stub
().
returns
(
ctx
.
$q
.
when
(
ctx
.
datasource
));
ctx
.
datasourceSrv
.
getMetricSources
=
sinon
.
stub
().
returns
(
scenario
.
metricSources
);
ctx
.
$location
.
search
=
sinon
.
stub
().
returns
(
scenario
.
urlParams
);
ctx
.
dashboard
=
{
templating
:
{
list
:
scenario
.
variables
},
events
:
new
Emitter
(),
};
ctx
.
variableSrv
.
init
(
ctx
.
dashboard
);
ctx
.
$rootScope
.
$digest
();
scenario
.
variables
=
ctx
.
variableSrv
.
variables
;
});
fn
(
scenario
);
});
}
[
'query'
,
'interval'
,
'custom'
,
'datasource'
].
forEach
(
type
=>
{
describeInitScenario
(
'when setting '
+
type
+
' variable via url'
,
scenario
=>
{
scenario
.
setup
(()
=>
{
scenario
.
variables
=
[
{
name
:
'apps'
,
type
:
type
,
current
:
{
text
:
'test'
,
value
:
'test'
},
options
:
[{
text
:
'test'
,
value
:
'test'
}],
},
];
scenario
.
urlParams
[
'var-apps'
]
=
'new'
;
scenario
.
metricSources
=
[];
});
it
(
'should update current value'
,
()
=>
{
expect
(
scenario
.
variables
[
0
].
current
.
value
).
to
.
be
(
'new'
);
expect
(
scenario
.
variables
[
0
].
current
.
text
).
to
.
be
(
'new'
);
});
});
});
describe
(
'given dependent variables'
,
()
=>
{
var
variableList
=
[
{
name
:
'app'
,
type
:
'query'
,
query
:
''
,
current
:
{
text
:
'app1'
,
value
:
'app1'
},
options
:
[{
text
:
'app1'
,
value
:
'app1'
}],
},
{
name
:
'server'
,
type
:
'query'
,
refresh
:
1
,
query
:
'$app.*'
,
current
:
{
text
:
'server1'
,
value
:
'server1'
},
options
:
[{
text
:
'server1'
,
value
:
'server1'
}],
},
];
describeInitScenario
(
'when setting parent var from url'
,
scenario
=>
{
scenario
.
setup
(()
=>
{
scenario
.
variables
=
_
.
cloneDeep
(
variableList
);
scenario
.
urlParams
[
'var-app'
]
=
'google'
;
scenario
.
queryResult
=
[{
text
:
'google-server1'
},
{
text
:
'google-server2'
}];
});
it
(
'should update child variable'
,
()
=>
{
expect
(
scenario
.
variables
[
1
].
options
.
length
).
to
.
be
(
2
);
expect
(
scenario
.
variables
[
1
].
current
.
text
).
to
.
be
(
'google-server1'
);
});
it
(
'should only update it once'
,
()
=>
{
expect
(
ctx
.
datasource
.
metricFindQuery
.
callCount
).
to
.
be
(
1
);
});
});
});
describeInitScenario
(
'when datasource variable is initialized'
,
scenario
=>
{
scenario
.
setup
(()
=>
{
scenario
.
variables
=
[
{
type
:
'datasource'
,
query
:
'graphite'
,
name
:
'test'
,
current
:
{
value
:
'backend4_pee'
,
text
:
'backend4_pee'
},
regex
:
'/pee$/'
,
},
];
scenario
.
metricSources
=
[
{
name
:
'backend1'
,
meta
:
{
id
:
'influx'
}
},
{
name
:
'backend2_pee'
,
meta
:
{
id
:
'graphite'
}
},
{
name
:
'backend3'
,
meta
:
{
id
:
'graphite'
}
},
{
name
:
'backend4_pee'
,
meta
:
{
id
:
'graphite'
}
},
];
});
it
(
'should update current value'
,
function
()
{
var
variable
=
ctx
.
variableSrv
.
variables
[
0
];
expect
(
variable
.
options
.
length
).
to
.
be
(
2
);
});
});
describeInitScenario
(
'when template variable is present in url multiple times'
,
scenario
=>
{
scenario
.
setup
(()
=>
{
scenario
.
variables
=
[
{
name
:
'apps'
,
type
:
'query'
,
multi
:
true
,
current
:
{
text
:
'val1'
,
value
:
'val1'
},
options
:
[
{
text
:
'val1'
,
value
:
'val1'
},
{
text
:
'val2'
,
value
:
'val2'
},
{
text
:
'val3'
,
value
:
'val3'
,
selected
:
true
},
],
},
];
scenario
.
urlParams
[
'var-apps'
]
=
[
'val2'
,
'val1'
];
});
it
(
'should update current value'
,
function
()
{
var
variable
=
ctx
.
variableSrv
.
variables
[
0
];
expect
(
variable
.
current
.
value
.
length
).
to
.
be
(
2
);
expect
(
variable
.
current
.
value
[
0
]).
to
.
be
(
'val2'
);
expect
(
variable
.
current
.
value
[
1
]).
to
.
be
(
'val1'
);
expect
(
variable
.
current
.
text
).
to
.
be
(
'val2 + val1'
);
expect
(
variable
.
options
[
0
].
selected
).
to
.
be
(
true
);
expect
(
variable
.
options
[
1
].
selected
).
to
.
be
(
true
);
});
it
(
'should set options that are not in value to selected false'
,
function
()
{
var
variable
=
ctx
.
variableSrv
.
variables
[
0
];
expect
(
variable
.
options
[
2
].
selected
).
to
.
be
(
false
);
});
});
describeInitScenario
(
'when template variable is present in url multiple times using key/values'
,
scenario
=>
{
scenario
.
setup
(()
=>
{
scenario
.
variables
=
[
{
name
:
'apps'
,
type
:
'query'
,
multi
:
true
,
current
:
{
text
:
'Val1'
,
value
:
'val1'
},
options
:
[
{
text
:
'Val1'
,
value
:
'val1'
},
{
text
:
'Val2'
,
value
:
'val2'
},
{
text
:
'Val3'
,
value
:
'val3'
,
selected
:
true
},
],
},
];
scenario
.
urlParams
[
'var-apps'
]
=
[
'val2'
,
'val1'
];
});
it
(
'should update current value'
,
function
()
{
var
variable
=
ctx
.
variableSrv
.
variables
[
0
];
expect
(
variable
.
current
.
value
.
length
).
to
.
be
(
2
);
expect
(
variable
.
current
.
value
[
0
]).
to
.
be
(
'val2'
);
expect
(
variable
.
current
.
value
[
1
]).
to
.
be
(
'val1'
);
expect
(
variable
.
current
.
text
).
to
.
be
(
'Val2 + Val1'
);
expect
(
variable
.
options
[
0
].
selected
).
to
.
be
(
true
);
expect
(
variable
.
options
[
1
].
selected
).
to
.
be
(
true
);
});
it
(
'should set options that are not in value to selected false'
,
function
()
{
var
variable
=
ctx
.
variableSrv
.
variables
[
0
];
expect
(
variable
.
options
[
2
].
selected
).
to
.
be
(
false
);
});
});
});
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