unsaved_changes_srv_specs.ts 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. rows: [
  29. {
  30. panels: [{ test: "asd", legend: { } }]
  31. }
  32. ]
  33. });
  34. scope = _rootScope.$new();
  35. scope.appEvent = sinon.spy();
  36. scope.onAppEvent = sinon.spy();
  37. tracker = new _unsavedChangesSrv.Tracker(dash, scope);
  38. });
  39. it('No changes should not have changes', function() {
  40. expect(tracker.hasChanges()).to.be(false);
  41. });
  42. it('Simple change should be registered', function() {
  43. dash.property = "google";
  44. expect(tracker.hasChanges()).to.be(true);
  45. });
  46. it('Should ignore a lot of changes', function() {
  47. dash.time = {from: '1h'};
  48. dash.refresh = true;
  49. dash.schemaVersion = 10;
  50. expect(tracker.hasChanges()).to.be(false);
  51. });
  52. it('Should ignore row collapse change', function() {
  53. dash.rows[0].collapse = true;
  54. expect(tracker.hasChanges()).to.be(false);
  55. });
  56. it('Should ignore panel legend changes', function() {
  57. dash.rows[0].panels[0].legend.sortDesc = true;
  58. dash.rows[0].panels[0].legend.sort = "avg";
  59. expect(tracker.hasChanges()).to.be(false);
  60. });
  61. it('Should ignore panel repeats', function() {
  62. dash.rows[0].panels.push({repeatPanelId: 10});
  63. expect(tracker.hasChanges()).to.be(false);
  64. });
  65. it('Should ignore row repeats', function() {
  66. dash.addEmptyRow();
  67. dash.rows[1].repeatRowId = 10;
  68. expect(tracker.hasChanges()).to.be(false);
  69. });
  70. });