unsavedChangesSrv-specs.js 2.3 KB

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