graph_ctrl_specs.ts 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. ///<reference path="../../../../headers/common.d.ts" />
  2. import {
  3. describe,
  4. beforeEach,
  5. it,
  6. expect,
  7. angularMocks
  8. } from "../../../../../test/lib/common";
  9. import moment from "moment";
  10. import { GraphCtrl } from "../module";
  11. import helpers from "../../../../../test/specs/helpers";
  12. describe("GraphCtrl", function() {
  13. var ctx = new helpers.ControllerTestContext();
  14. beforeEach(angularMocks.module("grafana.services"));
  15. beforeEach(angularMocks.module("grafana.controllers"));
  16. beforeEach(
  17. angularMocks.module(function($compileProvider) {
  18. $compileProvider.preAssignBindingsEnabled(true);
  19. })
  20. );
  21. beforeEach(ctx.providePhase());
  22. beforeEach(ctx.createPanelController(GraphCtrl));
  23. beforeEach(() => {
  24. ctx.ctrl.annotationsPromise = Promise.resolve({});
  25. ctx.ctrl.updateTimeRange();
  26. });
  27. describe("when time series are outside range", function() {
  28. beforeEach(function() {
  29. var data = [
  30. {
  31. target: "test.cpu1",
  32. datapoints: [[45, 1234567890], [60, 1234567899]]
  33. }
  34. ];
  35. ctx.ctrl.range = { from: moment().valueOf(), to: moment().valueOf() };
  36. ctx.ctrl.onDataReceived(data);
  37. });
  38. it("should set datapointsOutside", function() {
  39. expect(ctx.ctrl.dataWarning.title).to.be(
  40. "Data points outside time range"
  41. );
  42. });
  43. });
  44. describe("when time series are inside range", function() {
  45. beforeEach(function() {
  46. var range = {
  47. from: moment()
  48. .subtract(1, "days")
  49. .valueOf(),
  50. to: moment().valueOf()
  51. };
  52. var data = [
  53. {
  54. target: "test.cpu1",
  55. datapoints: [[45, range.from + 1000], [60, range.from + 10000]]
  56. }
  57. ];
  58. ctx.ctrl.range = range;
  59. ctx.ctrl.onDataReceived(data);
  60. });
  61. it("should set datapointsOutside", function() {
  62. expect(ctx.ctrl.dataWarning).to.be(null);
  63. });
  64. });
  65. describe("datapointsCount given 2 series", function() {
  66. beforeEach(function() {
  67. var data = [
  68. { target: "test.cpu1", datapoints: [] },
  69. { target: "test.cpu2", datapoints: [] }
  70. ];
  71. ctx.ctrl.onDataReceived(data);
  72. });
  73. it("should set datapointsCount warning", function() {
  74. expect(ctx.ctrl.dataWarning.title).to.be("No data points");
  75. });
  76. });
  77. });