/
overview.controller.spec.js
88 lines (65 loc) · 2.57 KB
/
overview.controller.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import { module, inject } from "angular-mocks";
import "../../../app/overview/overview.module";
(function () {
'use strict';
describe('Overview Controller', function(){
var controller,
OverviewServiceMock,
rootScope,
initDeferred,
q;
beforeEach(module('xr.overview'));
beforeEach(module(function ($provide) {
OverviewServiceMock = {
getActiveEntries: function () {}
};
$provide.value('OverviewService', OverviewServiceMock);
}));
beforeEach(inject(function($controller, $q, $rootScope) {
q = $q;
rootScope = $rootScope;
initDeferred = q.defer();
spyOn(OverviewServiceMock, 'getActiveEntries').and.returnValue(initDeferred.promise);
controller = $controller('OverviewController');
}));
describe('init', function () {
it('should set set up with empty array of active entries', function() {
expect(controller.activeEntries).toBeDefined();
expect(controller.activeEntries.length).toBe(0);
});
it('should get active entries', function () {
expect(OverviewServiceMock.getActiveEntries).toHaveBeenCalled();
});
it('should update array of overviews when entries get back from service', function () {
var resolvedData = [{something: null}, {somethingElse: 'Derp'}];
initDeferred.resolve(resolvedData);
rootScope.$digest();
expect(controller.activeEntries).toBe(resolvedData);
});
});
describe('deleteDelegate', function () {
it('should remove the entry sent in from the entry list', function () {
var entry = {
test: 'test'
};
controller.activeEntries = [
entry
];
controller.deleteDelegate.delete(entry);
expect(controller.activeEntries.length).toBe(0);
});
it('should not remove an entry if not in the list', function () {
var entry = {
test: 'test'
};
controller.activeEntries = [
{
not: 'the same'
}
];
controller.deleteDelegate.delete(entry);
expect(controller.activeEntries.length).toBe(1);
});
});
});
})();