2017-12-21 08:39:31 +01:00
|
|
|
import { describe, beforeEach, it, expect, sinon, angularMocks } from 'test/lib/common';
|
2017-12-21 13:22:20 +01:00
|
|
|
import { Tracker } from 'app/features/dashboard/unsaved_changes_srv';
|
2017-12-20 12:33:33 +01:00
|
|
|
import 'app/features/dashboard/dashboard_srv';
|
2017-12-21 13:22:20 +01:00
|
|
|
import { contextSrv } from 'app/core/core';
|
2017-10-01 20:02:25 +02:00
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
describe('unsavedChangesSrv', function() {
|
2017-10-01 20:02:25 +02:00
|
|
|
var _dashboardSrv;
|
|
|
|
|
var _contextSrvStub = { isEditor: true };
|
|
|
|
|
var _rootScope;
|
2017-12-21 13:22:20 +01:00
|
|
|
var _location;
|
|
|
|
|
var _timeout;
|
|
|
|
|
var _window;
|
2017-10-01 20:02:25 +02:00
|
|
|
var tracker;
|
|
|
|
|
var dash;
|
|
|
|
|
var scope;
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
beforeEach(angularMocks.module('grafana.core'));
|
|
|
|
|
beforeEach(angularMocks.module('grafana.services'));
|
2017-12-19 16:06:54 +01:00
|
|
|
beforeEach(
|
|
|
|
|
angularMocks.module(function($provide) {
|
2017-12-20 12:33:33 +01:00
|
|
|
$provide.value('contextSrv', _contextSrvStub);
|
|
|
|
|
$provide.value('$window', {});
|
2017-12-19 16:06:54 +01:00
|
|
|
})
|
|
|
|
|
);
|
2017-10-01 20:02:25 +02:00
|
|
|
|
2017-12-19 16:06:54 +01:00
|
|
|
beforeEach(
|
2017-12-26 12:26:50 +01:00
|
|
|
angularMocks.inject(function($location, $rootScope, dashboardSrv, $timeout, $window) {
|
2017-12-19 16:06:54 +01:00
|
|
|
_dashboardSrv = dashboardSrv;
|
|
|
|
|
_rootScope = $rootScope;
|
2017-12-21 13:22:20 +01:00
|
|
|
_location = $location;
|
|
|
|
|
_timeout = $timeout;
|
|
|
|
|
_window = $window;
|
2017-12-19 16:06:54 +01:00
|
|
|
})
|
|
|
|
|
);
|
2017-10-01 20:02:25 +02:00
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
|
dash = _dashboardSrv.create({
|
|
|
|
|
refresh: false,
|
2017-12-20 12:33:33 +01:00
|
|
|
panels: [{ test: 'asd', legend: {} }],
|
2017-10-01 20:02:25 +02:00
|
|
|
rows: [
|
|
|
|
|
{
|
2017-12-20 12:33:33 +01:00
|
|
|
panels: [{ test: 'asd', legend: {} }],
|
|
|
|
|
},
|
|
|
|
|
],
|
2017-10-01 20:02:25 +02:00
|
|
|
});
|
|
|
|
|
scope = _rootScope.$new();
|
|
|
|
|
scope.appEvent = sinon.spy();
|
|
|
|
|
scope.onAppEvent = sinon.spy();
|
|
|
|
|
|
2017-12-26 12:26:50 +01:00
|
|
|
tracker = new Tracker(dash, scope, undefined, _location, _window, _timeout, contextSrv, _rootScope);
|
2017-10-01 20:02:25 +02:00
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
it('No changes should not have changes', function() {
|
2017-10-01 20:02:25 +02:00
|
|
|
expect(tracker.hasChanges()).to.be(false);
|
|
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
it('Simple change should be registered', function() {
|
|
|
|
|
dash.property = 'google';
|
2017-10-01 20:02:25 +02:00
|
|
|
expect(tracker.hasChanges()).to.be(true);
|
|
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
it('Should ignore a lot of changes', function() {
|
|
|
|
|
dash.time = { from: '1h' };
|
2017-10-01 20:02:25 +02:00
|
|
|
dash.refresh = true;
|
|
|
|
|
dash.schemaVersion = 10;
|
|
|
|
|
expect(tracker.hasChanges()).to.be(false);
|
|
|
|
|
});
|
|
|
|
|
|
2018-03-05 22:03:26 +01:00
|
|
|
it('Should ignore .iteration changes', () => {
|
|
|
|
|
dash.iteration = new Date().getTime() + 1;
|
|
|
|
|
expect(tracker.hasChanges()).to.be(false);
|
|
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
it.skip('Should ignore row collapse change', function() {
|
2017-10-01 20:02:25 +02:00
|
|
|
dash.rows[0].collapse = true;
|
|
|
|
|
expect(tracker.hasChanges()).to.be(false);
|
|
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
it('Should ignore panel legend changes', function() {
|
2017-10-12 12:01:13 +02:00
|
|
|
dash.panels[0].legend.sortDesc = true;
|
2017-12-20 12:33:33 +01:00
|
|
|
dash.panels[0].legend.sort = 'avg';
|
2017-10-01 20:02:25 +02:00
|
|
|
expect(tracker.hasChanges()).to.be(false);
|
|
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
it.skip('Should ignore panel repeats', function() {
|
2017-12-19 16:06:54 +01:00
|
|
|
dash.rows[0].panels.push({ repeatPanelId: 10 });
|
2017-10-01 20:02:25 +02:00
|
|
|
expect(tracker.hasChanges()).to.be(false);
|
|
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
it.skip('Should ignore row repeats', function() {
|
2017-10-01 20:02:25 +02:00
|
|
|
dash.addEmptyRow();
|
|
|
|
|
dash.rows[1].repeatRowId = 10;
|
|
|
|
|
expect(tracker.hasChanges()).to.be(false);
|
|
|
|
|
});
|
|
|
|
|
});
|