|
| 1 | +import re |
| 2 | + |
| 3 | +import pytest |
| 4 | +from django.urls import reverse |
| 5 | +from playwright.sync_api import expect |
| 6 | + |
| 7 | +from manage_breast_screening.core.system_test_setup import SystemTestCase |
| 8 | +from manage_breast_screening.participants.tests.factories import ( |
| 9 | + AppointmentFactory, |
| 10 | + ParticipantFactory, |
| 11 | + ScreeningEpisodeFactory, |
| 12 | +) |
| 13 | + |
| 14 | + |
| 15 | +class TestAddingPreviousMammograms(SystemTestCase): |
| 16 | + @pytest.fixture(autouse=True) |
| 17 | + def before(self): |
| 18 | + self.participant = ParticipantFactory(first_name="Janet", last_name="Williams") |
| 19 | + self.screening_episode = ScreeningEpisodeFactory(participant=self.participant) |
| 20 | + self.appointment = AppointmentFactory(screening_episode=self.screening_episode) |
| 21 | + self.provider = self.appointment.provider |
| 22 | + |
| 23 | + def test_adding_a_mammogram_at_the_same_provider(self): |
| 24 | + """ |
| 25 | + If a mammogram was taken at the same provider, but there is an error in the system, the participant can report that it was taken. |
| 26 | + """ |
| 27 | + self.given_i_am_on_the_start_screening_page() |
| 28 | + self.then_i_should_see_no_reported_mammograms() |
| 29 | + |
| 30 | + self.when_i_click_on_add_mammogram() |
| 31 | + self.then_i_should_be_on_the_add_previous_mammogram_form() |
| 32 | + |
| 33 | + self.when_i_select_the_same_provider() |
| 34 | + self.and_i_enter_an_exact_date() |
| 35 | + self.and_i_select_yes_same_name() |
| 36 | + self.and_i_enter_additional_information() |
| 37 | + self.and_i_click_continue() |
| 38 | + self.then_i_should_be_back_on_the_appointment() |
| 39 | + self.and_i_should_see_the_mammogram_with_the_same_provider() |
| 40 | + |
| 41 | + def test_adding_a_mammogram_taken_elsewhere_with_a_different_name(self): |
| 42 | + """ |
| 43 | + If a mammogram was taken at another BSU, or elsewhere in the UK, the participant can report that it was taken |
| 44 | + If the mammogram was taken under a different name, the mammographer can record that name. |
| 45 | + """ |
| 46 | + self.given_i_am_on_the_start_screening_page() |
| 47 | + self.then_i_should_see_no_reported_mammograms() |
| 48 | + |
| 49 | + self.when_i_click_on_add_mammogram() |
| 50 | + self.then_i_should_be_on_the_add_previous_mammogram_form() |
| 51 | + |
| 52 | + self.when_i_enter_another_location_in_the_uk() |
| 53 | + self.and_i_enter_an_approximate_date() |
| 54 | + self.and_i_enter_a_different_name() |
| 55 | + self.and_i_enter_additional_information() |
| 56 | + self.and_i_click_continue() |
| 57 | + self.then_i_should_be_back_on_the_appointment() |
| 58 | + self.and_i_should_see_the_mammogram_with_the_other_provider_and_name() |
| 59 | + |
| 60 | + def test_accessibility(self): |
| 61 | + self.given_i_am_on_the_add_previous_mammograms_page() |
| 62 | + self.then_the_accessibility_baseline_is_met() |
| 63 | + |
| 64 | + def given_i_am_on_the_start_screening_page(self): |
| 65 | + self.page.goto( |
| 66 | + self.live_server_url |
| 67 | + + reverse( |
| 68 | + "mammograms:start_screening", |
| 69 | + kwargs={"pk": self.appointment.pk}, |
| 70 | + ) |
| 71 | + ) |
| 72 | + |
| 73 | + def given_i_am_on_the_add_previous_mammograms_page(self): |
| 74 | + self.page.goto( |
| 75 | + self.live_server_url |
| 76 | + + reverse( |
| 77 | + "participants:add_previous_mammogram", |
| 78 | + kwargs={"pk": self.participant.pk}, |
| 79 | + ) |
| 80 | + ) |
| 81 | + |
| 82 | + def then_i_should_see_no_reported_mammograms(self): |
| 83 | + expect(self.page.get_by_test_id("mammograms")).to_contain_text("Not known") |
| 84 | + |
| 85 | + def when_i_click_on_add_mammogram(self): |
| 86 | + self.page.get_by_text("Add mammogram").click() |
| 87 | + |
| 88 | + def then_i_should_be_on_the_add_previous_mammogram_form(self): |
| 89 | + path = reverse( |
| 90 | + "participants:add_previous_mammogram", |
| 91 | + kwargs={"pk": self.participant.pk}, |
| 92 | + ) |
| 93 | + expect(self.page).to_have_url(re.compile(path)) |
| 94 | + |
| 95 | + def then_i_should_be_back_on_the_appointment(self): |
| 96 | + path = reverse( |
| 97 | + "mammograms:start_screening", |
| 98 | + kwargs={"pk": self.appointment.pk}, |
| 99 | + ) |
| 100 | + expect(self.page).to_have_url(re.compile(path)) |
| 101 | + |
| 102 | + def when_i_select_the_same_provider(self): |
| 103 | + option = f"At {self.provider.name}" |
| 104 | + self.page.get_by_label(option).click() |
| 105 | + |
| 106 | + def and_i_enter_an_exact_date(self): |
| 107 | + self.page.get_by_label("Enter an exact date").click() |
| 108 | + self.page.get_by_label("Day").fill("1") |
| 109 | + self.page.get_by_label("Month").fill("12") |
| 110 | + self.page.get_by_label("Year").fill("2023") |
| 111 | + |
| 112 | + def and_i_select_yes_same_name(self): |
| 113 | + self.page.get_by_label("Yes").click() |
| 114 | + |
| 115 | + def and_i_enter_additional_information(self): |
| 116 | + self.page.get_by_label("Additional information (optional)").fill("RR") |
| 117 | + |
| 118 | + def and_i_click_continue(self): |
| 119 | + self.page.get_by_text("Continue").click() |
| 120 | + |
| 121 | + def and_i_should_see_the_mammogram_with_the_same_provider(self): |
| 122 | + expected_inner_text = re.compile( |
| 123 | + rf"Added today\n1 December 2023 \(.* ago\)\n{self.provider.name}\nAdditional information: RR" |
| 124 | + ) |
| 125 | + expect(self.page.get_by_test_id("mammograms")).to_contain_text( |
| 126 | + expected_inner_text, |
| 127 | + use_inner_text=True, |
| 128 | + ) |
| 129 | + |
| 130 | + def when_i_enter_another_location_in_the_uk(self): |
| 131 | + self.page.get_by_label("Somewhere in the UK").click() |
| 132 | + self.page.get_by_label("Location").first.fill("other place") |
| 133 | + |
| 134 | + def and_i_enter_an_approximate_date(self): |
| 135 | + self.page.get_by_label("Enter an approximate date").and_( |
| 136 | + self.page.get_by_role("radio") |
| 137 | + ).click() |
| 138 | + self.page.get_by_label("Enter an approximate date").and_( |
| 139 | + self.page.get_by_role("textbox") |
| 140 | + ).fill("a year ago") |
| 141 | + |
| 142 | + def and_i_enter_a_different_name(self): |
| 143 | + self.page.get_by_label("No, under a different name").click() |
| 144 | + self.page.get_by_label("Enter the previously used name").fill("Taylor Swift") |
| 145 | + |
| 146 | + def and_i_should_see_the_mammogram_with_the_other_provider_and_name(self): |
| 147 | + expected_inner_text = re.compile( |
| 148 | + r"Added today\nApproximate date: a year ago\nIn the UK: other place\nPrevious name: Taylor Swift\nAdditional information: RR" |
| 149 | + ) |
| 150 | + expect(self.page.get_by_test_id("mammograms")).to_contain_text( |
| 151 | + expected_inner_text, |
| 152 | + use_inner_text=True, |
| 153 | + ) |
0 commit comments