dashboardSrv-specs.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. });
  65. describe('when creating dashboard with editable false', function() {
  66. var model;
  67. beforeEach(function() {
  68. model = _dashboardSrv.create({
  69. editable: false
  70. });
  71. });
  72. it('should set editable false', function() {
  73. expect(model.editable).to.be(false);
  74. });
  75. });
  76. describe('when creating dashboard with old schema', function() {
  77. var model;
  78. var graph;
  79. beforeEach(function() {
  80. model = _dashboardSrv.create({
  81. services: { filter: { time: { from: 'now-1d', to: 'now'}, list: [{}] }},
  82. pulldowns: [
  83. {type: 'filtering', enable: true},
  84. {type: 'annotations', enable: true, annotations: [{name: 'old'}]}
  85. ],
  86. rows: [
  87. {
  88. panels: [
  89. {type: 'graphite', legend: true, aliasYAxis: { test: 2 }, grid: { min: 1, max: 10 }}
  90. ]
  91. }
  92. ]
  93. });
  94. graph = model.rows[0].panels[0];
  95. });
  96. it('should have title', function() {
  97. expect(model.title).to.be('No Title');
  98. });
  99. it('should have panel id', function() {
  100. expect(graph.id).to.be(1);
  101. });
  102. it('should move time and filtering list', function() {
  103. expect(model.time.from).to.be('now-1d');
  104. expect(model.templating.list[0].allFormat).to.be('glob');
  105. });
  106. it('graphite panel should change name too graph', function() {
  107. expect(graph.type).to.be('graph');
  108. });
  109. it('update legend setting', function() {
  110. expect(graph.legend.show).to.be(true);
  111. });
  112. it('update grid options', function() {
  113. expect(graph.grid.leftMin).to.be(1);
  114. expect(graph.grid.leftMax).to.be(10);
  115. });
  116. it('move aliasYAxis to series override', function() {
  117. expect(graph.seriesOverrides[0].alias).to.be("test");
  118. expect(graph.seriesOverrides[0].yaxis).to.be(2);
  119. });
  120. it('should move pulldowns to new schema', function() {
  121. expect(model.annotations.list[0].name).to.be('old');
  122. });
  123. it('dashboard schema version should be set to latest', function() {
  124. expect(model.schemaVersion).to.be(6);
  125. });
  126. });
  127. describe('when creating dashboard model with missing list for annoations or templating', function() {
  128. var model;
  129. beforeEach(function() {
  130. model = _dashboardSrv.create({
  131. annotations: {
  132. enable: true,
  133. },
  134. templating: {
  135. enable: true
  136. }
  137. });
  138. });
  139. it('should add empty list', function() {
  140. expect(model.annotations.list.length).to.be(0);
  141. expect(model.templating.list.length).to.be(0);
  142. });
  143. });
  144. describe('Given editable false dashboard', function() {
  145. var model;
  146. beforeEach(function() {
  147. model = _dashboardSrv.create({
  148. editable: false,
  149. });
  150. });
  151. it('Should set meta canEdit and canSave to false', function() {
  152. expect(model.meta.canSave).to.be(false);
  153. expect(model.meta.canEdit).to.be(false);
  154. });
  155. it('getSaveModelClone should remove meta', function() {
  156. var clone = model.getSaveModelClone();
  157. expect(clone.meta).to.be(undefined);
  158. });
  159. });
  160. });
  161. });