unsavedChangesSrv-specs.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. define([
  2. 'app/features/dashboard/unsavedChangesSrv',
  3. 'app/features/dashboard/dashboardSrv'
  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.services'));
  16. beforeEach(module(function($provide) {
  17. $provide.value('contextSrv', _contextSrvStub);
  18. $provide.value('$window', {});
  19. }));
  20. beforeEach(inject(function(unsavedChangesSrv, $location, $rootScope, dashboardSrv) {
  21. _unsavedChangesSrv = unsavedChangesSrv;
  22. _dashboardSrv = dashboardSrv;
  23. _location = $location;
  24. _rootScope = $rootScope;
  25. }));
  26. beforeEach(function() {
  27. dash = _dashboardSrv.create({
  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.rows.push({repeatRowId: 10});
  67. expect(tracker.hasChanges()).to.be(false);
  68. });
  69. });
  70. });