Skip to content

Commit f37dff5

Browse files
refactoring to reduce duplicate code
1 parent 70de74f commit f37dff5

File tree

1 file changed

+53
-86
lines changed

1 file changed

+53
-86
lines changed

tests/regression/regression_tests/fobt_regression_tests/test_scenario_3.py

Lines changed: 53 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -298,49 +298,7 @@ def test_scenario_3(page: Page) -> None:
298298
"A25 - 1st Colonoscopy Assessment Appointment Booked, letter sent",
299299
)
300300

301-
# When I view the subject
302-
screening_subject_page_searcher.navigate_to_subject_summary_page(page, nhs_no)
303-
304-
# And I view the event history for the subject's latest episode
305-
SubjectScreeningSummaryPage(page).expand_episodes_list()
306-
SubjectScreeningSummaryPage(page).click_first_fobt_episode_link()
307-
308-
# And I view the latest practitioner appointment in the subject's episode
309-
EpisodeEventsAndNotesPage(page).click_view_appointment_link()
310-
311-
# And The subject cancels the practitioner appointment with reason "Patient Cancelled to Consider"
312-
AppointmentDetailPage(page).check_cancel_radio()
313-
AppointmentDetailPage(page).select_reason_for_cancellation_option(
314-
ReasonForCancellationOptions.PATIENT_CANCELLED_TO_CONSIDER
315-
)
316-
317-
# And I press OK on my confirmation prompt
318-
AppointmentDetailPage(page).click_save_button(accept_dialog=True)
319-
320-
# Then my subject has been updated as follows:
321-
criteria = {
322-
"latest event status": "J4 Appointment Cancellation (Patient to Consider)"
323-
}
324-
subject_assertion(nhs_no, criteria)
325-
326-
# And there is a "J4" letter batch for my subject with the exact title "Practitioner Clinic 1st Appt Cancelled (Patient To Consider)"
327-
# When I process the open "J4" letter batch for my subject
328-
batch_processing(
329-
page,
330-
"J4",
331-
"Practitioner Clinic 1st Appt Cancelled (Patient To Consider)",
332-
"J22 - Appointment Cancellation letter sent (Patient to Consider)",
333-
True,
334-
)
335-
336-
# Then there is a "J22" letter batch for my subject with the exact title "Subject Discharge (Refused Appointment)"
337-
# When I process the open "J22" letter batch for my subject
338-
batch_processing(
339-
page,
340-
"J22",
341-
"Subject Discharge (Refused Appointment)",
342-
"J8 - Patient discharge sent (refused colonoscopy assessment appointment)",
343-
)
301+
cancel_appointment_and_processes_batches(page, nhs_no)
344302

345303
# When I switch users to BCSS "England" as user role "Hub Manager"
346304
LogoutPage(page).log_out(close_page=False)
@@ -458,49 +416,7 @@ def test_scenario_3(page: Page) -> None:
458416
"A25 - 1st Colonoscopy Assessment Appointment Booked, letter sent",
459417
)
460418

