unsaved_changes_srv_specs.ts 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import {
  2. describe,
  3. beforeEach,
  4. it,
  5. expect,
  6. sinon,
  7. angularMocks,
  8. } from 'test/lib/common';
  9. import 'app/features/dashboard/unsavedChangesSrv';
  10. import 'app/features/dashboard/dashboard_srv';
  11. describe('unsavedChangesSrv', function() {
  12. var _unsavedChangesSrv;
  13. var _dashboardSrv;
  14. var _contextSrvStub = { isEditor: true };
  15. var _rootScope;
  16. var tracker;
  17. var dash;
  18. var scope;
  19. beforeEach(angularMocks.module('grafana.core'));
  20. beforeEach(angularMocks.module('grafana.services'));
  21. beforeEach(
  22. angularMocks.module(function($provide) {
  23. $provide.value('contextSrv', _contextSrvStub);
  24. $provide.value('$window', {});
  25. })
  26. );
  27. beforeEach(
  28. angularMocks.inject(function(
  29. unsavedChangesSrv,
  30. $location,
  31. $rootScope,
  32. dashboardSrv
  33. ) {
  34. _unsavedChangesSrv = unsavedChangesSrv;
  35. _dashboardSrv = dashboardSrv;
  36. _rootScope = $rootScope;
  37. })
  38. );
  39. beforeEach(function() {
  40. dash = _dashboardSrv.create({
  41. refresh: false,
  42. panels: [{ test: 'asd', legend: {} }],
  43. rows: [
  44. {
  45. panels: [{ test: 'asd', legend: {} }],
  46. },
  47. ],
  48. });
  49. scope = _rootScope.$new();
  50. scope.appEvent = sinon.spy();
  51. scope.onAppEvent = sinon.spy();
  52. tracker = new _unsavedChangesSrv.Tracker(dash, scope);
  53. });
  54. it('No changes should not have changes', function() {
  55. expect(tracker.hasChanges()).to.be(false);
  56. });
  57. it('Simple change should be registered', function() {
  58. dash.property = 'google';
  59. expect(tracker.hasChanges()).to.be(true);
  60. });
  61. it('Should ignore a lot of changes', function() {
  62. dash.time = { from: '1h' };
  63. dash.refresh = true;
  64. dash.schemaVersion = 10;
  65. expect(tracker.hasChanges()).to.be(false);
  66. });
  67. it.skip('Should ignore row collapse change', function() {
  68. dash.rows[0].collapse = true;
  69. expect(tracker.hasChanges()).to.be(false);
  70. });
  71. it('Should ignore panel legend changes', function() {
  72. dash.panels[0].legend.sortDesc = true;
  73. dash.panels[0].legend.sort = 'avg';
  74. expect(tracker.hasChanges()).to.be(false);
  75. });
  76. it.skip('Should ignore panel repeats', function() {
  77. dash.rows[0].panels.push({ repeatPanelId: 10 });
  78. expect(tracker.hasChanges()).to.be(false);
  79. });
  80. it.skip('Should ignore row repeats', function() {
  81. dash.addEmptyRow();
  82. dash.rows[1].repeatRowId = 10;
  83. expect(tracker.hasChanges()).to.be(false);
  84. });
  85. });