unsaved_changes_srv_specs.ts 2.3 KB

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