-
Notifications
You must be signed in to change notification settings - Fork 297
/
customWidgetSettings.spec.js
179 lines (139 loc) · 5.74 KB
/
customWidgetSettings.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
'use strict';
describe('Controller: CustomSettingsDemoCtrl', function() {
var $scope, injections, WidgetDataModel, RandomDataModel;
beforeEach(module('app'));
beforeEach(inject(function($rootScope, $controller, $window, _WidgetDataModel_, _RandomDataModel_){
WidgetDataModel = _WidgetDataModel_;
RandomDataModel = _RandomDataModel_;
$scope = $rootScope.$new();
injections = {
$scope: $scope,
$window: $window,
RandomDataModel: RandomDataModel
};
$controller('CustomSettingsDemoCtrl', injections);
}));
describe('the controller properties', function() {
it('should have properties in scope', function() {
expect($scope.dashboardOptions.widgetButtons).toEqual(true);
expect($scope.dashboardOptions.widgetDefinitions.length).toEqual(2);
expect($scope.dashboardOptions.widgetDefinitions[0].name).toEqual('congfigurable widget');
expect($scope.dashboardOptions.widgetDefinitions[0].directive).toEqual('wt-scope-watch');
expect($scope.dashboardOptions.widgetDefinitions[0].dataAttrName).toEqual('value');
expect($scope.dashboardOptions.widgetDefinitions[0].dataModelType).toBeDefined();
expect($scope.dashboardOptions.widgetDefinitions[0].dataModelOptions.limit).toEqual(10);
expect($scope.dashboardOptions.widgetDefinitions[0].settingsModalOptions.partialTemplateUrl).toEqual('app/template/configurableWidgetModalOptions.html');
expect(typeof $scope.dashboardOptions.widgetDefinitions[0].onSettingsClose).toEqual('function');
expect($scope.dashboardOptions.widgetDefinitions[1].name).toEqual('override modal widget');
expect($scope.dashboardOptions.widgetDefinitions[1].directive).toEqual('wt-scope-watch');
expect($scope.dashboardOptions.widgetDefinitions[1].dataAttrName).toEqual('value');
expect($scope.dashboardOptions.widgetDefinitions[1].dataModelType).toBeDefined();
expect($scope.dashboardOptions.widgetDefinitions[1].settingsModalOptions.templateUrl).toEqual('app/template/WidgetSpecificSettings.html');
expect($scope.dashboardOptions.widgetDefinitions[1].settingsModalOptions.controller).toEqual('WidgetSpecificSettingsCtrl');
expect($scope.dashboardOptions.widgetDefinitions[1].settingsModalOptions.backdrop).toBe(false);
expect(typeof $scope.dashboardOptions.widgetDefinitions[1].onSettingsClose).toEqual('function');
expect(typeof $scope.dashboardOptions.widgetDefinitions[1].onSettingsDismiss).toEqual('function');
});
});
describe('the definition onSettingsClose function', function() {
it('should update the limit', function() {
var widget = $scope.dashboardOptions.widgetDefinitions[0];
widget.dataModel = new RandomDataModel();
widget.dataModel.setup(widget, $scope);
widget.dataModel.init();
var result = {
dataModelOptions: {
limit: 20
}
};
widget.onSettingsClose(result, widget);
expect(widget.dataModelOptions.limit).toEqual(20);
});
it('should not update the limit', function() {
var widget = $scope.dashboardOptions.widgetDefinitions[0];
var result = {
dataModelOptions: {
limit: 20
}
};
widget.onSettingsClose(result, widget);
expect(widget.dataModelOptions.limit).toEqual(10);
});
it('should update the title', function() {
var widget = $scope.dashboardOptions.widgetDefinitions[1];
widget.dataModel = new RandomDataModel();
widget.dataModel.setup(widget, $scope);
widget.dataModel.init();
var result = {
title: 'new widget title'
};
widget.onSettingsClose(result, widget);
expect(widget.title).toEqual('new widget title');
});
it('should call the settings dismiss', function() {
expect(function() {
$scope.dashboardOptions.widgetDefinitions[1].onSettingsDismiss();
}).not.toThrow();
});
});
describe('the dashboardOptions onSettingsClose function', function() {
it('should update the title', function() {
var widget = $scope.dashboardOptions.widgetDefinitions[1];
widget.dataModel = new RandomDataModel();
widget.dataModel.setup(widget, $scope);
widget.dataModel.init();
var result = {
title: 'new widget title'
};
$scope.dashboardOptions.onSettingsClose(result, widget);
expect(widget.title).toEqual('new widget title');
});
it('should call the settings dismiss', function() {
expect(function() {
$scope.dashboardOptions.onSettingsDismiss();
}).not.toThrow();
});
});
});
describe('Controller: WidgetSpecificSettingsCtrl', function() {
var $scope, uibModalInstance, widget = {};
beforeEach(module('app'));
beforeEach(inject(function($rootScope, $controller) {
$scope = $rootScope.$new();
uibModalInstance = {
close: function() {
},
dismiss: function() {
}
};
spyOn(uibModalInstance, 'close');
spyOn(uibModalInstance, 'dismiss');
// let's mock widget
$scope.widget = {
includeUrl: 'app/template/peopleList.html'
};
$controller('WidgetSpecificSettingsCtrl', {
$scope: $scope,
$uibModalInstance: uibModalInstance,
widget: widget
});
}));
describe('the controller properties', function() {
it('should have widget in scope', function() {
expect($scope.widget).toBeDefined();
expect($scope.result).toBeDefined();
});
});
describe('the ok function', function() {
it('should call modal close', function() {
$scope.ok();
expect(uibModalInstance.close).toHaveBeenCalled();
});
});
describe('the dismiss function', function() {
it('should call modal dismiss', function() {
$scope.cancel();
expect(uibModalInstance.dismiss).toHaveBeenCalled();
});
});
});