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
b0a24ae4
Commit
b0a24ae4
authored
Jan 25, 2016
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tech(singlestat): move singlestat test to plugin
and change to typescript
parent
42802ac7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
121 additions
and
63 deletions
+121
-63
public/app/plugins/panel/singlestat/specs/singlestat-specs.ts
+63
-63
public/app/plugins/panel/singlestat/specs/singlestat_panel_spec.ts
+58
-0
No files found.
public/
test/specs/singlestat-specs.j
s
→
public/
app/plugins/panel/singlestat/specs/singlestat-specs.t
s
View file @
b0a24ae4
define
([
'angular'
,
'./helpers'
,
'app/plugins/panel/singlestat/controller'
,
'app/features/panel/panel_srv'
,
'app/features/panel/panel_helper'
,
],
function
(
angular
,
helpers
,
SingleStatCtrl
)
{
'use strict'
;
///<reference path="../../../../headers/common.d.ts" />
angular
.
module
(
'grafana.controllers'
).
controller
(
'SingleStatCtrl'
,
SingleStatCtrl
)
;
import
{
describe
,
beforeEach
,
it
,
sinon
,
expect
,
angularMocks
}
from
'../../../../../test/lib/common'
;
describe
(
'SingleStatCtrl'
,
function
()
{
var
ctx
=
new
helpers
.
ControllerTestContext
()
;
import
'app/features/panel/panel_srv'
;
import
'app/features/panel/panel_helper'
;
function
singleStatScenario
(
desc
,
func
)
{
import
angular
from
'angular'
;
import
helpers
from
'../../../../../test/specs/helpers'
;
import
{
SingleStatCtrl
}
from
'../controller'
;
describe
(
desc
,
function
()
{
ctx
.
setup
=
function
(
setupFunc
)
{
angular
.
module
(
'grafana.controllers'
).
controller
(
'SingleStatCtrl'
,
SingleStatCtrl
);
beforeEach
(
module
(
'grafana.services'
));
beforeEach
(
module
(
'grafana.controllers'
)
);
describe
(
'SingleStatCtrl'
,
function
()
{
var
ctx
=
new
helpers
.
ControllerTestContext
(
);
beforeEach
(
ctx
.
providePhase
());
beforeEach
(
ctx
.
createControllerPhase
(
'SingleStatCtrl'
));
function
singleStatScenario
(
desc
,
func
)
{
beforeEach
(
function
()
{
setupFunc
();
ctx
.
datasource
.
query
=
sinon
.
stub
().
returns
(
ctx
.
$q
.
when
({
data
:
[{
target
:
'test.cpu1'
,
datapoints
:
ctx
.
datapoints
}]
}));
describe
(
desc
,
function
()
{
ctx
.
scope
.
refreshData
(
ctx
.
datasource
);
ctx
.
scope
.
$digest
();
ctx
.
data
=
ctx
.
scope
.
data
;
});
};
ctx
.
setup
=
function
(
setupFunc
)
{
func
(
ctx
);
});
}
beforeEach
(
angularMocks
.
module
(
'grafana.services'
));
beforeEach
(
angularMocks
.
module
(
'grafana.controllers'
));
singleStatScenario
(
'with defaults'
,
function
(
ctx
)
{
ctx
.
setup
(
function
()
{
ctx
.
datapoints
=
[[
10
,
1
],
[
20
,
2
]];
});
beforeEach
(
ctx
.
providePhase
());
beforeEach
(
ctx
.
createControllerPhase
(
'SingleStatCtrl'
));
it
(
'Should use series avg as default main value'
,
function
()
{
expect
(
ctx
.
data
.
value
).
to
.
be
(
15
);
expect
(
ctx
.
data
.
valueRounded
).
to
.
be
(
15
);
});
beforeEach
(
function
()
{
setupFunc
();
ctx
.
datasource
.
query
=
sinon
.
stub
().
returns
(
ctx
.
$q
.
when
({
data
:
[{
target
:
'test.cpu1'
,
datapoints
:
ctx
.
datapoints
}]
}));
it
(
'should set formated falue'
,
function
()
{
expect
(
ctx
.
data
.
valueFormated
).
to
.
be
(
'15'
);
});
ctx
.
scope
.
refreshData
(
ctx
.
datasource
);
ctx
.
scope
.
$digest
();
ctx
.
data
=
ctx
.
scope
.
data
;
});
};
func
(
ctx
);
});
}
singleStatScenario
(
'with defaults'
,
function
(
ctx
)
{
ctx
.
setup
(
function
()
{
ctx
.
datapoints
=
[[
10
,
1
],
[
20
,
2
]];
});
singleStatScenario
(
'MainValue should use same number for decimals as displayed when checking thresholds'
,
function
(
ctx
)
{
ctx
.
setup
(
function
()
{
ctx
.
datapoints
=
[[
99.999
,
1
],
[
99.99999
,
2
]];
});
it
(
'Should use series avg as default main value'
,
function
()
{
expect
(
ctx
.
data
.
value
).
to
.
be
(
15
);
expect
(
ctx
.
data
.
valueRounded
).
to
.
be
(
15
);
});
it
(
'should set formated falue'
,
function
()
{
expect
(
ctx
.
data
.
valueFormated
).
to
.
be
(
'15'
);
});
});
it
(
'Should be rounded'
,
function
(
)
{
expect
(
ctx
.
data
.
value
).
to
.
be
(
99.999495
);
expect
(
ctx
.
data
.
valueRounded
).
to
.
be
(
100
)
;
});
singleStatScenario
(
'MainValue should use same number for decimals as displayed when checking thresholds'
,
function
(
ctx
)
{
ctx
.
setup
(
function
()
{
ctx
.
datapoints
=
[[
99.999
,
1
],
[
99.99999
,
2
]]
;
});
it
(
'should set formated falue
'
,
function
()
{
expect
(
ctx
.
data
.
valueFormated
).
to
.
be
(
'100'
);
}
);
it
(
'Should be rounded
'
,
function
()
{
expect
(
ctx
.
data
.
value
).
to
.
be
(
99.999495
);
expect
(
ctx
.
data
.
valueRounded
).
to
.
be
(
100
);
});
singleStatScenario
(
'When value to text mapping is specified'
,
function
(
ctx
)
{
ctx
.
setup
(
function
()
{
ctx
.
datapoints
=
[[
10
,
1
]];
ctx
.
scope
.
panel
.
valueMaps
=
[{
value
:
'10'
,
text
:
'OK'
}];
});
it
(
'should set formated falue'
,
function
()
{
expect
(
ctx
.
data
.
valueFormated
).
to
.
be
(
'100'
);
});
});
it
(
'Should replace value with text'
,
function
()
{
expect
(
ctx
.
data
.
value
).
to
.
be
(
10
);
expect
(
ctx
.
data
.
valueFormated
).
to
.
be
(
'OK'
);
});
singleStatScenario
(
'When value to text mapping is specified'
,
function
(
ctx
)
{
ctx
.
setup
(
function
()
{
ctx
.
datapoints
=
[[
10
,
1
]];
ctx
.
scope
.
panel
.
valueMaps
=
[{
value
:
'10'
,
text
:
'OK'
}];
});
it
(
'Should replace value with text'
,
function
()
{
expect
(
ctx
.
data
.
value
).
to
.
be
(
10
);
expect
(
ctx
.
data
.
valueFormated
).
to
.
be
(
'OK'
);
});
});
});
public/app/plugins/panel/singlestat/specs/singlestat_panel_spec.ts
View file @
b0a24ae4
import
{
describe
,
beforeEach
,
it
,
sinon
,
expect
}
from
'test/lib/common'
;
import
{
getColorForValue
}
from
'../module'
;
describe
(
'grafanaSingleStat'
,
function
()
{
describe
(
'legacy thresholds'
,
()
=>
{
describe
(
'positive thresholds'
,
()
=>
{
var
data
:
any
=
{
colorMap
:
[
'green'
,
'yellow'
,
'red'
],
thresholds
:
[
0
,
20
,
50
]
};
it
(
'5 should return green'
,
()
=>
{
expect
(
getColorForValue
(
data
,
5
)).
to
.
be
(
'green'
);
});
it
(
'25 should return green'
,
()
=>
{
expect
(
getColorForValue
(
data
,
25
)).
to
.
be
(
'yellow'
);
});
it
(
'55 should return green'
,
()
=>
{
expect
(
getColorForValue
(
data
,
55
)).
to
.
be
(
'red'
);
});
});
});
describe
(
'negative thresholds'
,
()
=>
{
var
data
:
any
=
{
colorMap
:
[
'green'
,
'yellow'
,
'red'
],
thresholds
:
[
-
20
,
0
,
20
]
};
it
(
'-30 should return green'
,
()
=>
{
expect
(
getColorForValue
(
data
,
-
30
)).
to
.
be
(
'green'
);
});
it
(
'1 should return green'
,
()
=>
{
expect
(
getColorForValue
(
data
,
1
)).
to
.
be
(
'yellow'
);
});
it
(
'22 should return green'
,
()
=>
{
expect
(
getColorForValue
(
data
,
22
)).
to
.
be
(
'red'
);
});
});
describe
(
'negative thresholds'
,
()
=>
{
var
data
:
any
=
{
colorMap
:
[
'green'
,
'yellow'
,
'red'
],
thresholds
:
[
-
40
,
-
27
,
20
]
};
it
(
'-30 should return green'
,
()
=>
{
expect
(
getColorForValue
(
data
,
-
26
)).
to
.
be
(
'yellow'
);
});
});
});
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