unsaved_changes_srv_specs.ts 2.3 KB

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