mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Merge pull request #12367 from dehrax/12224-history-ctrl
Karma to Jest: history_ctrl
This commit is contained in:
313
public/app/features/dashboard/specs/history_ctrl.jest.ts
Normal file
313
public/app/features/dashboard/specs/history_ctrl.jest.ts
Normal file
@@ -0,0 +1,313 @@
|
||||
import _ from 'lodash';
|
||||
import { HistoryListCtrl } from 'app/features/dashboard/history/history';
|
||||
import { versions, compare, restore } from './history_mocks';
|
||||
import $q from 'q';
|
||||
|
||||
describe('HistoryListCtrl', () => {
|
||||
const RESTORE_ID = 4;
|
||||
|
||||
const versionsResponse: any = versions();
|
||||
|
||||
restore(7, RESTORE_ID);
|
||||
|
||||
let historySrv;
|
||||
let $rootScope;
|
||||
let historyListCtrl;
|
||||
beforeEach(() => {
|
||||
historySrv = {
|
||||
calculateDiff: jest.fn(),
|
||||
restoreDashboard: jest.fn(() => $q.when({})),
|
||||
};
|
||||
$rootScope = {
|
||||
appEvent: jest.fn(),
|
||||
onAppEvent: jest.fn(),
|
||||
};
|
||||
});
|
||||
|
||||
describe('when the history list component is loaded', () => {
|
||||
let deferred;
|
||||
|
||||
beforeEach(() => {
|
||||
deferred = $q.defer({});
|
||||
historySrv.getHistoryList = jest.fn(() => deferred.promise);
|
||||
|
||||
historyListCtrl = new HistoryListCtrl({}, $rootScope, {}, $q, historySrv, {});
|
||||
|
||||
historyListCtrl.dashboard = {
|
||||
id: 2,
|
||||
version: 3,
|
||||
formatDate: jest.fn(() => 'date'),
|
||||
};
|
||||
});
|
||||
|
||||
it('should immediately attempt to fetch the history list', () => {
|
||||
expect(historySrv.getHistoryList).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
describe('and the history list is successfully fetched', () => {
|
||||
beforeEach(async () => {
|
||||
deferred.resolve(versionsResponse);
|
||||
await historyListCtrl.getLog();
|
||||
});
|
||||
|
||||
it("should reset the controller's state", async () => {
|
||||
expect(historyListCtrl.mode).toBe('list');
|
||||
expect(historyListCtrl.delta).toEqual({ basic: '', json: '' });
|
||||
|
||||
expect(historyListCtrl.canCompare).toBe(false);
|
||||
expect(_.find(historyListCtrl.revisions, rev => rev.checked)).toBe(undefined);
|
||||
});
|
||||
|
||||
it('should indicate loading has finished', () => {
|
||||
expect(historyListCtrl.loading).toBe(false);
|
||||
});
|
||||
|
||||
it('should store the revisions sorted desc by version id', () => {
|
||||
expect(historyListCtrl.revisions[0].version).toBe(4);
|
||||
expect(historyListCtrl.revisions[1].version).toBe(3);
|
||||
expect(historyListCtrl.revisions[2].version).toBe(2);
|
||||
expect(historyListCtrl.revisions[3].version).toBe(1);
|
||||
});
|
||||
|
||||
it('should add a checked property to each revision', () => {
|
||||
let actual = _.filter(historyListCtrl.revisions, rev => rev.hasOwnProperty('checked'));
|
||||
expect(actual.length).toBe(4);
|
||||
});
|
||||
|
||||
it('should set all checked properties to false on reset', () => {
|
||||
historyListCtrl.revisions[0].checked = true;
|
||||
historyListCtrl.revisions[2].checked = true;
|
||||
historyListCtrl.reset();
|
||||
let actual = _.filter(historyListCtrl.revisions, rev => !rev.checked);
|
||||
expect(actual.length).toBe(4);
|
||||
});
|
||||
});
|
||||
|
||||
describe('and fetching the history list fails', () => {
|
||||
beforeEach(async () => {
|
||||
deferred = $q.defer();
|
||||
|
||||
historySrv.getHistoryList = jest.fn(() => deferred.promise);
|
||||
|
||||
historyListCtrl = new HistoryListCtrl({}, $rootScope, {}, $q, historySrv, {});
|
||||
|
||||
deferred.reject(new Error('HistoryListError'));
|
||||
|
||||
await historyListCtrl.getLog();
|
||||
});
|
||||
|
||||
it("should reset the controller's state", () => {
|
||||
expect(historyListCtrl.mode).toBe('list');
|
||||
expect(historyListCtrl.delta).toEqual({ basic: '', json: '' });
|
||||
expect(_.find(historyListCtrl.revisions, rev => rev.checked)).toBe(undefined);
|
||||
});
|
||||
|
||||
it('should indicate loading has finished', () => {
|
||||
expect(historyListCtrl.loading).toBe(false);
|
||||
});
|
||||
|
||||
it('should have an empty revisions list', () => {
|
||||
expect(historyListCtrl.revisions).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('should update the history list when the dashboard is saved', () => {
|
||||
beforeEach(() => {
|
||||
historyListCtrl.dashboard = { version: 3 };
|
||||
historyListCtrl.resetFromSource = jest.fn();
|
||||
});
|
||||
|
||||
it('should listen for the `dashboard-saved` appEvent', () => {
|
||||
expect($rootScope.onAppEvent).toHaveBeenCalledTimes(1);
|
||||
expect($rootScope.onAppEvent.mock.calls[0][0]).toBe('dashboard-saved');
|
||||
});
|
||||
|
||||
it('should call `onDashboardSaved` when the appEvent is received', () => {
|
||||
expect($rootScope.onAppEvent.mock.calls[0][1]).not.toBe(historyListCtrl.onDashboardSaved);
|
||||
expect($rootScope.onAppEvent.mock.calls[0][1].toString).toBe(historyListCtrl.onDashboardSaved.toString);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the user wants to compare two revisions', () => {
|
||||
let deferred;
|
||||
|
||||
beforeEach(async () => {
|
||||
deferred = $q.defer({});
|
||||
historySrv.getHistoryList = jest.fn(() => $q.when(versionsResponse));
|
||||
historySrv.calculateDiff = jest.fn(() => deferred.promise);
|
||||
|
||||
historyListCtrl = new HistoryListCtrl({}, $rootScope, {}, $q, historySrv, {});
|
||||
|
||||
historyListCtrl.dashboard = {
|
||||
id: 2,
|
||||
version: 3,
|
||||
formatDate: jest.fn(() => 'date'),
|
||||
};
|
||||
|
||||
deferred.resolve(versionsResponse);
|
||||
await historyListCtrl.getLog();
|
||||
});
|
||||
|
||||
it('should have already fetched the history list', () => {
|
||||
expect(historySrv.getHistoryList).toHaveBeenCalled();
|
||||
expect(historyListCtrl.revisions.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it('should check that two valid versions are selected', () => {
|
||||
// []
|
||||
expect(historyListCtrl.canCompare).toBe(false);
|
||||
|
||||
// single value
|
||||
historyListCtrl.revisions = [{ checked: true }];
|
||||
historyListCtrl.revisionSelectionChanged();
|
||||
expect(historyListCtrl.canCompare).toBe(false);
|
||||
|
||||
// both values in range
|
||||
historyListCtrl.revisions = [{ checked: true }, { checked: true }];
|
||||
historyListCtrl.revisionSelectionChanged();
|
||||
expect(historyListCtrl.canCompare).toBe(true);
|
||||
});
|
||||
|
||||
describe('and the basic diff is successfully fetched', () => {
|
||||
beforeEach(async () => {
|
||||
deferred = $q.defer({});
|
||||
historySrv.calculateDiff = jest.fn(() => deferred.promise);
|
||||
deferred.resolve(compare('basic'));
|
||||
historyListCtrl.revisions[1].checked = true;
|
||||
historyListCtrl.revisions[3].checked = true;
|
||||
await historyListCtrl.getDiff('basic');
|
||||
});
|
||||
|
||||
it('should fetch the basic diff if two valid versions are selected', () => {
|
||||
expect(historySrv.calculateDiff).toHaveBeenCalledTimes(1);
|
||||
expect(historyListCtrl.delta.basic).toBe('<div></div>');
|
||||
expect(historyListCtrl.delta.json).toBe('');
|
||||
});
|
||||
|
||||
it('should set the basic diff view as active', () => {
|
||||
expect(historyListCtrl.mode).toBe('compare');
|
||||
expect(historyListCtrl.diff).toBe('basic');
|
||||
});
|
||||
|
||||
it('should indicate loading has finished', () => {
|
||||
expect(historyListCtrl.loading).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('and the json diff is successfully fetched', () => {
|
||||
beforeEach(async () => {
|
||||
deferred = $q.defer({});
|
||||
historySrv.calculateDiff = jest.fn(() => deferred.promise);
|
||||
deferred.resolve(compare('json'));
|
||||
historyListCtrl.revisions[1].checked = true;
|
||||
historyListCtrl.revisions[3].checked = true;
|
||||
await historyListCtrl.getDiff('json');
|
||||
});
|
||||
|
||||
it('should fetch the json diff if two valid versions are selected', () => {
|
||||
expect(historySrv.calculateDiff).toHaveBeenCalledTimes(1);
|
||||
expect(historyListCtrl.delta.basic).toBe('');
|
||||
expect(historyListCtrl.delta.json).toBe('<pre><code></code></pre>');
|
||||
});
|
||||
|
||||
it('should set the json diff view as active', () => {
|
||||
expect(historyListCtrl.mode).toBe('compare');
|
||||
expect(historyListCtrl.diff).toBe('json');
|
||||
});
|
||||
|
||||
it('should indicate loading has finished', () => {
|
||||
expect(historyListCtrl.loading).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('and diffs have already been fetched', () => {
|
||||
beforeEach(async () => {
|
||||
deferred.resolve(compare('basic'));
|
||||
|
||||
historyListCtrl.revisions[3].checked = true;
|
||||
historyListCtrl.revisions[1].checked = true;
|
||||
historyListCtrl.delta.basic = 'cached basic';
|
||||
historyListCtrl.getDiff('basic');
|
||||
await historySrv.calculateDiff();
|
||||
});
|
||||
|
||||
it('should use the cached diffs instead of fetching', () => {
|
||||
expect(historySrv.calculateDiff).toHaveBeenCalledTimes(1);
|
||||
expect(historyListCtrl.delta.basic).toBe('cached basic');
|
||||
});
|
||||
|
||||
it('should indicate loading has finished', () => {
|
||||
expect(historyListCtrl.loading).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('and fetching the diff fails', () => {
|
||||
beforeEach(async () => {
|
||||
deferred = $q.defer({});
|
||||
historySrv.calculateDiff = jest.fn(() => deferred.promise);
|
||||
|
||||
historyListCtrl.revisions[3].checked = true;
|
||||
historyListCtrl.revisions[1].checked = true;
|
||||
deferred.reject();
|
||||
await historyListCtrl.getDiff('basic');
|
||||
});
|
||||
|
||||
it('should fetch the diff if two valid versions are selected', () => {
|
||||
expect(historySrv.calculateDiff).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('should return to the history list view', () => {
|
||||
expect(historyListCtrl.mode).toBe('list');
|
||||
});
|
||||
|
||||
it('should indicate loading has finished', () => {
|
||||
expect(historyListCtrl.loading).toBe(false);
|
||||
});
|
||||
|
||||
it('should have an empty delta/changeset', () => {
|
||||
expect(historyListCtrl.delta).toEqual({ basic: '', json: '' });
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the user wants to restore a revision', () => {
|
||||
let deferred;
|
||||
|
||||
beforeEach(async () => {
|
||||
deferred = $q.defer();
|
||||
historySrv.getHistoryList = jest.fn(() => $q.when(versionsResponse));
|
||||
historySrv.restoreDashboard = jest.fn(() => deferred.promise);
|
||||
|
||||
historyListCtrl = new HistoryListCtrl({}, $rootScope, {}, $q, historySrv, {});
|
||||
|
||||
historyListCtrl.dashboard = {
|
||||
id: 1,
|
||||
};
|
||||
historyListCtrl.restore();
|
||||
deferred.resolve(versionsResponse);
|
||||
await historyListCtrl.getLog();
|
||||
});
|
||||
|
||||
it('should display a modal allowing the user to restore or cancel', () => {
|
||||
expect($rootScope.appEvent).toHaveBeenCalledTimes(1);
|
||||
expect($rootScope.appEvent.mock.calls[0][0]).toBe('confirm-modal');
|
||||
});
|
||||
|
||||
describe('and restore fails to fetch', () => {
|
||||
beforeEach(async () => {
|
||||
deferred = $q.defer();
|
||||
historySrv.getHistoryList = jest.fn(() => $q.when(versionsResponse));
|
||||
historySrv.restoreDashboard = jest.fn(() => deferred.promise);
|
||||
historyListCtrl = new HistoryListCtrl({}, $rootScope, {}, $q, historySrv, {});
|
||||
deferred.reject(new Error('RestoreError'));
|
||||
historyListCtrl.restoreConfirm(RESTORE_ID);
|
||||
await historyListCtrl.getLog();
|
||||
});
|
||||
|
||||
it('should indicate loading has finished', () => {
|
||||
expect(historyListCtrl.loading).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,329 +0,0 @@
|
||||
import { describe, beforeEach, it, sinon, expect, angularMocks } from 'test/lib/common';
|
||||
|
||||
import _ from 'lodash';
|
||||
import { HistoryListCtrl } from 'app/features/dashboard/history/history';
|
||||
import { versions, compare, restore } from './history_mocks';
|
||||
|
||||
describe('HistoryListCtrl', function() {
|
||||
var RESTORE_ID = 4;
|
||||
|
||||
var ctx: any = {};
|
||||
var versionsResponse: any = versions();
|
||||
|
||||
restore(7, RESTORE_ID);
|
||||
|
||||
beforeEach(angularMocks.module('grafana.core'));
|
||||
beforeEach(angularMocks.module('grafana.services'));
|
||||
beforeEach(
|
||||
angularMocks.inject($rootScope => {
|
||||
ctx.scope = $rootScope.$new();
|
||||
})
|
||||
);
|
||||
|
||||
var historySrv;
|
||||
var $rootScope;
|
||||
beforeEach(function() {
|
||||
historySrv = {
|
||||
getHistoryList: sinon.stub(),
|
||||
calculateDiff: sinon.stub(),
|
||||
restoreDashboard: sinon.stub(),
|
||||
};
|
||||
$rootScope = {
|
||||
appEvent: sinon.spy(),
|
||||
onAppEvent: sinon.spy(),
|
||||
};
|
||||
});
|
||||
|
||||
describe('when the history list component is loaded', function() {
|
||||
var deferred;
|
||||
|
||||
beforeEach(
|
||||
angularMocks.inject(($controller, $q) => {
|
||||
deferred = $q.defer();
|
||||
historySrv.getHistoryList.returns(deferred.promise);
|
||||
ctx.ctrl = $controller(
|
||||
HistoryListCtrl,
|
||||
{
|
||||
historySrv,
|
||||
$rootScope,
|
||||
$scope: ctx.scope,
|
||||
},
|
||||
{
|
||||
dashboard: {
|
||||
id: 2,
|
||||
version: 3,
|
||||
formatDate: sinon.stub().returns('date'),
|
||||
},
|
||||
}
|
||||
);
|
||||
})
|
||||
);
|
||||
|
||||
it('should immediately attempt to fetch the history list', function() {
|
||||
expect(historySrv.getHistoryList.calledOnce).to.be(true);
|
||||
});
|
||||
|
||||
describe('and the history list is successfully fetched', function() {
|
||||
beforeEach(function() {
|
||||
deferred.resolve(versionsResponse);
|
||||
ctx.ctrl.$scope.$apply();
|
||||
});
|
||||
|
||||
it("should reset the controller's state", function() {
|
||||
expect(ctx.ctrl.mode).to.be('list');
|
||||
expect(ctx.ctrl.delta).to.eql({ basic: '', json: '' });
|
||||
expect(ctx.ctrl.canCompare).to.be(false);
|
||||
expect(_.find(ctx.ctrl.revisions, rev => rev.checked)).to.be(undefined);
|
||||
});
|
||||
|
||||
it('should indicate loading has finished', function() {
|
||||
expect(ctx.ctrl.loading).to.be(false);
|
||||
});
|
||||
|
||||
it('should store the revisions sorted desc by version id', function() {
|
||||
expect(ctx.ctrl.revisions[0].version).to.be(4);
|
||||
expect(ctx.ctrl.revisions[1].version).to.be(3);
|
||||
expect(ctx.ctrl.revisions[2].version).to.be(2);
|
||||
expect(ctx.ctrl.revisions[3].version).to.be(1);
|
||||
});
|
||||
|
||||
it('should add a checked property to each revision', function() {
|
||||
var actual = _.filter(ctx.ctrl.revisions, rev => rev.hasOwnProperty('checked'));
|
||||
expect(actual.length).to.be(4);
|
||||
});
|
||||
|
||||
it('should set all checked properties to false on reset', function() {
|
||||
ctx.ctrl.revisions[0].checked = true;
|
||||
ctx.ctrl.revisions[2].checked = true;
|
||||
ctx.ctrl.reset();
|
||||
var actual = _.filter(ctx.ctrl.revisions, rev => !rev.checked);
|
||||
expect(actual.length).to.be(4);
|
||||
});
|
||||
});
|
||||
|
||||
describe('and fetching the history list fails', function() {
|
||||
beforeEach(function() {
|
||||
deferred.reject(new Error('HistoryListError'));
|
||||
ctx.ctrl.$scope.$apply();
|
||||
});
|
||||
|
||||
it("should reset the controller's state", function() {
|
||||
expect(ctx.ctrl.mode).to.be('list');
|
||||
expect(ctx.ctrl.delta).to.eql({ basic: '', json: '' });
|
||||
expect(_.find(ctx.ctrl.revisions, rev => rev.checked)).to.be(undefined);
|
||||
});
|
||||
|
||||
it('should indicate loading has finished', function() {
|
||||
expect(ctx.ctrl.loading).to.be(false);
|
||||
});
|
||||
|
||||
it('should have an empty revisions list', function() {
|
||||
expect(ctx.ctrl.revisions).to.eql([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('should update the history list when the dashboard is saved', function() {
|
||||
beforeEach(function() {
|
||||
ctx.ctrl.dashboard = { version: 3 };
|
||||
ctx.ctrl.resetFromSource = sinon.spy();
|
||||
});
|
||||
|
||||
it('should listen for the `dashboard-saved` appEvent', function() {
|
||||
expect($rootScope.onAppEvent.calledOnce).to.be(true);
|
||||
expect($rootScope.onAppEvent.getCall(0).args[0]).to.be('dashboard-saved');
|
||||
});
|
||||
|
||||
it('should call `onDashboardSaved` when the appEvent is received', function() {
|
||||
expect($rootScope.onAppEvent.getCall(0).args[1]).to.not.be(ctx.ctrl.onDashboardSaved);
|
||||
expect($rootScope.onAppEvent.getCall(0).args[1].toString).to.be(ctx.ctrl.onDashboardSaved.toString);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the user wants to compare two revisions', function() {
|
||||
var deferred;
|
||||
|
||||
beforeEach(
|
||||
angularMocks.inject(($controller, $q) => {
|
||||
deferred = $q.defer();
|
||||
historySrv.getHistoryList.returns($q.when(versionsResponse));
|
||||
historySrv.calculateDiff.returns(deferred.promise);
|
||||
ctx.ctrl = $controller(
|
||||
HistoryListCtrl,
|
||||
{
|
||||
historySrv,
|
||||
$rootScope,
|
||||
$scope: ctx.scope,
|
||||
},
|
||||
{
|
||||
dashboard: {
|
||||
id: 2,
|
||||
version: 3,
|
||||
formatDate: sinon.stub().returns('date'),
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
ctx.ctrl.$scope.onDashboardSaved = sinon.spy();
|
||||
ctx.ctrl.$scope.$apply();
|
||||
})
|
||||
);
|
||||
|
||||
it('should have already fetched the history list', function() {
|
||||
expect(historySrv.getHistoryList.calledOnce).to.be(true);
|
||||
expect(ctx.ctrl.revisions.length).to.be.above(0);
|
||||
});
|
||||
|
||||
it('should check that two valid versions are selected', function() {
|
||||
// []
|
||||
expect(ctx.ctrl.canCompare).to.be(false);
|
||||
|
||||
// single value
|
||||
ctx.ctrl.revisions = [{ checked: true }];
|
||||
ctx.ctrl.revisionSelectionChanged();
|
||||
expect(ctx.ctrl.canCompare).to.be(false);
|
||||
|
||||
// both values in range
|
||||
ctx.ctrl.revisions = [{ checked: true }, { checked: true }];
|
||||
ctx.ctrl.revisionSelectionChanged();
|
||||
expect(ctx.ctrl.canCompare).to.be(true);
|
||||
});
|
||||
|
||||
describe('and the basic diff is successfully fetched', function() {
|
||||
beforeEach(function() {
|
||||
deferred.resolve(compare('basic'));
|
||||
ctx.ctrl.revisions[1].checked = true;
|
||||
ctx.ctrl.revisions[3].checked = true;
|
||||
ctx.ctrl.getDiff('basic');
|
||||
ctx.ctrl.$scope.$apply();
|
||||
});
|
||||
|
||||
it('should fetch the basic diff if two valid versions are selected', function() {
|
||||
expect(historySrv.calculateDiff.calledOnce).to.be(true);
|
||||
expect(ctx.ctrl.delta.basic).to.be('<div></div>');
|
||||
expect(ctx.ctrl.delta.json).to.be('');
|
||||
});
|
||||
|
||||
it('should set the basic diff view as active', function() {
|
||||
expect(ctx.ctrl.mode).to.be('compare');
|
||||
expect(ctx.ctrl.diff).to.be('basic');
|
||||
});
|
||||
|
||||
it('should indicate loading has finished', function() {
|
||||
expect(ctx.ctrl.loading).to.be(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('and the json diff is successfully fetched', function() {
|
||||
beforeEach(function() {
|
||||
deferred.resolve(compare('json'));
|
||||
ctx.ctrl.revisions[1].checked = true;
|
||||
ctx.ctrl.revisions[3].checked = true;
|
||||
ctx.ctrl.getDiff('json');
|
||||
ctx.ctrl.$scope.$apply();
|
||||
});
|
||||
|
||||
it('should fetch the json diff if two valid versions are selected', function() {
|
||||
expect(historySrv.calculateDiff.calledOnce).to.be(true);
|
||||
expect(ctx.ctrl.delta.basic).to.be('');
|
||||
expect(ctx.ctrl.delta.json).to.be('<pre><code></code></pre>');
|
||||
});
|
||||
|
||||
it('should set the json diff view as active', function() {
|
||||
expect(ctx.ctrl.mode).to.be('compare');
|
||||
expect(ctx.ctrl.diff).to.be('json');
|
||||
});
|
||||
|
||||
it('should indicate loading has finished', function() {
|
||||
expect(ctx.ctrl.loading).to.be(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('and diffs have already been fetched', function() {
|
||||
beforeEach(function() {
|
||||
deferred.resolve(compare('basic'));
|
||||
ctx.ctrl.revisions[3].checked = true;
|
||||
ctx.ctrl.revisions[1].checked = true;
|
||||
ctx.ctrl.delta.basic = 'cached basic';
|
||||
ctx.ctrl.getDiff('basic');
|
||||
ctx.ctrl.$scope.$apply();
|
||||
});
|
||||
|
||||
it('should use the cached diffs instead of fetching', function() {
|
||||
expect(historySrv.calculateDiff.calledOnce).to.be(false);
|
||||
expect(ctx.ctrl.delta.basic).to.be('cached basic');
|
||||
});
|
||||
|
||||
it('should indicate loading has finished', function() {
|
||||
expect(ctx.ctrl.loading).to.be(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('and fetching the diff fails', function() {
|
||||
beforeEach(function() {
|
||||
deferred.reject(new Error('DiffError'));
|
||||
ctx.ctrl.revisions[3].checked = true;
|
||||
ctx.ctrl.revisions[1].checked = true;
|
||||
ctx.ctrl.getDiff('basic');
|
||||
ctx.ctrl.$scope.$apply();
|
||||
});
|
||||
|
||||
it('should fetch the diff if two valid versions are selected', function() {
|
||||
expect(historySrv.calculateDiff.calledOnce).to.be(true);
|
||||
});
|
||||
|
||||
it('should return to the history list view', function() {
|
||||
expect(ctx.ctrl.mode).to.be('list');
|
||||
});
|
||||
|
||||
it('should indicate loading has finished', function() {
|
||||
expect(ctx.ctrl.loading).to.be(false);
|
||||
});
|
||||
|
||||
it('should have an empty delta/changeset', function() {
|
||||
expect(ctx.ctrl.delta).to.eql({ basic: '', json: '' });
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the user wants to restore a revision', function() {
|
||||
var deferred;
|
||||
|
||||
beforeEach(
|
||||
angularMocks.inject(($controller, $q) => {
|
||||
deferred = $q.defer();
|
||||
historySrv.getHistoryList.returns($q.when(versionsResponse));
|
||||
historySrv.restoreDashboard.returns(deferred.promise);
|
||||
ctx.ctrl = $controller(HistoryListCtrl, {
|
||||
historySrv,
|
||||
contextSrv: { user: { name: 'Carlos' } },
|
||||
$rootScope,
|
||||
$scope: ctx.scope,
|
||||
});
|
||||
ctx.ctrl.dashboard = { id: 1 };
|
||||
ctx.ctrl.restore();
|
||||
ctx.ctrl.$scope.$apply();
|
||||
})
|
||||
);
|
||||
|
||||
it('should display a modal allowing the user to restore or cancel', function() {
|
||||
expect($rootScope.appEvent.calledOnce).to.be(true);
|
||||
expect($rootScope.appEvent.calledWith('confirm-modal')).to.be(true);
|
||||
});
|
||||
|
||||
describe('and restore fails to fetch', function() {
|
||||
beforeEach(function() {
|
||||
deferred.reject(new Error('RestoreError'));
|
||||
ctx.ctrl.restoreConfirm(RESTORE_ID);
|
||||
try {
|
||||
// this throws error, due to promise rejection
|
||||
ctx.ctrl.$scope.$apply();
|
||||
} catch (e) {}
|
||||
});
|
||||
|
||||
it('should indicate loading has finished', function() {
|
||||
expect(ctx.ctrl.loading).to.be(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user