CRM-19723 - CaseType Config UI improvements: icons, popups, labels
[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 },
127 relTypes: {
128 values: [
129 {
130 "id": "14",
131 "name_a_b": "Benefits Specialist is",
132 "label_a_b": "Benefits Specialist is",
133 "name_b_a": "Benefits Specialist",
134 "label_b_a": "Benefits Specialist",
135 "description": "Benefits Specialist",
136 "contact_type_a": "Individual",
137 "contact_type_b": "Individual",
138 "is_reserved": "0",
139 "is_active": "1"
140 },
141 {
142 "id": "9",
143 "name_a_b": "Case Coordinator is",
144 "label_a_b": "Case Coordinator is",
145 "name_b_a": "Case Coordinator",
146 "label_b_a": "Case Coordinator",
147 "description": "Case Coordinator",
148 "contact_type_a": "Individual",
149 "contact_type_b": "Individual",
150 "is_reserved": "0",
151 "is_active": "1"
152 }
153 ]
154 },
155 caseType: {
156 "id": "1",
157 "name": "housing_support",
158 "title": "Housing Support",
159 "description": "Help homeless individuals obtain temporary and long-term housing",
160 "is_active": "1",
161 "is_reserved": "0",
162 "weight": "1",
163 "is_forkable": "1",
164 "is_forked": "",
165 "definition": {
166 "activityTypes": [
167 {"name": "Open Case", "max_instances": "1"}
168 ],
169 "activitySets": [
170 {
171 "name": "standard_timeline",
172 "label": "Standard Timeline",
173 "timeline": "1",
174 "activityTypes": [
175 {
176 "name": "Open Case",
177 "status": "Completed"
178 },
179 {
180 "name": "Medical evaluation",
181 "reference_activity": "Open Case",
182 "reference_offset": "1",
183 "reference_select": "newest"
184 }
185 ]
186 }
187 ],
188 "caseRoles": [
189 {
190 "name": "Homeless Services Coordinator",
191 "creator": "1",
192 "manager": "1"
193 }
194 ]
195 }
196 }
197 };
198 ctrl = $controller('CaseTypeCtrl', {$scope: scope, apiCalls: apiCalls});
199 }));
200
201 it('should load activity statuses', function() {
202 expect(scope.activityStatuses).toEqualData(apiCalls.actStatuses.values);
203 });
204
205 it('should load activity types', function() {
206 expect(scope.activityTypes['ADC referral']).toEqualData(apiCalls.actTypes.values[0]);
207 });
208
209 it('addActivitySet should add an activitySet to the case type', function() {
210 scope.addActivitySet('timeline');
211 var activitySets = scope.caseType.definition.activitySets;
212 var newSet = activitySets[activitySets.length - 1];
213 expect(newSet.name).toBe('timeline_1');
214 expect(newSet.timeline).toBe('1');
215 expect(newSet.label).toBe('Timeline');
216 });
217
218 it('addActivitySet handles second timeline correctly', function() {
219 scope.addActivitySet('timeline');
220 scope.addActivitySet('timeline');
221 var activitySets = scope.caseType.definition.activitySets;
222 var newSet = activitySets[activitySets.length - 1];
223 expect(newSet.name).toBe('timeline_2');
224 expect(newSet.timeline).toBe('1');
225 expect(newSet.label).toBe('Timeline #2');
226 });
227
228 });
229 });