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
abc8077a
Commit
abc8077a
authored
Aug 07, 2014
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added some unit tests for graph panel controller
parent
02fb2baf
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
70 additions
and
39 deletions
+70
-39
src/app/panels/graph/module.html
+1
-1
src/app/panels/graph/module.js
+7
-4
src/test/specs/graph-ctrl-specs.js
+44
-0
src/test/specs/graph-panel-controller-specs.js
+0
-32
src/test/specs/helpers.js
+17
-2
src/test/test-main.js
+1
-0
No files found.
src/app/panels/graph/module.html
View file @
abc8077a
<div
ng-controller=
'
graph
'
<div
ng-controller=
'
GraphCtrl
'
style=
"min-height:{{panel.height || row.height}}"
style=
"min-height:{{panel.height || row.height}}"
ng-class=
"{'panel-fullscreen': fullscreen}"
>
ng-class=
"{'panel-fullscreen': fullscreen}"
>
...
...
src/app/panels/graph/module.js
View file @
abc8077a
...
@@ -19,6 +19,7 @@ define([
...
@@ -19,6 +19,7 @@ define([
'kbn'
,
'kbn'
,
'moment'
,
'moment'
,
'./timeSeries'
,
'./timeSeries'
,
'services/panelSrv'
,
'services/annotationsSrv'
,
'services/annotationsSrv'
,
'services/datasourceSrv'
,
'services/datasourceSrv'
,
'jquery.flot'
,
'jquery.flot'
,
...
@@ -35,7 +36,7 @@ function (angular, app, $, _, kbn, moment, timeSeries) {
...
@@ -35,7 +36,7 @@ function (angular, app, $, _, kbn, moment, timeSeries) {
var
module
=
angular
.
module
(
'grafana.panels.graph'
,
[]);
var
module
=
angular
.
module
(
'grafana.panels.graph'
,
[]);
app
.
useModule
(
module
);
app
.
useModule
(
module
);
module
.
controller
(
'
graph
'
,
function
(
$scope
,
$rootScope
,
$timeout
,
panelSrv
,
annotationsSrv
)
{
module
.
controller
(
'
GraphCtrl
'
,
function
(
$scope
,
$rootScope
,
$timeout
,
panelSrv
,
annotationsSrv
)
{
$scope
.
panelMeta
=
{
$scope
.
panelMeta
=
{
modals
:
[],
modals
:
[],
...
@@ -190,12 +191,14 @@ function (angular, app, $, _, kbn, moment, timeSeries) {
...
@@ -190,12 +191,14 @@ function (angular, app, $, _, kbn, moment, timeSeries) {
$scope
.
init
=
function
()
{
$scope
.
init
=
function
()
{
panelSrv
.
init
(
$scope
);
panelSrv
.
init
(
$scope
);
$scope
.
hiddenSeries
=
{};
$scope
.
hiddenSeries
=
{};
$scope
.
get_data
();
if
(
!
$scope
.
skipDataOnInit
)
{
$scope
.
get_data
();
}
};
};
$scope
.
updateTimeRange
=
function
()
{
$scope
.
updateTimeRange
=
function
()
{
$scope
.
range
=
this
.
filter
.
timeRange
();
$scope
.
range
=
$scope
.
filter
.
timeRange
();
$scope
.
rangeUnparsed
=
this
.
filter
.
timeRange
(
false
);
$scope
.
rangeUnparsed
=
$scope
.
filter
.
timeRange
(
false
);
$scope
.
resolution
=
Math
.
ceil
(
$
(
window
).
width
()
*
(
$scope
.
panel
.
span
/
12
));
$scope
.
resolution
=
Math
.
ceil
(
$
(
window
).
width
()
*
(
$scope
.
panel
.
span
/
12
));
$scope
.
interval
=
'10m'
;
$scope
.
interval
=
'10m'
;
...
...
src/test/specs/graph-ctrl-specs.js
0 → 100644
View file @
abc8077a
define
([
'./helpers'
,
'panels/graph/module'
],
function
(
helpers
)
{
'use strict'
;
describe
(
'GraphCtrl'
,
function
()
{
var
ctx
=
new
helpers
.
ControllerTestContext
();
beforeEach
(
module
(
'grafana.services'
));
beforeEach
(
module
(
'grafana.panels.graph'
));
beforeEach
(
ctx
.
providePhase
());
beforeEach
(
ctx
.
createControllerPhase
(
'GraphCtrl'
));
describe
(
'get_data with 2 series'
,
function
()
{
beforeEach
(
function
()
{
ctx
.
annotationsSrv
.
getAnnotations
=
sinon
.
stub
().
returns
(
ctx
.
$q
.
when
([]));
ctx
.
datasource
.
query
=
sinon
.
stub
().
returns
(
ctx
.
$q
.
when
({
data
:
[
{
target
:
'test.cpu1'
,
datapoints
:
[[
1
,
10
]]},
{
target
:
'test.cpu2'
,
datapoints
:
[[
1
,
10
]]}
]
}));
ctx
.
scope
.
render
=
sinon
.
spy
();
ctx
.
scope
.
get_data
();
ctx
.
scope
.
$digest
();
});
it
(
'should build legend model'
,
function
()
{
expect
(
ctx
.
scope
.
legend
[
0
].
alias
).
to
.
be
(
'test.cpu1'
);
expect
(
ctx
.
scope
.
legend
[
1
].
alias
).
to
.
be
(
'test.cpu2'
);
});
it
(
'should send time series to render'
,
function
()
{
var
data
=
ctx
.
scope
.
render
.
getCall
(
0
).
args
[
0
];
expect
(
data
.
length
).
to
.
be
(
2
);
});
});
});
});
src/test/specs/graph-panel-controller-specs.js
deleted
100644 → 0
View file @
02fb2baf
/*define([
'panels/graphite/module'
], function() {
'use strict';
describe('Graph panel controller', function() {
var _graphPanelCtrl;
beforeEach(module('grafana.panels.graphite'));
beforeEach(module(function($provide){
$provide.value('filterSrv',{});
}));
beforeEach(inject(function($controller, $rootScope) {
_graphPanelCtrl = $controller('graphite', {
$scope: $rootScope.$new()
});
}));
describe('init', function() {
beforeEach(function() {
});
it('asd', function() {
});
});
});
});
*/
\ No newline at end of file
src/test/specs/helpers.js
View file @
abc8077a
define
([
define
([
],
function
()
{
'kbn'
],
function
(
kbn
)
{
'use strict'
;
'use strict'
;
function
ControllerTestContext
()
{
function
ControllerTestContext
()
{
var
self
=
this
;
var
self
=
this
;
this
.
timeRange
=
{
from
:
'now-1h'
,
to
:
'now'
};
this
.
datasource
=
{};
this
.
datasource
=
{};
this
.
annotationsSrv
=
{};
this
.
datasourceSrv
=
{
this
.
datasourceSrv
=
{
getMetricSources
:
function
()
{},
getMetricSources
:
function
()
{},
get
:
function
()
{
return
self
.
datasource
;
}
get
:
function
()
{
return
self
.
datasource
;
}
...
@@ -14,6 +17,7 @@ define([
...
@@ -14,6 +17,7 @@ define([
this
.
providePhase
=
function
()
{
this
.
providePhase
=
function
()
{
return
module
(
function
(
$provide
)
{
return
module
(
function
(
$provide
)
{
$provide
.
value
(
'datasourceSrv'
,
self
.
datasourceSrv
);
$provide
.
value
(
'datasourceSrv'
,
self
.
datasourceSrv
);
$provide
.
value
(
'annotationsSrv'
,
self
.
annotationsSrv
);
});
});
};
};
...
@@ -22,9 +26,20 @@ define([
...
@@ -22,9 +26,20 @@ define([
self
.
scope
=
$rootScope
.
$new
();
self
.
scope
=
$rootScope
.
$new
();
self
.
scope
.
panel
=
{};
self
.
scope
.
panel
=
{};
self
.
scope
.
filter
=
{
self
.
scope
.
filter
=
{
timeRange
:
function
()
{}
timeRange
:
function
(
parse
)
{
if
(
!
parse
)
{
return
self
.
timeRange
;
}
return
{
from
:
kbn
.
parseDate
(
self
.
timeRange
.
from
),
to
:
kbn
.
parseDate
(
self
.
timeRange
.
to
)
};
}
};
};
self
.
scope
.
colors
=
[];
for
(
var
i
=
0
;
i
<
50
;
i
++
)
{
self
.
scope
.
colors
.
push
(
'#'
+
i
);
}
self
.
$q
=
$q
;
self
.
$q
=
$q
;
self
.
scope
.
skipDataOnInit
=
true
;
self
.
scope
.
skipDataOnInit
=
true
;
self
.
controller
=
$controller
(
controllerName
,
{
self
.
controller
=
$controller
(
controllerName
,
{
...
...
src/test/test-main.js
View file @
abc8077a
...
@@ -118,6 +118,7 @@ require([
...
@@ -118,6 +118,7 @@ require([
'specs/parser-specs'
,
'specs/parser-specs'
,
'specs/gfunc-specs'
,
'specs/gfunc-specs'
,
'specs/graphiteTargetCtrl-specs'
,
'specs/graphiteTargetCtrl-specs'
,
'specs/graph-ctrl-specs'
,
'specs/filterSrv-specs'
,
'specs/filterSrv-specs'
,
'specs/kbn-format-specs'
,
'specs/kbn-format-specs'
,
'specs/dashboardModel-specs'
,
'specs/dashboardModel-specs'
,
...
...
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