dashboardSrv-specs.js 5.2 KB

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