unsaved_changes_srv_specs.ts 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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('Should ignore .iteration changes', () => {
  61. dash.iteration = new Date().getTime() + 1;
  62. expect(tracker.hasChanges()).to.be(false);
  63. });
  64. it.skip('Should ignore row collapse change', function() {
  65. dash.rows[0].collapse = true;
  66. expect(tracker.hasChanges()).to.be(false);
  67. });
  68. it('Should ignore panel legend changes', function() {
  69. dash.panels[0].legend.sortDesc = true;
  70. dash.panels[0].legend.sort = 'avg';
  71. expect(tracker.hasChanges()).to.be(false);
  72. });
  73. it.skip('Should ignore panel repeats', function() {
  74. dash.rows[0].panels.push({ repeatPanelId: 10 });
  75. expect(tracker.hasChanges()).to.be(false);
  76. });
  77. it.skip('Should ignore row repeats', function() {
  78. dash.addEmptyRow();
  79. dash.rows[1].repeatRowId = 10;
  80. expect(tracker.hasChanges()).to.be(false);
  81. });
  82. });