Skip to content

Commit 9fcbaf9

Browse files
committed
Add basic feature tests for sessions
This adds some basic tests that cover the functionality of creating a clinic or school session. Jira-Issue: MAV-2645
1 parent 37241ee commit 9fcbaf9

3 files changed

Lines changed: 103 additions & 83 deletions

File tree

spec/factories/patients.rb

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,16 @@
5555

5656
factory :patient do
5757
transient do
58-
academic_year { AcademicYear.current }
58+
academic_year { session&.academic_year || AcademicYear.current }
59+
location { session&.location }
60+
location_name { nil }
5961
parents { [] }
6062
performed_by { association(:user) }
6163
programmes { session&.programmes || [] }
62-
session { nil }
63-
year_group { programmes.flat_map(&:default_year_groups).sort.uniq.first }
64-
location_name { nil }
6564
random_nhs_number { false }
66-
65+
session { nil }
6766
team { session&.team || school&.team || create(:team, programmes:) }
67+
year_group { programmes.flat_map(&:default_year_groups).sort.uniq.first }
6868
end
6969

7070
nhs_number do
@@ -124,14 +124,9 @@
124124
end
125125

126126
after(:create) do |patient, evaluator|
127-
if (session = evaluator.session)
128-
location_id = session.location_id
129-
academic_year = session.academic_year
130-
PatientLocation.find_or_create_by!(
131-
patient:,
132-
location_id:,
133-
academic_year:
134-
)
127+
if (location = evaluator.location) &&
128+
(academic_year = evaluator.academic_year)
129+
PatientLocation.find_or_create_by!(patient:, location:, academic_year:)
135130
end
136131
end
137132

spec/features/manage_clinic_sessions_spec.rb renamed to spec/features/sessions_clinic_spec.rb

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,28 @@
11
# frozen_string_literal: true
22

3-
describe "Manage clinic sessions" do
3+
describe "Clinic sessions" do
44
around { |example| travel_to(Time.zone.local(2024, 2, 18)) { example.run } }
55

6-
scenario "Adding dates to the session, sending reminders and closing consent" do
6+
before { Flipper.enable(:schools_and_sessions) }
7+
8+
scenario "adding a new session, sending reminders and closing consent" do
79
given_my_team_is_running_an_hpv_vaccination_programme
810
and_i_am_signed_in
911

1012
when_i_go_to_todays_sessions_as_a_nurse
1113
then_i_see_no_sessions
1214

13-
when_i_go_to_unscheduled_sessions
14-
then_i_see_the_community_clinic
15-
16-
when_i_click_on_the_community_clinic
17-
then_i_see_the_clinic_session
18-
19-
when_i_click_on_schedule_sessions
20-
then_i_see_the_dates_page
21-
22-
when_i_choose_the_dates
15+
when_i_click_on_add_a_new_session
16+
and_i_choose_community_clinic
17+
and_i_choose_the_programmes
18+
and_i_choose_the_dates
2319
then_i_see_the_confirmation_page
2420

2521
when_i_click_on_change_invitations
2622
then_i_see_the_change_invitations_page
2723
and_i_change_invitations_date
2824

29-
when_i_save_changes
25+
when_i_save_the_session
3026
then_i_should_see_the_session_details
3127

3228
when_i_go_to_todays_sessions_as_a_nurse
@@ -73,19 +69,15 @@ def given_my_team_is_running_an_hpv_vaccination_programme
7369
programmes: [@programme]
7470
)
7571

76-
@session =
77-
create(
78-
:session,
79-
:unscheduled,
80-
team: @team,
81-
programmes: [@programme],
82-
location: @team.generic_clinic
83-
)
84-
8572
@parent = create(:parent)
8673

8774
@patient =
88-
create(:patient, year_group: 8, session: @session, parents: [@parent])
75+
create(
76+
:patient,
77+
year_group: 8,
78+
location: @team.generic_clinic,
79+
parents: [@parent]
80+
)
8981
end
9082

9183
def and_i_am_signed_in
@@ -131,16 +123,29 @@ def then_i_see_the_clinic_session
131123
expect(page).to have_content("No dates scheduled")
132124
end
133125

134-
def when_i_click_on_schedule_sessions
135-
click_on "Edit session"
136-
click_on "Add session dates"
126+
def when_i_click_on_add_a_new_session
127+
click_on "Add a new session"
137128
end
138129

