dashboardSrv-specs.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. define([
  2. 'services/dashboard/dashboardSrv'
  3. ], function() {
  4. 'use strict';
  5. describe('when creating new dashboard with defaults only', function() {
  6. var model;
  7. beforeEach(module('grafana.services'));
  8. beforeEach(inject(function(dashboardSrv) {
  9. model = dashboardSrv.create({});
  10. }));
  11. it('should have title', function() {
  12. expect(model.title).to.be('No Title');
  13. });
  14. it('should have default properties', function() {
  15. expect(model.rows.length).to.be(0);
  16. expect(model.nav.length).to.be(1);
  17. });
  18. });
  19. describe('when getting next panel id', function() {
  20. var model;
  21. beforeEach(module('grafana.services'));
  22. beforeEach(inject(function(dashboardSrv) {
  23. model = dashboardSrv.create({
  24. rows: [{ panels: [{ id: 5 }]}]
  25. });
  26. }));
  27. it('should return max id + 1', function() {
  28. expect(model.getNextPanelId()).to.be(6);
  29. });
  30. });
  31. describe('row and panel manipulation', function() {
  32. var dashboard;
  33. beforeEach(module('grafana.services'));
  34. beforeEach(inject(function(dashboardSrv) {
  35. dashboard = dashboardSrv.create({});
  36. }));
  37. it('row span should sum spans', function() {
  38. var spanLeft = dashboard.rowSpan({ panels: [{ span: 2 }, { span: 3 }] });
  39. expect(spanLeft).to.be(5);
  40. });
  41. it('adding default should split span in half', function() {
  42. dashboard.rows = [{ panels: [{ span: 12, id: 7 }] }];
  43. dashboard.add_panel({span: 4}, dashboard.rows[0]);
  44. expect(dashboard.rows[0].panels[0].span).to.be(6);
  45. expect(dashboard.rows[0].panels[1].span).to.be(6);
  46. expect(dashboard.rows[0].panels[1].id).to.be(8);
  47. });
  48. it('duplicate panel should try to add it to same row', function() {
  49. var panel = { span: 4, attr: '123', id: 10 };
  50. dashboard.rows = [{ panels: [panel] }];
  51. dashboard.duplicatePanel(panel, dashboard.rows[0]);
  52. expect(dashboard.rows[0].panels[0].span).to.be(4);
  53. expect(dashboard.rows[0].panels[1].span).to.be(4);
  54. expect(dashboard.rows[0].panels[1].attr).to.be('123');
  55. expect(dashboard.rows[0].panels[1].id).to.be(11);
  56. });
  57. it('duplicate should add row if there is no space left', function() {
  58. var panel = { span: 12, attr: '123' };
  59. dashboard.rows = [{ panels: [panel] }];
  60. dashboard.duplicatePanel(panel, dashboard.rows[0]);
  61. expect(dashboard.rows[0].panels[0].span).to.be(12);
  62. expect(dashboard.rows[0].panels.length).to.be(1);
  63. expect(dashboard.rows[1].panels[0].attr).to.be('123');
  64. });
  65. });
  66. describe('when creating dashboard with old schema', function() {
  67. var model;
  68. var graph;
  69. beforeEach(module('grafana.services'));
  70. beforeEach(inject(function(dashboardSrv) {
  71. model = dashboardSrv.create({
  72. services: { filter: { time: { from: 'now-1d', to: 'now'}, list: [1] }},
  73. pulldowns: [
  74. {
  75. type: 'filtering',
  76. enable: true
  77. },
  78. {
  79. type: 'annotations',
  80. enable: true,
  81. annotations: [{name: 'old'}]
  82. }
  83. ],
  84. rows: [
  85. {
  86. panels: [
  87. {
  88. type: 'graphite',
  89. legend: true,
  90. aliasYAxis: { test: 2 },
  91. grid: { min: 1, max: 10 }
  92. }
  93. ]
  94. }
  95. ]
  96. });
  97. graph = model.rows[0].panels[0];
  98. }));
  99. it('should have title', function() {
  100. expect(model.title).to.be('No Title');
  101. });
  102. it('should have panel id', function() {
  103. expect(graph.id).to.be(1);
  104. });
  105. it('should move time and filtering list', function() {
  106. expect(model.time.from).to.be('now-1d');
  107. expect(model.templating.list[0]).to.be(1);
  108. });
  109. it('graphite panel should change name too graph', function() {
  110. expect(graph.type).to.be('graph');
  111. });
  112. it('update legend setting', function() {
  113. expect(graph.legend.show).to.be(true);
  114. });
  115. it('update grid options', function() {
  116. expect(graph.grid.leftMin).to.be(1);
  117. expect(graph.grid.leftMax).to.be(10);
  118. });
  119. it('move aliasYAxis to series override', function() {
  120. expect(graph.seriesOverrides[0].alias).to.be("test");
  121. expect(graph.seriesOverrides[0].yaxis).to.be(2);
  122. });
  123. it('should move pulldowns to new schema', function() {
  124. expect(model.templating.enable).to.be(true);
  125. expect(model.annotations.enable).to.be(true);
  126. expect(model.annotations.list[0].name).to.be('old');
  127. });
  128. it('dashboard schema version should be set to latest', function() {
  129. expect(model.version).to.be(5);
  130. });
  131. });
  132. });