unsaved_changes_srv_specs.ts 2.5 KB

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