unsaved_changes_srv_specs.ts 2.6 KB

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