Merge pull request #9973 from lcdservices/CRM-19469
[civicrm-core.git] / tests / karma / unit / crmCaseTypeSpec.js
1 'use strict';
2
3 describe('crmCaseType', function() {
4
5 beforeEach(function() {
6 CRM.resourceUrls = {
7 'civicrm': ''
8 };
9 // CRM_Case_XMLProcessor::REL_TYPE_CNAME
10 CRM.crmCaseType = {
11 'REL_TYPE_CNAME': 'label_b_a'
12 };
13 module('crmCaseType');
14 module('crmJsonComparator');
15 inject(function(crmJsonComparator) {
16 crmJsonComparator.register(jasmine);
17 });
18 });
19
20 describe('CaseTypeCtrl', function() {
21 var apiCalls;
22 var ctrl;
23 var compile;
24 var $httpBackend;
25 var scope;
26 var timeout;
27
28 beforeEach(inject(function(_$httpBackend_, $rootScope, $controller, $compile, $timeout) {
29 $httpBackend = _$httpBackend_;
30 scope = $rootScope.$new();
31 compile = $compile;
32 timeout = $timeout;
33 apiCalls = {
34 actStatuses: {
35 values: [
36 {
37 "id": "272",
38 "option_group_id": "25",
39 "label": "Scheduled",
40 "value": "1",
41 "name": "Scheduled",
42 "filter": "0",
43 "is_default": "1",
44 "weight": "1",
45 "is_optgroup": "0",
46 "is_reserved": "1",
47 "is_active": "1"
48 },
49 {
50 "id": "273",
51 "option_group_id": "25",
52 "label": "Completed",
53 "value": "2",
54 "name": "Completed",
55 "filter": "0",
56 "weight": "2",
57 "is_optgroup": "0",
58 "is_reserved": "1",
59 "is_active": "1"
60 }
61 ]
62 },
63 caseStatuses: {
64 values: [
65 {
66 "id": "290",
67 "option_group_id": "28",
68 "label": "Ongoing",
69 "value": "1",
70 "name": "Open",
71 "grouping": "Opened",
72 "filter": "0",
73 "is_default": "1",
74 "weight": "1",
75 "is_optgroup": "0",
76 "is_reserved": "1",
77 "is_active": "1"
78 },
79 {
80 "id": "291",
81 "option_group_id": "28",
82 "label": "Resolved",
83 "value": "2",
84 "name": "Closed",
85 "grouping": "Closed",
86 "filter": "0",
87 "weight": "2",
88 "is_optgroup": "0",
89 "is_reserved": "1",
90 "is_active": "1"
91 }
92 ]
93 },
94 actTypes: {
95 values: [
96 {
97 "id": "784",
98 "option_group_id": "2",
99 "label": "ADC referral",
100 "value": "62",
101 "name": "ADC referral",
102 "filter": "0",
103 "is_default": "0",
104 "weight": "64",
105 "is_optgroup": "0",
106 "is_reserved": "0",
107 "is_active": "1",
108 "component_id": "7"
109 },
110 {
111 "id": "32",
112 "option_group_id": "2",
113 "label": "Add Client To Case",
114 "value": "27",
115 "name": "Add Client To Case",
116 "filter": "0",
117 "is_default": "0",
118 "weight": "26",
119 "description": "",
120 "is_optgroup": "0",
121 "is_reserved": "1",
122 "is_active": "1",
123 "component_id": "7"
124 },
125 {
126 "id": "18",
127 "option_group_id": "2",
128 "label": "Open Case",
129 "value": "13",
130 "name": "Open Case",
131 "filter": "0",
132 "is_default": "0",
133 "weight": "13",
134 "is_optgroup": "0",
135 "is_reserved": "1",
136 "is_active": "1",
137 "component_id": "7",
138 "icon": "fa-folder-open-o"
139 },
140 {
141 "id": "857",
142 "option_group_id": "2",
143 "label": "Medical evaluation",
144 "value": "55",
145 "name": "Medical evaluation",
146 "filter": "0",
147 "is_default": "0",
148 "weight": "56",
149 "is_optgroup": "0",
150 "is_reserved": "0",
151 "is_active": "1",
152 "component_id": "7"
153 },
154 ]
155 },
156 relTypes: {
157 values: [
158 {
159 "id": "14",
160 "name_a_b": "Benefits Specialist is",
161 "label_a_b": "Benefits Specialist is",
162 "name_b_a": "Benefits Specialist",
163 "label_b_a": "Benefits Specialist",
164 "description": "Benefits Specialist",
165 "contact_type_a": "Individual",
166 "contact_type_b": "Individual",
167 "is_reserved": "0",
168 "is_active": "1"
169 },
170 {
171 "id": "9",
172 "name_a_b": "Case Coordinator is",
173 "label_a_b": "Case Coordinator is",
174 "name_b_a": "Case Coordinator",
175 "label_b_a": "Case Coordinator",
176 "description": "Case Coordinator",
177 "contact_type_a": "Individual",
178 "contact_type_b": "Individual",
179 "is_reserved": "0",
180 "is_active": "1"
181 }
182 ]
183 },
184 caseType: {
185 "id": "1",
186 "name": "housing_support",
187 "title": "Housing Support",
188 "description": "Help homeless individuals obtain temporary and long-term housing",
189 "is_active": "1",
190 "is_reserved": "0",
191 "weight": "1",
192 "is_forkable": "1",
193 "is_forked": "",
194 "definition": {
195 "activityTypes": [
196 {"name": "Open Case", "max_instances": "1"}
197 ],
198 "activitySets": [
199 {
200 "name": "standard_timeline",
201 "label": "Standard Timeline",
202 "timeline": "1",
203 "activityTypes": [
204 {
205 "name": "Open Case",
206 "status": "Completed"
207 },
208 {
209 "name": "Medical evaluation",
210 "reference_activity": "Open Case",
211 "reference_offset": "1",
212 "reference_select": "newest"
213 }
214 ]
215 }
216 ],
217 "caseRoles": [
218 {
219 "name": "Homeless Services Coordinator",
220 "creator": "1",
221 "manager": "1"
222 }
223 ]
224 }
225 }
226 };
227 ctrl = $controller('CaseTypeCtrl', {$scope: scope, apiCalls: apiCalls});
228 }));
229
230 it('should load activity statuses', function() {
231 expect(scope.activityStatuses).toEqualData(apiCalls.actStatuses.values);
232 });
233
234 it('should load activity types', function() {
235 expect(scope.activityTypes['ADC referral']).toEqualData(apiCalls.actTypes.values[0]);
236 });
237
238 it('addActivitySet should add an activitySet to the case type', function() {
239 scope.addActivitySet('timeline');
240 var activitySets = scope.caseType.definition.activitySets;
241 var newSet = activitySets[activitySets.length - 1];
242 expect(newSet.name).toBe('timeline_1');
243 expect(newSet.timeline).toBe('1');
244 expect(newSet.label).toBe('Timeline');
245 });
246
247 it('addActivitySet handles second timeline correctly', function() {
248 scope.addActivitySet('timeline');
249 scope.addActivitySet('timeline');
250 var activitySets = scope.caseType.definition.activitySets;
251 var newSet = activitySets[activitySets.length - 1];
252 expect(newSet.name).toBe('timeline_2');
253 expect(newSet.timeline).toBe('1');
254 expect(newSet.label).toBe('Timeline #2');
255 });
256
257 });
258 });