unsaved_changes_srv_specs.ts 2.3 KB

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