unsavedChangesSrv-specs.js 2.3 KB

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