461-
# When I view the subject
462-
screening_subject_page_searcher.navigate_to_subject_summary_page(page, nhs_no)
463-
464-
# And I view the event history for the subject's latest episode
465-
SubjectScreeningSummaryPage(page).expand_episodes_list()
466-
SubjectScreeningSummaryPage(page).click_first_fobt_episode_link()
467-
468-
# And I view the latest practitioner appointment in the subject's episode
469-
EpisodeEventsAndNotesPage(page).click_view_appointment_link()
470-
471-
# And The subject cancels the practitioner appointment with reason "Patient Cancelled to Consider"
472-
AppointmentDetailPage(page).check_cancel_radio()
473-
AppointmentDetailPage(page).select_reason_for_cancellation_option(
474-
ReasonForCancellationOptions.PATIENT_CANCELLED_TO_CONSIDER
475-
)
476-
477-
# And I press OK on my confirmation prompt
478-
AppointmentDetailPage(page).click_save_button(accept_dialog=True)
479-
480-
# Then my subject has been updated as follows:
481-
criteria = {
482-
"latest event status": "J4 Appointment Cancellation (Patient to Consider)"
483-
}
484-
subject_assertion(nhs_no, criteria)
485-
486-
# And there is a "J4" letter batch for my subject with the exact title "Practitioner Clinic 1st Appt Cancelled (Patient To Consider)"
487-
# When I process the open "J4" letter batch for my subject
488-
batch_processing(
489-
page,
490-
"J4",
491-
"Practitioner Clinic 1st Appt Cancelled (Patient To Consider)",
492-
"J22 - Appointment Cancellation letter sent (Patient to Consider)",
493-
True,
494-
)
495-
496-
# Then there is a "J22" letter batch for my subject with the exact title "Subject Discharge (Refused Appointment)"
497-
# When I process the open "J22" letter batch for my subject
498-
batch_processing(
499-
page,
500-
"J22",
501-
"Subject Discharge (Refused Appointment)",
502-
"J8 - Patient discharge sent (refused colonoscopy assessment appointment)",
503-
)
419+
cancel_appointment_and_processes_batches(page, nhs_no)
504420

505421
# When I switch users to BCSS "England" as user role "Hub Manager"
506422
LogoutPage(page).log_out(close_page=False)
@@ -550,3 +466,54 @@ def test_scenario_3(page: Page) -> None:
550466
subject_assertion(nhs_no, criteria, user_role)
551467

552468
LogoutPage(page).log_out()
469+
470+
471+
def cancel_appointment_and_processes_batches(page: Page, nhs_no: str) -> None:
472+
"""
473+
This function is used to reduce duplicate code in the test.
474+
It navigates to the subject summary page and cancels an appointment for the subject.
475+
Once the appointment is cancelled it processes the relevant batches
476+
"""
477+
# When I view the subject
478+
screening_subject_page_searcher.navigate_to_subject_summary_page(page, nhs_no)
479+
480+
# And I view the event history for the subject's latest episode
481+
SubjectScreeningSummaryPage(page).expand_episodes_list()
482+
SubjectScreeningSummaryPage(page).click_first_fobt_episode_link()
483+
484+
# And I view the latest practitioner appointment in the subject's episode
485+
EpisodeEventsAndNotesPage(page).click_view_appointment_link()
486+
487+
# And The subject cancels the practitioner appointment with reason "Patient Cancelled to Consider"
488+
AppointmentDetailPage(page).check_cancel_radio()
489+
AppointmentDetailPage(page).select_reason_for_cancellation_option(
490+
ReasonForCancellationOptions.PATIENT_CANCELLED_TO_CONSIDER
491+
)
492+
493+
# And I press OK on my confirmation prompt
494+
AppointmentDetailPage(page).click_save_button(accept_dialog=True)
495+
496+
# Then my subject has been updated as follows:
497+
criteria = {
498+
"latest event status": "J4 Appointment Cancellation (Patient to Consider)"
499+
}
500+
subject_assertion(nhs_no, criteria)
501+
502+
# And there is a "J4" letter batch for my subject with the exact title "Practitioner Clinic 1st Appt Cancelled (Patient To Consider)"
503+
# When I process the open "J4" letter batch for my subject
504+
batch_processing(
505+
page,
506+
"J4",
507+
"Practitioner Clinic 1st Appt Cancelled (Patient To Consider)",
508+
"J22 - Appointment Cancellation letter sent (Patient to Consider)",
509+
True,
510+
)
511+
512+
# Then there is a "J22" letter batch for my subject with the exact title "Subject Discharge (Refused Appointment)"
513+
# When I process the open "J22" letter batch for my subject
514+
batch_processing(
515+
page,
516+
"J22",
517+
"Subject Discharge (Refused Appointment)",
518+
"J8 - Patient discharge sent (refused colonoscopy assessment appointment)",
519+
)

0 commit comments

Comments
 (0)