-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathtst_ganttChart.cls
More file actions
executable file
·260 lines (213 loc) · 8.27 KB
/
tst_ganttChart.cls
File metadata and controls
executable file
·260 lines (213 loc) · 8.27 KB
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
@isTest
public with sharing class tst_ganttChart {
@isTest
static void ganttChart_getChartData() {
Date d = Date.today();
DateTime dt = DateTime.now();
Project__c p = new Project__c(
Name='Test Project',
Color__c='Orange');
insert p;
Resource__c r = new Resource__c(
Name='Test Resource',
Default_Role__c='Test Role');
insert r;
Allocation__c a = new Allocation__c(
Project__c = p.Id,
Resource__c = r.Id,
Start_Date__c = d,
End_Date__c = d);
insert a;
Test.startTest();
Map<String, Object> chartData = ganttChart.getChartData(
null,
null,
null,
1,
new List<String>(),
new List<String>(),
'');
Test.stopTest();
System.assert(chartData.containsKey('projects'));
List<Object> projects = (List<Object>)chartData.get('projects');
System.assertEquals(1, projects.size());
Map<String, Object> projectMap = (Map<String, Object>)projects.get(0);
System.assertEquals(p.Id, (String)projectMap.get('Id'));
System.assert(chartData.containsKey('resources'));
List<Object> resources = (List<Object>)chartData.get('resources');
System.assertEquals(1, resources.size());
Map<String, Object> resourceMap = (Map<String, Object>)resources.get(0);
System.assertEquals(r.Id, (String)resourceMap.get('Id'));
System.assert(chartData.containsKey('roles'));
Set<String> roles = (Set<String>)chartData.get('roles');
System.assertEquals(1, roles.size());
System.assert(roles.contains(r.Default_Role__c));
}
@isTest
static void ganttChart_getChartData_withFilters() {
Date d = Date.today();
DateTime dt = DateTime.now();
Project__c p = new Project__c(
Name='Test Project',
Color__c='Orange');
insert p;
Resource__c r = new Resource__c(
Name='Test Resource',
Default_Role__c='Test Role');
insert r;
Allocation__c a = new Allocation__c(
Project__c = p.Id,
Resource__c = r.Id,
Effort__c = 'High',
Status__c = 'Active',
Start_Date__c = d,
End_Date__c = d);
insert a;
Test.startTest();
Map<String, Object> chartData = ganttChart.getChartData(
r.Id,
null,
null,
1,
new List<String> { p.Id },
new List<String> { r.Default_Role__c },
a.Status__c);
Test.stopTest();
System.assert(chartData.containsKey('projects'));
List<Object> projects = (List<Object>)chartData.get('projects');
System.assertEquals(1, projects.size());
Map<String, Object> projectMap = (Map<String, Object>)projects.get(0);
System.assertEquals(p.Id, (String)projectMap.get('Id'));
System.assert(chartData.containsKey('resources'));
List<Object> resources = (List<Object>)chartData.get('resources');
System.assertEquals(1, resources.size());
Map<String, Object> resourceMap = (Map<String, Object>)resources.get(0);
System.assertEquals(r.Id, (String)resourceMap.get('Id'));
System.assert(chartData.containsKey('roles'));
Set<String> roles = (Set<String>)chartData.get('roles');
System.assertEquals(1, roles.size());
System.assert(roles.contains(r.Default_Role__c));
}
@isTest
static void ganttChart_getResources() {
Resource__c r = new Resource__c(
Name='Test Resource',
Default_Role__c='Test Role');
insert r;
Test.startTest();
List<Object> resources = ganttChart.getResources();
Test.stopTest();
System.assertEquals(1, resources.size());
System.assertEquals(r.Id, ((Map<String, Object>)resources.get(0)).get('Id'));
System.assertEquals(r.Default_Role__c, ((Map<String, Object>)resources.get(0)).get('Default_Role__c'));
}
@isTest
static void ganttChart_getProjects() {
Project__c p = new Project__c(
Name='Test Project',
Color__c='Orange');
insert p;
Test.startTest();
List<Project__c> projects = ganttChart.getProjects();
Test.stopTest();
System.assertEquals(1, projects.size());
System.assertEquals(p.Id, projects.get(0).Id);
}
@isTest
static void ganttChart_saveAllocation() {
Date d = Date.today();
DateTime dt = DateTime.now();
Project__c p = new Project__c(
Name='Test Project',
Color__c='Orange');
insert p;
Resource__c r = new Resource__c(
Name='Test Resource',
Default_Role__c='Test Role');
insert r;
Date startDate = Date.newInstance(2023, 3, 1);
Date endDate = Date.newInstance(2023, 3, 10);
String effort = 'High';
String status = 'Active';
Test.startTest();
ganttChart.saveAllocation(null, p.Id, r.Id, effort, status, startDate, endDate);
Test.stopTest();
List<Allocation__c> allocations = [SELECT Id, Project__c, Resource__c, Effort__c, Status__c, Start_Date__c, End_Date__c
FROM Allocation__c];
System.assertEquals(1, allocations.size());
System.assertEquals(p.Id, allocations.get(0).Project__c);
System.assertEquals(r.Id, allocations.get(0).Resource__c);
System.assertEquals(effort, allocations.get(0).Effort__c);
System.assertEquals(status, allocations.get(0).Status__c);
}
@isTest
static void ganttChart_saveAllocation_update() {
Date d = Date.today();
DateTime dt = DateTime.now();
Project__c p = new Project__c(
Name='Test Project',
Color__c='Orange');
insert p;
Resource__c r = new Resource__c(
Name='Test Resource',
Default_Role__c='Test Role');
insert r;
String effort = 'High';
String status = 'Unavailable';
Date startDate = Date.newInstance(2023, 3, 1);
Date endDate = Date.newInstance(2023, 3, 10);
Allocation__c a = new Allocation__c(
Project__c = p.Id,
Resource__c = r.Id,
Effort__c = effort,
Status__c = 'Active',
Start_Date__c = d,
End_Date__c = d);
insert a;
Test.startTest();
ganttChart.saveAllocation(a.Id, null, r.Id, effort, status, startDate, endDate);
Test.stopTest();
List<Allocation__c> allocations = [SELECT Id, Project__c, Resource__c, Effort__c, Status__c, Start_Date__c, End_Date__c
FROM Allocation__c];
System.assertEquals(1, allocations.size());
System.assertEquals(a.Id, allocations.get(0).Id);
System.assertEquals(null, allocations.get(0).Project__c);
System.assertEquals(r.Id, allocations.get(0).Resource__c);
System.assertEquals(effort, allocations.get(0).Effort__c);
System.assertEquals(status, allocations.get(0).Status__c);
}
@isTest
static void ganttChart_deleteAllocation() {
Date d = Date.today();
Project__c p = new Project__c(
Name='Test Project',
Color__c='Orange');
insert p;
Resource__c r = new Resource__c(
Name='Test Resource',
Default_Role__c='Test Role');
insert r;
Allocation__c a = new Allocation__c(
Project__c = p.Id,
Resource__c = r.Id,
Start_Date__c = d,
End_Date__c = d);
insert a;
Test.startTest();
ganttChart.deleteAllocation(a.Id);
Test.stopTest();
List<Allocation__c> allocations = [SELECT Id FROM Allocation__c];
System.assertEquals(0, allocations.size());
}
@isTest
static void ganttChart_getHolidays() {
Date d = Date.today();
Holidays__c h = new Holidays__c(
Name='Test H',
HolidayDate__c = d);
insert h;
Test.startTest();
List<Holidays__c> holidays = ganttChart.getHolidays();
Test.stopTest();
}
}