-
Notifications
You must be signed in to change notification settings - Fork 297
/
dynamicOptions.spec.js
129 lines (96 loc) · 4.12 KB
/
dynamicOptions.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
'use strict';
describe('Controller: DynamicOptionsCtrl', function() {
var $scope, injections;
beforeEach(module('app'));
beforeEach(inject(function($rootScope, $controller, $window, $timeout){
$scope = $rootScope.$new();
// let's mock the $timeout so we can spy on it
// however, we still want to retain the original $timeout functionality
// to test for time sensitive operations
function timeout(fn, delay) {
$timeout(fn, delay);
};
timeout.flush = function(ms) {
$timeout.flush(ms);
};
injections = {
$scope: $scope,
$timeout: timeout,
$window: $window
};
spyOn(injections, '$timeout').and.callThrough();
$controller('DynamicOptionsCtrl', injections);
}));
describe('the controller properties', function() {
it('should have properties in scope', function() {
expect($scope.style).toEqual('peopleList');
expect($scope.dashboardOptions.hideToolbar).toEqual(true);
expect($scope.dashboardOptions.widgetDefinitions.length).toEqual(2);
expect($scope.dashboardOptions.widgetDefinitions[0].name).toEqual('peopleList');
expect($scope.dashboardOptions.widgetDefinitions[0].title).toEqual('people list');
expect($scope.dashboardOptions.widgetDefinitions[0].templateUrl).toEqual('app/template/dynamicOptionsContainer.html');
expect($scope.dashboardOptions.widgetDefinitions[0].size).toBeDefined();
expect($scope.dashboardOptions.widgetDefinitions[0].includeUrl).toEqual('app/template/peopleList.html');
expect($scope.dashboardOptions.widgetDefinitions[1].name).toEqual('peopleThumbnail');
expect($scope.dashboardOptions.widgetDefinitions[1].title).toEqual('people thumbnail');
expect($scope.dashboardOptions.widgetDefinitions[1].templateUrl).toEqual('app/template/dynamicOptionsContainer.html');
expect($scope.dashboardOptions.widgetDefinitions[1].size).toBeDefined();
expect($scope.dashboardOptions.widgetDefinitions[1].includeUrl).toEqual('app/template/peopleThumbnail.html');
expect($scope.dashboardOptions.defaultWidgets).toBeDefined();
expect($scope.dashboardOptions.storage).toBeDefined();
expect($scope.dashboardOptions.storageId.indexOf('demo_dynamic-options') === 0).toEqual(true);
});
});
describe('the toggleWidget method', function() {
it('should change style', function() {
$scope.toggleWidget();
expect($scope.style).toEqual('peopleThumbnail');
$scope.toggleWidget();
expect($scope.style).toEqual('peopleList');
});
it('should change dashboardOptions reference', function() {
// object for later comparison
var savedDashboardOptions = $scope.dashboardOptions;
$scope.toggleWidget();
injections.$timeout.flush();
expect(injections.$timeout).toHaveBeenCalled();
// we want to compare the object reference
expect(savedDashboardOptions === $scope.dashboardOptions).toBeFalsy();
});
});
});
describe('Controller: PeopleCtrl', function() {
var $scope;
beforeEach(module('app'));
beforeEach(inject(function($rootScope, $controller) {
$scope = $rootScope.$new();
// let's mock widget
$scope.widget = {
includeUrl: 'app/template/peopleList.html'
};
$controller('PeopleCtrl', { $scope: $scope });
}));
describe('the controller properties', function() {
it('should have people in scope', function() {
expect($scope.people.length).toEqual(10);
});
});
describe('the toggleTemplate method', function() {
it('should change the includeUrl', function() {
$scope.toggleTemplate();
expect($scope.widget.includeUrl).toEqual('app/template/peopleThumbnail.html');
$scope.toggleTemplate();
expect($scope.widget.includeUrl).toEqual('app/template/peopleList.html');
});
});
describe('theremovePerson method', function() {
it('should remove one person', function() {
$scope.removePerson($scope.people[2]);
expect($scope.people.length).toEqual(9);
});
it('should not remove anyone', function() {
$scope.removePerson({ $$hashKey: 'xxx' });
expect($scope.people.length).toEqual(10);
});
});
});