dynamic_dashboard_srv_specs.ts 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. // import {describe, beforeEach, it, expect, angularMocks} from 'test/lib/common';
  2. //
  3. // import '../dashboard_srv';
  4. // import {DynamicDashboardSrv} from '../dynamic_dashboard_srv';
  5. //
  6. // function dynamicDashScenario(desc, func) {
  7. //
  8. // describe.skip(desc, function() {
  9. // var ctx: any = {};
  10. //
  11. // ctx.setup = function (setupFunc) {
  12. //
  13. // beforeEach(angularMocks.module('grafana.core'));
  14. // beforeEach(angularMocks.module('grafana.services'));
  15. // beforeEach(angularMocks.module(function($provide) {
  16. // $provide.value('contextSrv', {
  17. // user: { timezone: 'utc'}
  18. // });
  19. // }));
  20. //
  21. // beforeEach(angularMocks.inject(function(dashboardSrv) {
  22. // ctx.dashboardSrv = dashboardSrv;
  23. //
  24. // var model = {
  25. // rows: [],
  26. // templating: { list: [] }
  27. // };
  28. //
  29. // setupFunc(model);
  30. // ctx.dash = ctx.dashboardSrv.create(model);
  31. // ctx.dynamicDashboardSrv = new DynamicDashboardSrv();
  32. // ctx.dynamicDashboardSrv.init(ctx.dash);
  33. // ctx.dynamicDashboardSrv.process();
  34. // ctx.rows = ctx.dash.rows;
  35. // }));
  36. // };
  37. //
  38. // func(ctx);
  39. // });
  40. // }
  41. //
  42. // dynamicDashScenario('given dashboard with panel repeat', function(ctx) {
  43. // ctx.setup(function(dash) {
  44. // dash.rows.push({
  45. // panels: [{id: 2, repeat: 'apps'}]
  46. // });
  47. // dash.templating.list.push({
  48. // name: 'apps',
  49. // current: {
  50. // text: 'se1, se2, se3',
  51. // value: ['se1', 'se2', 'se3']
  52. // },
  53. // options: [
  54. // {text: 'se1', value: 'se1', selected: true},
  55. // {text: 'se2', value: 'se2', selected: true},
  56. // {text: 'se3', value: 'se3', selected: true},
  57. // {text: 'se4', value: 'se4', selected: false}
  58. // ]
  59. // });
  60. // });
  61. //
  62. // it('should repeat panel one time', function() {
  63. // expect(ctx.rows[0].panels.length).to.be(3);
  64. // });
  65. //
  66. // it('should mark panel repeated', function() {
  67. // expect(ctx.rows[0].panels[0].repeat).to.be('apps');
  68. // expect(ctx.rows[0].panels[1].repeatPanelId).to.be(2);
  69. // });
  70. //
  71. // it('should set scopedVars on panels', function() {
  72. // expect(ctx.rows[0].panels[0].scopedVars.apps.value).to.be('se1');
  73. // expect(ctx.rows[0].panels[1].scopedVars.apps.value).to.be('se2');
  74. // expect(ctx.rows[0].panels[2].scopedVars.apps.value).to.be('se3');
  75. // });
  76. //
  77. // describe('After a second iteration', function() {
  78. // var repeatedPanelAfterIteration1;
  79. //
  80. // beforeEach(function() {
  81. // repeatedPanelAfterIteration1 = ctx.rows[0].panels[1];
  82. // ctx.rows[0].panels[0].fill = 10;
  83. // ctx.dynamicDashboardSrv.process();
  84. // });
  85. //
  86. // it('should have reused same panel instances', function() {
  87. // expect(ctx.rows[0].panels[1]).to.be(repeatedPanelAfterIteration1);
  88. // });
  89. //
  90. // it('reused panel should copy properties from source', function() {
  91. // expect(ctx.rows[0].panels[1].fill).to.be(10);
  92. // });
  93. //
  94. // it('should have same panel count', function() {
  95. // expect(ctx.rows[0].panels.length).to.be(3);
  96. // });
  97. // });
  98. //
  99. // describe('After a second iteration with different variable', function() {
  100. // beforeEach(function() {
  101. // ctx.dash.templating.list.push({
  102. // name: 'server',
  103. // current: { text: 'se1, se2, se3', value: ['se1']},
  104. // options: [{text: 'se1', value: 'se1', selected: true}]
  105. // });
  106. // ctx.rows[0].panels[0].repeat = "server";
  107. // ctx.dynamicDashboardSrv.process();
  108. // });
  109. //
  110. // it('should remove scopedVars value for last variable', function() {
  111. // expect(ctx.rows[0].panels[0].scopedVars.apps).to.be(undefined);
  112. // });
  113. //
  114. // it('should have new variable value in scopedVars', function() {
  115. // expect(ctx.rows[0].panels[0].scopedVars.server.value).to.be("se1");
  116. // });
  117. // });
  118. //
  119. // describe('After a second iteration and selected values reduced', function() {
  120. // beforeEach(function() {
  121. // ctx.dash.templating.list[0].options[1].selected = false;
  122. // ctx.dynamicDashboardSrv.process();
  123. // });
  124. //
  125. // it('should clean up repeated panel', function() {
  126. // expect(ctx.rows[0].panels.length).to.be(2);
  127. // });
  128. // });
  129. //
  130. // describe('After a second iteration and panel repeat is turned off', function() {
  131. // beforeEach(function() {
  132. // ctx.rows[0].panels[0].repeat = null;
  133. // ctx.dynamicDashboardSrv.process();
  134. // });
  135. //
  136. // it('should clean up repeated panel', function() {
  137. // expect(ctx.rows[0].panels.length).to.be(1);
  138. // });
  139. //
  140. // it('should remove scoped vars from reused panel', function() {
  141. // expect(ctx.rows[0].panels[0].scopedVars).to.be(undefined);
  142. // });
  143. // });
  144. //
  145. // });
  146. //
  147. // dynamicDashScenario('given dashboard with row repeat', function(ctx) {
  148. // ctx.setup(function(dash) {
  149. // dash.rows.push({
  150. // repeat: 'servers',
  151. // panels: [{id: 2}]
  152. // });
  153. // dash.rows.push({panels: []});
  154. // dash.templating.list.push({
  155. // name: 'servers',
  156. // current: {
  157. // text: 'se1, se2',
  158. // value: ['se1', 'se2']
  159. // },
  160. // options: [
  161. // {text: 'se1', value: 'se1', selected: true},
  162. // {text: 'se2', value: 'se2', selected: true},
  163. // ]
  164. // });
  165. // });
  166. //
  167. // it('should repeat row one time', function() {
  168. // expect(ctx.rows.length).to.be(3);
  169. // });
  170. //
  171. // it('should keep panel ids on first row', function() {
  172. // expect(ctx.rows[0].panels[0].id).to.be(2);
  173. // });
  174. //
  175. // it('should keep first row as repeat', function() {
  176. // expect(ctx.rows[0].repeat).to.be('servers');
  177. // });
  178. //
  179. // it('should clear repeat field on repeated row', function() {
  180. // expect(ctx.rows[1].repeat).to.be(null);
  181. // });
  182. //
  183. // it('should add scopedVars to rows', function() {
  184. // expect(ctx.rows[0].scopedVars.servers.value).to.be('se1');
  185. // expect(ctx.rows[1].scopedVars.servers.value).to.be('se2');
  186. // });
  187. //
  188. // it('should generate a repeartRowId based on repeat row index', function() {
  189. // expect(ctx.rows[1].repeatRowId).to.be(1);
  190. // expect(ctx.rows[1].repeatIteration).to.be(ctx.dynamicDashboardSrv.iteration);
  191. // });
  192. //
  193. // it('should set scopedVars on row panels', function() {
  194. // expect(ctx.rows[0].panels[0].scopedVars.servers.value).to.be('se1');
  195. // expect(ctx.rows[1].panels[0].scopedVars.servers.value).to.be('se2');
  196. // });
  197. //
  198. // describe('After a second iteration', function() {
  199. // var repeatedRowAfterFirstIteration;
  200. //
  201. // beforeEach(function() {
  202. // repeatedRowAfterFirstIteration = ctx.rows[1];
  203. // ctx.rows[0].height = 500;
  204. // ctx.dynamicDashboardSrv.process();
  205. // });
  206. //
  207. // it('should still only have 2 rows', function() {
  208. // expect(ctx.rows.length).to.be(3);
  209. // });
  210. //
  211. // it.skip('should have updated props from source', function() {
  212. // expect(ctx.rows[1].height).to.be(500);
  213. // });
  214. //
  215. // it('should reuse row instance', function() {
  216. // expect(ctx.rows[1]).to.be(repeatedRowAfterFirstIteration);
  217. // });
  218. // });
  219. //
  220. // describe('After a second iteration and selected values reduced', function() {
  221. // beforeEach(function() {
  222. // ctx.dash.templating.list[0].options[1].selected = false;
  223. // ctx.dynamicDashboardSrv.process();
  224. // });
  225. //
  226. // it('should remove repeated second row', function() {
  227. // expect(ctx.rows.length).to.be(2);
  228. // });
  229. // });
  230. // });
  231. //
  232. // dynamicDashScenario('given dashboard with row repeat and panel repeat', function(ctx) {
  233. // ctx.setup(function(dash) {
  234. // dash.rows.push({
  235. // repeat: 'servers',
  236. // panels: [{id: 2, repeat: 'metric'}]
  237. // });
  238. // dash.templating.list.push({
  239. // name: 'servers',
  240. // current: { text: 'se1, se2', value: ['se1', 'se2'] },
  241. // options: [
  242. // {text: 'se1', value: 'se1', selected: true},
  243. // {text: 'se2', value: 'se2', selected: true},
  244. // ]
  245. // });
  246. // dash.templating.list.push({
  247. // name: 'metric',
  248. // current: { text: 'm1, m2', value: ['m1', 'm2'] },
  249. // options: [
  250. // {text: 'm1', value: 'm1', selected: true},
  251. // {text: 'm2', value: 'm2', selected: true},
  252. // ]
  253. // });
  254. // });
  255. //
  256. // it('should repeat row one time', function() {
  257. // expect(ctx.rows.length).to.be(2);
  258. // });
  259. //
  260. // it('should repeat panel on both rows', function() {
  261. // expect(ctx.rows[0].panels.length).to.be(2);
  262. // expect(ctx.rows[1].panels.length).to.be(2);
  263. // });
  264. //
  265. // it('should keep panel ids on first row', function() {
  266. // expect(ctx.rows[0].panels[0].id).to.be(2);
  267. // });
  268. //
  269. // it('should mark second row as repeated', function() {
  270. // expect(ctx.rows[0].repeat).to.be('servers');
  271. // });
  272. //
  273. // it('should clear repeat field on repeated row', function() {
  274. // expect(ctx.rows[1].repeat).to.be(null);
  275. // });
  276. //
  277. // it('should generate a repeartRowId based on repeat row index', function() {
  278. // expect(ctx.rows[1].repeatRowId).to.be(1);
  279. // });
  280. //
  281. // it('should set scopedVars on row panels', function() {
  282. // expect(ctx.rows[0].panels[0].scopedVars.servers.value).to.be('se1');
  283. // expect(ctx.rows[1].panels[0].scopedVars.servers.value).to.be('se2');
  284. // });
  285. //
  286. // });