dashboardSrv-specs.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. define([
  2. 'features/dashboard/dashboardSrv'
  3. ], function() {
  4. 'use strict';
  5. describe('dashboardSrv', function() {
  6. var _dashboardSrv;
  7. beforeEach(module('grafana.services'));
  8. beforeEach(inject(function(dashboardSrv) {
  9. _dashboardSrv = dashboardSrv;
  10. }));
  11. describe('when creating new dashboard with defaults only', function() {
  12. var model;
  13. beforeEach(function() {
  14. model = _dashboardSrv.create({}, {});
  15. });
  16. it('should have title', function() {
  17. expect(model.title).to.be('No Title');
  18. });
  19. it('should have meta', function() {
  20. expect(model.meta.canSave).to.be(true);
  21. expect(model.meta.canShare).to.be(true);
  22. });
  23. it('should have default properties', function() {
  24. expect(model.rows.length).to.be(0);
  25. expect(model.nav.length).to.be(1);
  26. });
  27. });
  28. describe('when getting next panel id', function() {
  29. var model;
  30. beforeEach(function() {
  31. model = _dashboardSrv.create({
  32. rows: [{ panels: [{ id: 5 }]}]
  33. });
  34. });
  35. it('should return max id + 1', function() {
  36. expect(model.getNextPanelId()).to.be(6);
  37. });
  38. });
  39. describe('row and panel manipulation', function() {
  40. var dashboard;
  41. beforeEach(function() {
  42. dashboard = _dashboardSrv.create({});
  43. });
  44. it('row span should sum spans', function() {
  45. var spanLeft = dashboard.rowSpan({ panels: [{ span: 2 }, { span: 3 }] });
  46. expect(spanLeft).to.be(5);
  47. });
  48. it('adding default should split span in half', function() {
  49. dashboard.rows = [{ panels: [{ span: 12, id: 7 }] }];
  50. dashboard.add_panel({span: 4}, dashboard.rows[0]);
  51. expect(dashboard.rows[0].panels[0].span).to.be(6);
  52. expect(dashboard.rows[0].panels[1].span).to.be(6);
  53. expect(dashboard.rows[0].panels[1].id).to.be(8);
  54. });
  55. it('duplicate panel should try to add it to same row', function() {
  56. var panel = { span: 4, attr: '123', id: 10 };
  57. dashboard.rows = [{ panels: [panel] }];
  58. dashboard.duplicatePanel(panel, dashboard.rows[0]);
  59. expect(dashboard.rows[0].panels[0].span).to.be(4);
  60. expect(dashboard.rows[0].panels[1].span).to.be(4);
  61. expect(dashboard.rows[0].panels[1].attr).to.be('123');
  62. expect(dashboard.rows[0].panels[1].id).to.be(11);
  63. });
  64. it('duplicate panel should remove repeat data', function() {
  65. var panel = { span: 4, attr: '123', id: 10, repeat: 'asd', scopedVars: { test: 'asd' }};
  66. dashboard.rows = [{ panels: [panel] }];
  67. dashboard.duplicatePanel(panel, dashboard.rows[0]);
  68. expect(dashboard.rows[0].panels[1].repeat).to.be(undefined);
  69. expect(dashboard.rows[0].panels[1].scopedVars).to.be(undefined);
  70. });
  71. });
  72. describe('when creating dashboard with editable false', function() {
  73. var model;
  74. beforeEach(function() {
  75. model = _dashboardSrv.create({
  76. editable: false
  77. });
  78. });
  79. it('should set editable false', function() {
  80. expect(model.editable).to.be(false);
  81. });
  82. });
  83. describe('when creating dashboard with old schema', function() {
  84. var model;
  85. var graph;
  86. beforeEach(function() {
  87. model = _dashboardSrv.create({
  88. services: { filter: { time: { from: 'now-1d', to: 'now'}, list: [{}] }},
  89. pulldowns: [
  90. {type: 'filtering', enable: true},
  91. {type: 'annotations', enable: true, annotations: [{name: 'old'}]}
  92. ],
  93. rows: [
  94. {
  95. panels: [
  96. {type: 'graphite', legend: true, aliasYAxis: { test: 2 }, grid: { min: 1, max: 10 }}
  97. ]
  98. }
  99. ]
  100. });
  101. graph = model.rows[0].panels[0];
  102. });
  103. it('should have title', function() {
  104. expect(model.title).to.be('No Title');
  105. });
  106. it('should have panel id', function() {
  107. expect(graph.id).to.be(1);
  108. });
  109. it('should move time and filtering list', function() {
  110. expect(model.time.from).to.be('now-1d');
  111. expect(model.templating.list[0].allFormat).to.be('glob');
  112. });
  113. it('graphite panel should change name too graph', function() {
  114. expect(graph.type).to.be('graph');
  115. });
  116. it('update legend setting', function() {
  117. expect(graph.legend.show).to.be(true);
  118. });
  119. it('update grid options', function() {
  120. expect(graph.grid.leftMin).to.be(1);
  121. expect(graph.grid.leftMax).to.be(10);
  122. });
  123. it('move aliasYAxis to series override', function() {
  124. expect(graph.seriesOverrides[0].alias).to.be("test");
  125. expect(graph.seriesOverrides[0].yaxis).to.be(2);
  126. });
  127. it('should move pulldowns to new schema', function() {
  128. expect(model.annotations.list[0].name).to.be('old');
  129. });
  130. it('dashboard schema version should be set to latest', function() {
  131. expect(model.schemaVersion).to.be(6);
  132. });
  133. });
  134. describe('when creating dashboard model with missing list for annoations or templating', function() {
  135. var model;
  136. beforeEach(function() {
  137. model = _dashboardSrv.create({
  138. annotations: {
  139. enable: true,
  140. },
  141. templating: {
  142. enable: true
  143. }
  144. });
  145. });
  146. it('should add empty list', function() {
  147. expect(model.annotations.list.length).to.be(0);
  148. expect(model.templating.list.length).to.be(0);
  149. });
  150. });
  151. describe('Given editable false dashboard', function() {
  152. var model;
  153. beforeEach(function() {
  154. model = _dashboardSrv.create({
  155. editable: false,
  156. });
  157. });
  158. it('Should set meta canEdit and canSave to false', function() {
  159. expect(model.meta.canSave).to.be(false);
  160. expect(model.meta.canEdit).to.be(false);
  161. });
  162. it('getSaveModelClone should remove meta', function() {
  163. var clone = model.getSaveModelClone();
  164. expect(clone.meta).to.be(undefined);
  165. });
  166. });
  167. });
  168. });