139-
def then_i_see_the_dates_page
140-
expect(page).to have_content("When will this session be held?")
130+
def and_i_choose_community_clinic
131+
expect(page).to have_content("What type of session is this?")
132+
133+
choose "Community clinic"
134+
click_on "Continue"
141135
end
142136

143-
def when_i_choose_the_dates
137+
def and_i_choose_the_programmes
138+
expect(page).to have_content(
139+
"Which programmes will you run in this session?"
140+
)
141+
142+
check "HPV"
143+
click_on "Continue"
144+
end
145+
146+
def and_i_choose_the_dates
147+
expect(page).to have_content("When will this session be held?")
148+
144149
fill_in "Day", with: "10"
145150
fill_in "Month", with: "03"
146151
fill_in "Year", with: "2024"
@@ -173,7 +178,7 @@ def when_i_choose_the_dates
173178
end
174179

175180
def then_i_see_the_confirmation_page
176-
expect(page).to have_content("Edit session")
181+
expect(page).to have_content("Check and confirm")
177182
expect(page).to have_content("InvitationsSend on Sunday, 18 February 2024")
178183
end
179184

@@ -192,8 +197,8 @@ def and_i_change_invitations_date
192197
click_on "Continue"
193198
end
194199

195-
def when_i_save_changes
196-
click_on "Save changes"
200+
def when_i_save_the_session
201+
click_on "Continue"
197202
end
198203

199204
def then_i_should_see_the_session_details
@@ -210,7 +215,7 @@ def when_the_patient_has_been_invited
210215
:clinic_notification,
211216
:initial_invitation,
212217
patient: @patient,
213-
session: @session
218+
session: Session.last
214219
)
215220
end
216221

spec/features/manage_school_sessions_spec.rb renamed to spec/features/sessions_school_spec.rb

Lines changed: 57 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,21 @@
11
# frozen_string_literal: true
22

3-
describe "Manage school sessions" do
3+
describe "School sessions" do
44
around { |example| travel_to(Time.zone.local(2024, 2, 18)) { example.run } }
55

6-
scenario "Adding a new session, closing consent, and closing the session" do
6+
before { Flipper.enable(:schools_and_sessions) }
7+
8+
scenario "adding a new session, closing consent, and closing the session" do
79
given_my_team_is_running_an_hpv_vaccination_programme
810
and_i_am_signed_in
911

1012
when_i_go_to_todays_sessions_as_a_nurse
1113
then_i_see_no_sessions
1214

13-
when_i_go_to_unscheduled_sessions
14-
then_i_see_the_school
15-
16-
when_i_seach_for_the_school
17-
then_i_see_the_school
18-
19-
when_i_click_on_the_school
20-
then_i_see_the_school_session
21-
and_i_see_a_child_in_the_cohort
22-
23-
when_i_click_on_schedule_sessions
15+
when_i_click_on_add_a_new_session
16+
and_i_choose_the_school
17+
and_i_choose_the_programmes
18+
and_i_choose_the_year_groups
2419
then_i_see_the_dates_page
2520

2621
when_i_add_an_invalid_date
@@ -42,14 +37,15 @@
4237
then_i_see_the_change_consent_reminders_page
4338
and_i_change_consent_reminders_weeks
4439

45-
when_i_save_changes
40+
when_i_save_the_session
4641
then_i_should_see_the_session_details
4742

4843
when_i_go_to_todays_sessions_as_a_nurse
4944
then_i_see_no_sessions
5045

5146
when_i_go_to_scheduled_sessions
5247
then_i_see_the_school
48+
and_i_see_a_child_in_the_cohort
5349

5450
when_i_go_to_completed_sessions
5551
then_i_see_no_sessions
@@ -90,19 +86,11 @@ def given_my_team_is_running_an_hpv_vaccination_programme
9086
programmes: [@programme, @other_programme]
9187
)
9288
@location = create(:school, :secondary, team: @team)
93-
@session =
94-
create(
95-
:session,
96-
:unscheduled,
97-
location: @location,
98-
team: @team,
99-
programmes: [@programme]
100-
)
10189

10290
@parent = create(:parent)
10391

