singlestat-specs.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. define([
  2. 'helpers',
  3. 'features/panel/panelSrv',
  4. 'features/panel/panelHelper',
  5. 'panels/singlestat/module'
  6. ], function(helpers) {
  7. 'use strict';
  8. describe('SingleStatCtrl', function() {
  9. var ctx = new helpers.ControllerTestContext();
  10. function singleStatScenario(desc, func) {
  11. describe(desc, function() {
  12. ctx.setup = function (setupFunc) {
  13. beforeEach(module('grafana.services'));
  14. beforeEach(module('grafana.panels.singlestat'));
  15. beforeEach(ctx.providePhase());
  16. beforeEach(ctx.createControllerPhase('SingleStatCtrl'));
  17. beforeEach(function() {
  18. setupFunc();
  19. ctx.datasource.query = sinon.stub().returns(ctx.$q.when({
  20. data: [ { target: 'test.cpu1', datapoints: ctx.datapoints } ]
  21. }));
  22. ctx.scope.refreshData(ctx.datasource);
  23. ctx.scope.$digest();
  24. ctx.data = ctx.scope.data;
  25. });
  26. };
  27. func(ctx);
  28. });
  29. }
  30. singleStatScenario('with defaults', function(ctx) {
  31. ctx.setup(function() {
  32. ctx.datapoints = [[10,1], [20,2]];
  33. });
  34. it('Should use series avg as default main value', function() {
  35. expect(ctx.data.value).to.be(15);
  36. expect(ctx.data.valueRounded).to.be(15);
  37. });
  38. it('should set formated falue', function() {
  39. expect(ctx.data.valueFormated).to.be('15');
  40. });
  41. });
  42. singleStatScenario('MainValue should use same number for decimals as displayed when checking thresholds', function(ctx) {
  43. ctx.setup(function() {
  44. ctx.datapoints = [[99.999,1], [99.99999,2]];
  45. });
  46. it('Should be rounded', function() {
  47. expect(ctx.data.value).to.be(99.999495);
  48. expect(ctx.data.valueRounded).to.be(100);
  49. });
  50. it('should set formated falue', function() {
  51. expect(ctx.data.valueFormated).to.be('100');
  52. });
  53. });
  54. singleStatScenario('When value to text mapping is specified', function(ctx) {
  55. ctx.setup(function() {
  56. ctx.datapoints = [[10,1]];
  57. ctx.scope.panel.valueMaps = [{value: '10', text: 'OK'}];
  58. });
  59. it('Should replace value with text', function() {
  60. expect(ctx.data.value).to.be(10);
  61. expect(ctx.data.valueFormated).to.be('OK');
  62. });
  63. });
  64. });
  65. });