-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathactivities_controller_spec.rb
More file actions
336 lines (287 loc) · 13 KB
/
activities_controller_spec.rb
File metadata and controls
336 lines (287 loc) · 13 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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
require "rails_helper"
RSpec.describe Activities::ActivitiesController, type: :controller do
include_context "activity_hub"
render_views
describe "#index" do
let(:current_flow) { create(:activity_flow) }
before do
create(:activity_flow) # ensure there is a second flow that might get mixed up
current_flow.reload
activity = create(:volunteering_activity, activity_flow: current_flow, organization_name: "Food Pantry")
create(:volunteering_activity_month, volunteering_activity: activity, month: current_flow.reporting_window_range.begin, hours: 5)
session[:flow_id] = current_flow.id
session[:flow_type] = :activity
get :index
end
it "shows current flow community service activities" do
expect(
assigns(:community_service_activities)
).to match_array(
current_flow.volunteering_activities
)
end
it "shows current flow work programs activities" do
expect(
assigns(:work_programs_activities)
).to match_array(
current_flow.job_training_activities
)
end
it "shows current flow education activities" do
expect(
assigns(:education_activities)
).to match_array(
current_flow.education_activities
)
end
it "renders the progress indicator when hours exist" do
expect(response.body).to include("activity-flow-progress-indicator")
end
end
describe "delete-on-close cleanup" do
let(:current_flow) { create(:activity_flow, volunteering_activities_count: 0, job_training_activities_count: 0, education_activities_count: 0) }
before do
session[:flow_id] = current_flow.id
session[:flow_type] = :activity
end
it "destroys the tracked incomplete activity on hub visit" do
activity = create(:volunteering_activity, activity_flow: current_flow)
session[:creating_activity] = { "class_name" => "VolunteeringActivity", "id" => activity.id }
expect { get :index }.to change(VolunteeringActivity, :count).by(-1)
expect(session[:creating_activity]).to be_nil
end
it "does nothing when no creating_activity is in session" do
create(:volunteering_activity, activity_flow: current_flow)
expect { get :index }.not_to change(VolunteeringActivity, :count)
end
it "handles an already-deleted activity gracefully" do
session[:creating_activity] = { "class_name" => "VolunteeringActivity", "id" => -1 }
expect { get :index }.not_to raise_error
expect(session[:creating_activity]).to be_nil
end
it "destroys a tracked incomplete payroll account on hub visit" do
payroll_account = create(:payroll_account, :pinwheel_fully_synced, flow: current_flow)
session[:creating_payroll_account] = payroll_account.aggregator_account_id
expect { get :index }.to change(current_flow.payroll_accounts, :count).by(-1)
expect(session[:creating_payroll_account]).to be_nil
end
it "handles an already-deleted payroll account gracefully" do
session[:creating_payroll_account] = "nonexistent-account-id"
expect { get :index }.not_to raise_error
expect(session[:creating_payroll_account]).to be_nil
end
end
context "when no activities are added" do
let(:current_flow) do
create(:activity_flow, volunteering_activities_count: 0, job_training_activities_count: 0, education_activities_count: 0)
end
before do
session[:flow_id] = current_flow.id
session[:flow_type] = :activity
get :index
end
it "renders empty-state copy for all sections and hides review and submit" do
expect(response.body).to include(I18n.t("activities.hub.empty.employment"))
expect(response.body).to include(I18n.t("activities.hub.empty.education"))
expect(response.body).to include(I18n.t("activities.hub.empty.community_service"))
expect(response.body).to include(I18n.t("activities.hub.empty.work_programs"))
expect(response.body).not_to include(I18n.t("activities.hub.review_and_submit"))
end
it "renders the progress indicator even with no hours" do
expect(response.body).to include("activity-flow-progress-indicator")
end
it "renders the two-column container" do
expect(response.body).to include("activity-hub-columns")
end
it "does not render the horizontal divider" do
expect(response.body).not_to include("activity-hub-divider")
end
end
context "when at least one activity is added" do
let(:current_flow) { create(:activity_flow, volunteering_activities_count: 0, job_training_activities_count: 0, education_activities_count: 0) }
before do
create(:volunteering_activity, activity_flow: current_flow, hours: 1)
session[:flow_id] = current_flow.id
session[:flow_type] = :activity
get :index
end
it "does not show empty state for community service and shows review and submit" do
expect(response.body).not_to include(I18n.t("activities.hub.empty.community_service"))
expect(response.body).to include(I18n.t("activities.hub.review_and_submit"))
end
end
context "when education activity has no enrollment records" do
let(:current_flow) { create(:activity_flow, volunteering_activities_count: 0, job_training_activities_count: 0, education_activities_count: 0) }
before do
create(:education_activity, activity_flow: current_flow, status: :no_enrollments)
session[:flow_id] = current_flow.id
session[:flow_type] = :activity
get :index
end
it "shows education empty-state copy" do
expect(response.body).to include(I18n.t("activities.hub.empty.education"))
end
end
context "when education activity has enrollment records" do
let(:current_flow) { create(:activity_flow, volunteering_activities_count: 0, job_training_activities_count: 0, education_activities_count: 0, reporting_window_months: 1) }
before do
education_activity = create(:education_activity, activity_flow: current_flow)
create(
:nsc_enrollment_term,
education_activity:,
term_begin: current_flow.reporting_months.first.beginning_of_month,
term_end: current_flow.reporting_months.first.end_of_month
)
session[:flow_id] = current_flow.id
session[:flow_type] = :activity
get :index
end
it "shows enrollment data and not the empty-state copy" do
expect(response.body).to include("Test University")
expect(response.body).to include(
I18n.t(
"activities.hub.cards.enrollment_status",
status: I18n.t("components.enrollment_term_table_component.status.half_time")
)
)
expect(response.body).to include(I18n.t("activities.hub.cards.hours", count: ActivityFlowProgressCalculator::PER_MONTH_HOURS_THRESHOLD))
expect(response.body).not_to include(I18n.t("activities.hub.cards.credit_hours", amount: 12))
expect(response.body).not_to include(I18n.t("activities.hub.empty.education"))
end
end
context "when education activity has less-than-half-time enrollment records" do
let(:current_flow) { create(:activity_flow, volunteering_activities_count: 0, job_training_activities_count: 0, education_activities_count: 0, reporting_window_months: 1) }
before do
education_activity = create(:education_activity, activity_flow: current_flow, data_source: :partially_self_attested)
create(
:nsc_enrollment_term,
:less_than_half_time,
education_activity: education_activity,
credit_hours: 4,
term_begin: current_flow.reporting_months.first.beginning_of_month,
term_end: current_flow.reporting_months.first.end_of_month
)
session[:flow_id] = current_flow.id
session[:flow_type] = :activity
get :index
end
it "shows enrollment status with saved credit hours and CE hours on the education card" do
expect(response.body).to include("Test University")
expect(response.body).to include(
I18n.t(
"activities.hub.cards.enrollment_status",
status: I18n.t("components.enrollment_term_table_component.status.less_than_half_time")
)
)
expect(response.body).to include(I18n.t("activities.hub.cards.credit_hours", amount: 4))
expect(response.body).to include(I18n.t("activities.hub.cards.hours", count: 16))
expect(response.body).not_to include(I18n.t("activities.hub.empty.education"))
end
end
context "when education activity has mixed overlapping statuses in each month" do
let(:half_time_school_name) { "Pine Valley College" }
let(:less_than_half_time_school_name) { "Riverside Community College" }
let(:current_flow) do
create(
:activity_flow,
volunteering_activities_count: 0,
job_training_activities_count: 0,
education_activities_count: 0,
reporting_window_months: 2
)
end
before do
education_activity = create(:education_activity, activity_flow: current_flow, data_source: :validated, status: :succeeded)
first_month = current_flow.reporting_months.first
second_month = current_flow.reporting_months.second
create(
:nsc_enrollment_term,
education_activity: education_activity,
school_name: half_time_school_name,
enrollment_status: :half_time,
term_begin: first_month,
term_end: second_month.end_of_month
)
create(
:nsc_enrollment_term,
:less_than_half_time,
education_activity: education_activity,
school_name: less_than_half_time_school_name,
credit_hours: 0,
term_begin: first_month,
term_end: second_month.end_of_month
)
session[:flow_id] = current_flow.id
session[:flow_type] = :activity
get :index
end
it "shows all enrollment statuses on education cards and uses 80 hours in monthly progress" do
expect(response.body).to include(half_time_school_name)
expect(response.body).to include(less_than_half_time_school_name)
expect(response.body).to include(
I18n.t(
"activities.hub.cards.enrollment_status",
status: I18n.t("components.enrollment_term_table_component.status.half_time")
)
)
expect(response.body).to include(
I18n.t(
"activities.hub.cards.enrollment_status",
status: I18n.t("components.enrollment_term_table_component.status.less_than_half_time")
)
)
progress_text = /80\s*\/\s*#{ActivityFlowProgressCalculator::PER_MONTH_HOURS_THRESHOLD}\s*#{I18n.t("activity_flow_progress_indicator.hours")}/
page_text = Capybara.string(response.body).text
expect(page_text.scan(progress_text).count).to eq(2)
end
end
context "when self-attested education activity is added" do
let(:current_flow) { create(:activity_flow, volunteering_activities_count: 0, job_training_activities_count: 0, education_activities_count: 0, reporting_window_months: 1) }
before do
education_activity = create(
:education_activity,
activity_flow: current_flow,
data_source: :fully_self_attested,
school_name: "Colorado Springs Community College"
)
create(
:education_activity_month,
education_activity: education_activity,
month: current_flow.reporting_months.first.beginning_of_month,
hours: 4
)
session[:flow_id] = current_flow.id
session[:flow_type] = :activity
get :index
end
it "shows self-attested education card details and hides empty-state copy" do
expect(response.body).to include("Colorado Springs Community College")
expect(response.body).to include(I18n.t("activities.hub.cards.credit_hours", amount: 4))
expect(response.body).to include(I18n.t("activities.hub.cards.hours", count: 16))
expect(response.body).not_to include(I18n.t("activities.hub.empty.education"))
expect(response.body).to include(I18n.t("activities.hub.review_and_submit"))
end
end
context "when self-attested employment activities are added" do
let(:current_flow) { create(:activity_flow, volunteering_activities_count: 0, job_training_activities_count: 0, education_activities_count: 0, reporting_window_months: 1) }
before do
employment_activity = create(:employment_activity, activity_flow: current_flow, employer_name: "Gainesville Wrecking")
create(
:employment_activity_month,
employment_activity: employment_activity,
month: current_flow.reporting_months.first.beginning_of_month,
gross_income: 500,
hours: 40
)
session[:flow_id] = current_flow.id
session[:flow_type] = :activity
get :index
end
it "shows current flow employment activities" do
expect(assigns(:employment_activities)).to match_array(current_flow.employment_activities)
expect(response.body).to include("Gainesville Wrecking")
expect(response.body).to include(I18n.t("activities.hub.cards.gross_income", amount: "$500.00"))
expect(response.body).to include(I18n.t("activities.hub.cards.hours", count: 40))
end
end
end