10492
@patient =
105-
create(:patient, year_group: 8, session: @session, parents: [@parent])
93+
create(:patient, year_group: 8, location: @location, parents: [@parent])
10694

10795
clinic_session =
10896
create(
@@ -114,15 +102,15 @@ def given_my_team_is_running_an_hpv_vaccination_programme
114102
)
115103

116104
patient_already_in_clinic_without_invitiation =
117-
create(:patient, year_group: 8, session: @session)
105+
create(:patient, year_group: 8, location: @location)
118106
create(
119107
:patient_location,
120108
patient: patient_already_in_clinic_without_invitiation,
121109
session: clinic_session
122110
)
123111

124112
patient_already_in_clinic_with_invitiation =
125-
create(:patient, year_group: 8, session: @session)
113+
create(:patient, year_group: 8, location: @location)
126114
create(
127115
:patient_location,
128116
patient: patient_already_in_clinic_with_invitiation,
@@ -154,7 +142,7 @@ def when_i_go_to_unscheduled_sessions
154142
click_on "Update results"
155143
end
156144

157-
def when_i_seach_for_the_school
145+
def when_i_search_for_the_school
158146
fill_in "Search", with: @location.name
159147
click_on "Update results"
160148
end
@@ -189,16 +177,48 @@ def and_i_see_a_child_in_the_cohort
189177
expect(page).to have_content("3 children")
190178
end
191179

192-
def when_i_click_on_schedule_sessions
193-
click_on "Edit session"
194-
click_on "Add session dates"
195-
end
196-
197180
def and_i_click_on_edit_dates
198181
click_on "Edit session"
199182
click_on "Change session dates"
200183
end
201184

185+
def when_i_click_on_add_a_new_session
186+
click_on "Add a new session"
187+
end
188+
189+
def and_i_choose_the_school
190+
expect(page).to have_content("What type of session is this?")
191+
192+
choose "School"
193+
click_on "Continue"
194+
195+
expect(page).to have_content("Where is this school session taking place?")
196+
197+
select @location.name
198+
click_on "Continue"
199+
end
200+
201+
def and_i_choose_the_programmes
202+
expect(page).to have_content(
203+
"Which programmes will you run in this session?"
204+
)
205+
206+
check "HPV"
207+
click_on "Continue"
208+
end
209+
210+
def and_i_choose_the_year_groups
211+
expect(page).to have_content(
212+
"Which year groups do you want to invite to this session?"
213+
)
214+
215+
check "Year 8"
216+
check "Year 9"
217+
check "Year 10"
218+
check "Year 11"
219+
click_on "Continue"
220+
end
221+
202222
def then_i_see_the_dates_page_but_cannot_change
203223
expect(page).to have_content(
204224
"Children have attended this session. It cannot be changed."
@@ -256,7 +276,7 @@ def when_i_choose_the_dates
256276
end
257277

258278
def then_i_see_the_confirmation_page
259-
expect(page).to have_content("Edit session")
279+
expect(page).to have_content("Check and confirm")
260280
end
261281

262282
def when_i_click_on_change_programmes
@@ -310,8 +330,8 @@ def and_i_change_consent_reminders_weeks
310330
click_on "Continue"
311331
end
312332

313-
def when_i_save_changes
314-
click_on "Save changes"
333+
def when_i_save_the_session
334+
click_on "Continue"
315335
end
316336

317337
def then_i_should_see_the_session_details
@@ -320,7 +340,7 @@ def then_i_should_see_the_session_details
320340
end
321341

322342
def when_the_parent_visits_the_consent_form
323-
visit start_parent_interface_consent_forms_path(@session, @programme)
343+
visit start_parent_interface_consent_forms_path(Session.last, @programme)
324344
end
325345

326346
def then_they_can_give_consent
@@ -336,12 +356,12 @@ def and_patients_have_been_seen
336356
:attendance_record,
337357
:present,
338358
patient: @patient,
339-
session: @session.reload
359+
session: Session.last
340360
)
341361
end
342362

343363
def then_they_can_no_longer_give_consent
344-
visit start_parent_interface_consent_forms_path(@session, @programme)
364+
visit start_parent_interface_consent_forms_path(Session.last, @programme)
345365
expect(page).to have_content("The deadline for responding has passed")
346366
end
347367

0 commit comments

Comments
 (0)