1 /* global $, _, CRM:true */
4 describe('crmCaseType', function() {
15 beforeEach(function() {
19 // CRM_Case_XMLProcessor::REL_TYPE_CNAME
21 'REL_TYPE_CNAME': 'label_b_a'
23 module('crmCaseType');
24 module('crmJsonComparator');
25 inject(function(crmJsonComparator
) {
26 crmJsonComparator
.register(jasmine
);
30 beforeEach(inject(function(_
$controller_
, _
$compile_
, _
$httpBackend_
, _
$q_
, _
$rootScope_
) {
31 $controller
= _
$controller_
;
32 $compile
= _
$compile_
;
33 $httpBackend
= _
$httpBackend_
;
35 $rootScope
= _
$rootScope_
;
38 describe('CaseTypeCtrl', function() {
39 beforeEach(function () {
45 "option_group_id": "25",
58 "option_group_id": "25",
74 "option_group_id": "28",
88 "option_group_id": "28",
105 "option_group_id": "2",
106 "label": "ADC referral",
108 "name": "ADC referral",
119 "option_group_id": "2",
120 "label": "Add Client To Case",
122 "name": "Add Client To Case",
134 "option_group_id": "2",
135 "label": "Open Case",
145 "icon": "fa-folder-open-o"
149 "option_group_id": "2",
150 "label": "Medical evaluation",
152 "name": "Medical evaluation",
167 "name_a_b": "Benefits Specialist is",
168 "label_a_b": "Benefits Specialist is",
169 "name_b_a": "Benefits Specialist",
170 "label_b_a": "Benefits Specialist",
171 "description": "Benefits Specialist",
172 "contact_type_a": "Individual",
173 "contact_type_b": "Individual",
179 "name_a_b": "Case Coordinator is",
180 "label_a_b": "Case Coordinator is",
181 "name_b_a": "Case Coordinator",
182 "label_b_a": "Case Coordinator",
183 "description": "Case Coordinator",
184 "contact_type_a": "Individual",
185 "contact_type_b": "Individual",
193 "name": "housing_support",
194 "title": "Housing Support",
195 "description": "Help homeless individuals obtain temporary and long-term housing",
203 {"name": "Open Case", "max_instances": "1"}
207 "name": "standard_timeline",
208 "label": "Standard Timeline",
213 "status": "Completed"
216 "name": "Medical evaluation",
217 "reference_activity": "Open Case",
218 "reference_offset": "1",
219 "reference_select": "newest"
226 "name": "Homeless Services Coordinator",
234 scope
= $rootScope
.$new();
235 ctrl
= $controller('CaseTypeCtrl', {$scope
: scope
, apiCalls
: apiCalls
});
238 it('should load activity statuses', function() {
239 expect(scope
.activityStatuses
).toEqualData(apiCalls
.actStatuses
.values
);
242 it('should load activity types', function() {
243 expect(scope
.activityTypes
['ADC referral']).toEqualData(apiCalls
.actTypes
.values
[0]);
246 it('addActivitySet should add an activitySet to the case type', function() {
247 scope
.addActivitySet('timeline');
248 var activitySets
= scope
.caseType
.definition
.activitySets
;
249 var newSet
= activitySets
[activitySets
.length
- 1];
250 expect(newSet
.name
).toBe('timeline_1');
251 expect(newSet
.timeline
).toBe('1');
252 expect(newSet
.label
).toBe('Timeline');
255 it('addActivitySet handles second timeline correctly', function() {
256 scope
.addActivitySet('timeline');
257 scope
.addActivitySet('timeline');
258 var activitySets
= scope
.caseType
.definition
.activitySets
;
259 var newSet
= activitySets
[activitySets
.length
- 1];
260 expect(newSet
.name
).toBe('timeline_2');
261 expect(newSet
.timeline
).toBe('1');
262 expect(newSet
.label
).toBe('Timeline #2');
266 describe('crmAddName', function () {
269 beforeEach(function() {
270 scope
= $rootScope
.$new();
271 scope
.activityTypeOptions
= [1, 2, 3];
272 element
= '<span crm-add-name crm-options="activityTypeOptions"></span>';
274 spyOn(CRM
.$.fn
, 'crmSelect2').and
.callThrough();
276 element
= $compile(element
)(scope
);
280 describe('when initialized', function () {
283 beforeEach (function () {
284 var dataFunction
= CRM
.$.fn
.crmSelect2
.calls
.argsFor(0)[0].data
;
285 returnValue
= dataFunction();
288 it('updates the UI with updated value of scope variable', function () {
289 expect(returnValue
).toEqual({ results
: scope
.activityTypeOptions
});
294 describe('CaseTypeListCtrl', function() {
295 var caseTypes
, crmApiSpy
;
297 beforeEach(function() {
305 crmApiSpy
= jasmine
.createSpy('crmApi').and
.returnValue($q
.resolve());
306 scope
= $rootScope
.$new();
307 ctrl
= $controller('CaseTypeListCtrl', {
309 caseTypes
: caseTypes
,
314 it('should store an index of case types', function() {
315 expect(scope
.caseTypes
).toEqual(caseTypes
.values
);
318 describe('toggleCaseType', function() {
319 var caseType
= { id
: _
.uniqueId() };
321 describe('when the case is active', function() {
322 beforeEach(function() {
323 caseType
.is_active
= '1';
325 scope
.toggleCaseType(caseType
);
328 it('sets the case type as inactive', function() {
329 expect(crmApiSpy
).toHaveBeenCalledWith('CaseType', 'create', jasmine
.objectContaining({
336 describe('when the case is inactive', function() {
337 beforeEach(function() {
338 caseType
.is_active
= '0';
340 scope
.toggleCaseType(caseType
);
343 it('sets the case type as active', function() {
344 expect(crmApiSpy
).toHaveBeenCalledWith('CaseType', 'create', jasmine
.objectContaining({
352 describe('deleteCaseType', function() {
353 var caseType
= { id
: _
.uniqueId() };
355 beforeEach(function() {
356 crmApiSpy
.and
.returnValue($q
.resolve(caseType
));
357 scope
.caseTypes
[caseType
.id
] = caseType
;
359 scope
.deleteCaseType(caseType
);
363 describe('when the case type can be deleted', function() {
364 it('deletes the case from the api', function() {
365 expect(crmApiSpy
).toHaveBeenCalledWith('CaseType', 'delete', { id
: caseType
.id
}, jasmine
.any(Object
));
368 it('removes the case type from the list', function() {
369 expect(scope
.caseTypes
[caseType
.id
]).toBeUndefined();
373 describe('when the case type cannot be delted', function() {
374 var error
= { error_message
: 'Error Message' };
376 beforeEach(function() {
379 crmApiSpy
.and
.returnValue($q
.reject(error
));
380 scope
.caseTypes
[caseType
.id
] = caseType
;
383 scope
.deleteCaseType(caseType
);
386 errorHandler
= crmApiSpy
.calls
.mostRecent().args
[3].error
;
390 it('displays the error message', function() {
391 expect(CRM
.alert
).toHaveBeenCalledWith(error
.error_message
, 'Error', 'error');
395 describe('revertCaseType', function() {
402 describe('when reverting a case type', function() {
403 beforeEach(function() {
404 scope
.revertCaseType(caseType
);
407 it('resets the case type information using the api', function() {
408 expect(crmApiSpy
).toHaveBeenCalledWith('CaseType', 'create', jasmine
.objectContaining({