Merge pull request #5536 from totten/4.5-httpclient
[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.crmCaseType = {
10 'REL_TYPE_CNAME': 'label_b_a'
11 };
12 module('crmCaseType');
13 module('crmJsonComparator');
14 inject(function(crmJsonComparator) {
15 crmJsonComparator.register(jasmine);
16 });
17 });
18
19 describe('CaseTypeCtrl', function() {
20 var apiCalls;
21 var ctrl;
22 var compile;
23 var $httpBackend;
24 var scope;
25 var timeout;
26
27 beforeEach(inject(function(_$httpBackend_, $rootScope, $controller, $compile, $timeout) {
28 $httpBackend = _$httpBackend_;
29 scope = $rootScope.$new();
30 compile = $compile;
31 timeout = $timeout;
32 apiCalls = {
33 'actStatuses': {
34 'values': {
35 "272": {
36 "id": "272",
37 "option_group_id": "25",
38 "label": "Scheduled",
39 "value": "1",
40 "name": "Scheduled",
41 "filter": "0",
42 "is_default": "1",
43 "weight": "1",
44 "is_optgroup": "0",
45 "is_reserved": "1",
46 "is_active": "1"
47 },
48 "273": {
49 "id": "273",
50 "option_group_id": "25",
51 "label": "Completed",
52 "value": "2",
53 "name": "Completed",
54 "filter": "0",
55 "weight": "2",
56 "is_optgroup": "0",
57 "is_reserved": "1",
58 "is_active": "1"
59 }
60 }
61 },
62 'actTypes': {
63 'values': {
64 "784": {
65 "id": "784",
66 "option_group_id": "2",
67 "label": "ADC referral",
68 "value": "62",
69 "name": "ADC referral",
70 "filter": "0",
71 "is_default": "0",
72 "weight": "64",
73 "is_optgroup": "0",
74 "is_reserved": "0",
75 "is_active": "1",
76 "component_id": "7"
77 },
78 "32": {
79 "id": "32",
80 "option_group_id": "2",
81 "label": "Add Client To Case",
82 "value": "27",
83 "name": "Add Client To Case",
84 "filter": "0",
85 "is_default": "0",
86 "weight": "26",
87 "description": "",
88 "is_optgroup": "0",
89 "is_reserved": "1",
90 "is_active": "1",
91 "component_id": "7"
92 }
93 }
94 },
95 'relTypes': {
96 'values' : {
97 "14": {
98 "id": "14",
99 "name_a_b": "Benefits Specialist is",
100 "label_a_b": "Benefits Specialist is",
101 "name_b_a": "Benefits Specialist",
102 "label_b_a": "Benefits Specialist",
103 "description": "Benefits Specialist",
104 "contact_type_a": "Individual",
105 "contact_type_b": "Individual",
106 "is_reserved": "0",
107 "is_active": "1"
108 },
109 "9": {
110 "id": "9",
111 "name_a_b": "Case Coordinator is",
112 "label_a_b": "Case Coordinator is",
113 "name_b_a": "Case Coordinator",
114 "label_b_a": "Case Coordinator",
115 "description": "Case Coordinator",
116 "contact_type_a": "Individual",
117 "contact_type_b": "Individual",
118 "is_reserved": "0",
119 "is_active": "1"
120 }
121 }
122 },
123 "caseType": {
124 "id": "1",
125 "name": "housing_support",
126 "title": "Housing Support",
127 "description": "Help homeless individuals obtain temporary and long-term housing",
128 "is_active": "1",
129 "is_reserved": "0",
130 "weight": "1",
131 "is_forkable": "1",
132 "is_forked": "",
133 "definition": {
134 "activityTypes": [
135 {"name": "Open Case", "max_instances": "1"}
136 ],
137 "activitySets": [
138 {
139 "name": "standard_timeline",
140 "label": "Standard Timeline",
141 "timeline": "1",
142 "activityTypes": [
143 {
144 "name": "Open Case",
145 "status": "Completed"
146 },
147 {
148 "name": "Medical evaluation",
149 "reference_activity": "Open Case",
150 "reference_offset": "1",
151 "reference_select": "newest"
152 }
153 ]
154 }
155 ],
156 "caseRoles": [
157 {
158 "name": "Homeless Services Coordinator",
159 "creator": "1",
160 "manager": "1"
161 }
162 ]
163 }
164 }
165 };
166 ctrl = $controller('CaseTypeCtrl', {$scope: scope, apiCalls: apiCalls});
167 }));
168
169 it('should load activity statuses', function() {
170 expect(scope.activityStatuses).toEqualData([apiCalls.actStatuses.values['272'], apiCalls.actStatuses.values['273']]);
171 });
172
173 it('should load activity types', function() {
174 expect(scope.activityTypes).toEqualData(apiCalls.actTypes.values);
175 });
176
177 it('addActivitySet should add an activitySet to the case type', function() {
178 scope.addActivitySet('timeline');
179 var activitySets = scope.caseType.definition.activitySets;
180 var newSet = activitySets[activitySets.length - 1];
181 expect(newSet.name).toBe('timeline_1');
182 expect(newSet.timeline).toBe('1');
183 expect(newSet.label).toBe('Timeline');
184 });
185
186 it('addActivitySet handles second timeline correctly', function() {
187 scope.addActivitySet('timeline');
188 scope.addActivitySet('timeline');
189 var activitySets = scope.caseType.definition.activitySets;
190 var newSet = activitySets[activitySets.length - 1];
191 expect(newSet.name).toBe('timeline_2');
192 expect(newSet.timeline).toBe('1');
193 expect(newSet.label).toBe('Timeline #2');
194 });
195
196 });
197 });