Skip to content

Commit 364c0b8

Browse files
committed
Add feature spec for follow-up journey
Tests the nurse follo-up record flow end to end.
1 parent f95b900 commit 364c0b8

1 file changed

Lines changed: 306 additions & 0 deletions

File tree

Lines changed: 306 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,306 @@
1+
# frozen_string_literal: true
2+
3+
describe "Follow-up parent journey" do
4+
around { |example| travel_to(Date.new(2025, 7, 31)) { example.run } }
5+
6+
scenario "Nurse follows up and confirms the refusal" do
7+
given_an_hpv_programme_is_underway
8+
and_a_parent_has_submitted_consent_requesting_follow_up
9+
10+
when_i_navigate_to_the_patient_page
11+
then_i_see_the_follow_up_requested_status
12+
13+
when_i_click_through_to_the_consent
14+
then_i_see_the_follow_up_action
15+
16+
when_i_start_the_follow_up
17+
then_i_see_the_follow_up_page
18+
19+
when_i_try_continuing_without_selecting_a_radio
20+
then_i_see_an_error_message
21+
22+
when_i_confirm_the_decision_still_stands
23+
then_i_see_the_confirm_refusal_page
24+
25+
when_i_try_continuing_without_selecting_a_radio
26+
then_i_see_an_error_message
27+
28+
when_i_confirm_the_refusal_with_notes
29+
then_the_consent_is_updated_with_a_flash_message
30+
and_the_parent_receives_a_refusal_confirmation_email
31+
and_the_parent_receives_a_refusal_confirmation_text
32+
and_the_consent_is_marked_as_follow_up_confirmed
33+
34+
when_i_navigate_to_the_patient_page
35+
then_i_see_the_consent_refused_status
36+
37+
when_i_view_the_full_child_record_activity_log
38+
then_i_see_the_follow_up_requested_event_in_the_activity_log
39+
and_i_see_the_refusal_confirmed_follow_up_resolution_in_the_activity_log
40+
and_i_do_not_see_an_invalidated_consent_event_in_the_activity_log
41+
and_i_see_email_and_sms_notifications_in_the_activity_log("confirmed")
42+
end
43+
44+
scenario "Nurse follows up and records new consent (refusal withdrawn)" do
45+
given_an_hpv_programme_is_underway
46+
and_a_parent_has_submitted_consent_requesting_follow_up
47+
48+
when_i_navigate_to_the_patient_page
49+
then_i_see_the_follow_up_requested_status
50+
51+
when_i_click_through_to_the_consent
52+
when_i_start_the_follow_up
53+
54+
when_the_decision_no_longer_stands
55+
then_i_am_taken_to_the_agree_step
56+
57+
when_i_record_consent_given
58+
then_the_consent_is_recorded_with_a_flash_message
59+
and_the_parent_receives_a_consent_given_email
60+
and_the_parent_receives_a_consent_given_text
61+
and_the_new_consent_is_recorded_as_given
62+
and_the_original_consent_is_resolved_as_withdrawn
63+
64+
when_i_navigate_to_the_patient_page
65+
then_i_see_the_consent_given_status
66+
67+
when_i_view_the_full_child_record_activity_log
68+
then_i_see_the_follow_up_requested_event_in_the_activity_log
69+
and_i_see_the_refusal_withdrawn_follow_up_resolution_in_the_activity_log
70+
and_i_do_not_see_an_invalidated_consent_event_in_the_activity_log
71+
and_i_see_the_new_consent_given_event_in_the_activity_log
72+
and_i_see_email_and_sms_notifications_in_the_activity_log("withdrawn")
73+
end
74+
75+
def given_an_hpv_programme_is_underway
76+
@programme = Programme.hpv
77+
@team = create(:team, :with_one_nurse, programmes: [@programme])
78+
location = create(:school, name: "Pilot School", team: @team)
79+
@session =
80+
create(
81+
:session,
82+
:scheduled,
83+
team: @team,
84+
programmes: [@programme],
85+
location:
86+
)
87+
@patient = create(:patient, session: @session)
88+
end
89+
90+
def and_a_parent_has_submitted_consent_requesting_follow_up
91+
@parent =
92+
create(
93+
:parent,
94+
email: "jane@example.com",
95+
phone: "07123456789",
96+
phone_receive_updates: true
97+
)
98+
create(:parent_relationship, :mother, parent: @parent, patient: @patient)
99+
@consent =
100+
create(
101+
:consent,
102+
:follow_up_requested,
103+
patient: @patient,
104+
programme: @programme,
105+
team: @team,
106+
parent: @parent,
107+
route: "website",
108+
submitted_at: Date.new(2025, 7, 1)
109+
)
110+
PatientStatusUpdater.call(patient: @patient)
111+
end
112+
113+
def when_i_navigate_to_the_patient_page
114+
sign_in @team.users.first
115+
visit session_patients_path(@session)
116+
click_link @patient.full_name
117+
end
118+
119+
def then_i_see_the_follow_up_requested_status
120+
expect(page).to have_content("Follow-up requested")
121+
expect(page).to have_content(
122+
"would like to speak to a member of the team about other options"
123+
)
124+
end
125+
126+
def when_i_click_through_to_the_consent
127+
click_link @parent.full_name
128+
end
129+
130+
def then_i_see_the_follow_up_action
131+
expect(page).to have_link("Follow up")
132+
end
133+
134+
def when_i_start_the_follow_up
135+
click_link "Follow up"
136+
end
137+
138+
def then_i_see_the_follow_up_page
139+
expect(page).to have_content("Follow up refusal")
140+
expect(page).to have_content("Does their original decision still stand?")
141+
end
142+
143+
def when_i_confirm_the_decision_still_stands
144+
within_fieldset "Does their original decision still stand?" do
145+
choose "Yes"
146+
end
147+
click_button "Continue"
148+
end
149+
150+
def then_i_see_the_confirm_refusal_page
151+
expect(page).to have_content("Update consent response")
152+
expect(page).to have_content("Confirm consent refusal?")
153+
end
154+
155+
def when_i_try_continuing_without_selecting_a_radio
156+
if page.has_button?("Continue")
157+
click_button "Continue"
158+
else
159+
click_button "Save changes"
160+
end
161+
end
162+
163+
def then_i_see_an_error_message
164+
expect(page).to have_content("Select yes or no")
165+
end
166+
167+
def when_i_confirm_the_refusal_with_notes
168+
fill_in "Notes", with: "Parent has considered and still refuses."
169+
within_fieldset "Confirm consent refusal?" do
170+
choose "Yes"
171+
end
172+
click_button "Save changes"
173+
end
174+
175+
def then_the_consent_is_updated_with_a_flash_message
176+
expect(page).to have_content("Consent from #{@parent.full_name} updated.")
177+
end
178+
179+
def and_the_parent_receives_a_refusal_confirmation_email
180+
expect_email_to @parent.email, :consent_confirmation_refused
181+
end
182+
183+
def and_the_parent_receives_a_refusal_confirmation_text
184+
expect_sms_to @parent.phone, :consent_confirmation_refused
185+
end
186+
187+
def and_the_consent_is_marked_as_follow_up_confirmed
188+
expect(@consent.reload).to have_attributes(
189+
follow_up_requested: false,
190+
follow_up_outcome: "confirmed",
191+
follow_up_resolved_at: be_present
192+
)
193+
end
194+
195+
def then_i_see_the_consent_refused_status
196+
expect(page).to have_content("Consent refused")
197+
expect(page).to have_content("refused to give consent")
198+
end
199+
200+
def when_the_decision_no_longer_stands
201+
choose "No"
202+
click_button "Continue"
203+
end
204+
205+
def then_i_am_taken_to_the_agree_step
206+
expect(page).to have_content(
207+
"Do they agree to them having the HPV vaccination?"
208+
)
209+
end
210+
211+
def when_i_record_consent_given
212+
choose "Yes, they agree"
213+
click_button "Continue"
214+
215+
# Health questions — answer "No" to all
216+
all("label", text: "No").each(&:click)
217+
click_button "Continue"
218+
219+
expect(page).to have_content("Check and confirm answers")
220+
click_button "Confirm"
221+
end
222+
223+
def then_the_consent_is_recorded_with_a_flash_message
224+
expect(page).to have_content("Consent recorded for #{@patient.full_name}")
225+
end
226+
227+
def and_the_parent_receives_a_consent_given_email
228+
expect_email_to @parent.email, :consent_confirmation_given
229+
end
230+
231+
def and_the_parent_receives_a_consent_given_text
232+
expect_sms_to @parent.phone, :consent_confirmation_given
233+
end
234+
235+
def and_the_new_consent_is_recorded_as_given
236+
new_consent = @patient.reload.consents.not_invalidated.first
237+
expect(new_consent).to have_attributes(response: "given")
238+
end
239+
240+
def and_the_original_consent_is_resolved_as_withdrawn
241+
expect(@consent.reload).to have_attributes(
242+
follow_up_outcome: "withdrawn",
243+
follow_up_resolved_at: be_present,
244+
invalidated_at: be_present
245+
)
246+
end
247+
248+
def then_i_see_the_consent_given_status
249+
expect(page).to have_content("Consent given")
250+
expect(page).to have_content("is ready for the vaccinator")
251+
end
252+
253+
def when_i_view_the_full_child_record_activity_log
254+
click_link "View full child record"
255+
click_link @programme.name, match: :first
256+
end
257+
258+
def then_i_see_the_follow_up_requested_event_in_the_activity_log
259+
within(".app-card", text: "Programme activity") do
260+
expect(page).to have_content(
261+
"Follow-up requested by #{@parent.full_name} (mum)"
262+
)
263+
end
264+
end
265+
266+
def and_i_see_the_refusal_confirmed_follow_up_resolution_in_the_activity_log
267+
within(".app-card", text: "Programme activity") do
268+
expect(page).to have_content(
269+
"Consent response from #{@parent.full_name} (mum) followed-up: refusal confirmed"
270+
)
271+
end
272+
end
273+
274+
def and_i_see_the_refusal_withdrawn_follow_up_resolution_in_the_activity_log
275+
within(".app-card", text: "Programme activity") do
276+
expect(page).to have_content(
277+
"Consent response from #{@parent.full_name} (mum) followed-up: refusal withdrawn"
278+
)
279+
end
280+
end
281+
282+
def and_i_do_not_see_an_invalidated_consent_event_in_the_activity_log
283+
within(".app-card", text: "Programme activity") do
284+
expect(page).not_to have_content(
285+
"Consent from #{@parent.full_name} invalidated"
286+
)
287+
end
288+
end
289+
290+
def and_i_see_the_new_consent_given_event_in_the_activity_log
291+
within(".app-card", text: "Programme activity") do
292+
expect(page).to have_content(
293+
"Consent given by #{@parent.full_name} (mum)"
294+
)
295+
end
296+
end
297+
298+
def and_i_see_email_and_sms_notifications_in_the_activity_log(
299+
follow_up_outcome
300+
)
301+
outcome = follow_up_outcome == "confirmed" ? "refused" : "given"
302+
within(".app-card", text: "Programme activity") do
303+
expect(page).to have_content("Consent confirmation #{outcome} sent")
304+
end
305+
end
306+
end

0 commit comments

Comments
 (0)