Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions mavis/test/pages/children.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,6 @@ def click_invite_to_community_clinic(self) -> None:
def click_edit_child_record(self) -> None:
self.edit_child_record_button.click()

def expect_text_in_alert(self, text: str) -> None:
expect(self.page.get_by_role("alert")).to_contain_text(text)

@step("Click on Archive child record")
def click_archive_child_record(self) -> None:
self.archive_child_record_link.click()
Expand Down
7 changes: 2 additions & 5 deletions mavis/test/pages/nurse_consent.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Parent,
Programme,
)
from mavis.test.utils import generate_random_string
from mavis.test.utils import expect_alert_text, generate_random_string


class NurseConsentWizardPage:
Expand Down Expand Up @@ -168,9 +168,6 @@ def click_yes_for_nasal_spray(self) -> None:
def click_yes_for_injected_vaccine(self) -> None:
self.online_flu_agree_injection_radio.check()

def expect_text_in_alert(self, text: str) -> None:
expect(self.page.get_by_role("alert")).to_contain_text(text)

def record_parent_positive_consent(
self,
programme: Programme = Programme.HPV,
Expand Down Expand Up @@ -274,7 +271,7 @@ def _process_consent_confirmation(
def update_triage_outcome_positive(self) -> None:
self.click_safe_to_vaccinate()
self.click_save_triage()
self.expect_text_in_alert("Triage outcome updated")
expect_alert_text(self.page, "Triage outcome updated")

def click_withdraw_consent(self) -> None:
self.withdraw_consent_button.click()
Expand Down
5 changes: 1 addition & 4 deletions mavis/test/pages/programmes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from io import StringIO

import pandas as pd
from playwright.sync_api import Page, expect
from playwright.sync_api import Page

from mavis.test.annotations import step
from mavis.test.data import TestData
Expand Down Expand Up @@ -221,6 +221,3 @@ def click_use_duplicate(self) -> None:
@step("Click on Resolve duplicate")
def click_resolve_duplicate(self) -> None:
self.resolve_duplicate_button.click()

def expect_alert_text(self, text: str) -> None:
expect(self.page.get_by_role("alert")).to_contain_text(text)
76 changes: 22 additions & 54 deletions mavis/test/pages/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
)
from mavis.test.utils import (
MAVIS_NOTE_LENGTH_LIMIT,
expect_alert_text,
expect_details,
get_current_datetime_compact,
get_day_month_year_from_compact_date,
get_offset_date,
Expand Down Expand Up @@ -431,24 +433,26 @@ def create_invalid_session(self) -> None:
self.add_or_change_session_dates()
self.fill_date_fields(_invalid_date)
self.click_continue_button()
self.expect_alert_text("Enter a date")
expect_alert_text(self.page, "Enter a date")
self.click_back()

def create_session_in_previous_academic_year(self) -> None:
_previous_year_date = get_offset_date_compact_format(offset_days=-365)
self.add_or_change_session_dates()
self.fill_date_fields(_previous_year_date)
self.click_continue_button()
self.expect_alert_text("Enter a date on or after the start of the school year")
expect_alert_text(
self.page, "Enter a date on or after the start of the school year"
)
self.click_back()

def create_session_in_next_academic_year(self) -> None:
_next_year_date = get_offset_date_compact_format(offset_days=365)
self.add_or_change_session_dates()
self.fill_date_fields(_next_year_date)
self.click_continue_button()
self.expect_alert_text(
"Enter a date on or before the end of the current school year"
expect_alert_text(
self.page, "Enter a date on or before the end of the current school year"
)
self.click_back()

Expand Down Expand Up @@ -536,7 +540,8 @@ def schedule_a_valid_session(
if self.keep_session_dates_button.is_visible():
self.click_keep_session_dates() # MAV-2066

self.expect_details(
expect_details(
self.page,
"Session dates",
self._get_day_month_year_with_day_of_week(date_to_format=_future_date),
)
Expand All @@ -562,7 +567,8 @@ def schedule_a_valid_mmr_session(
if self.keep_session_dates_button.is_visible():
self.click_keep_session_dates() # MAV-2066

self.expect_details(
expect_details(
self.page,
"Session dates",
self._get_day_month_year_with_day_of_week(date_to_format=_future_date),
)
Expand All @@ -582,18 +588,6 @@ def answer_whether_psd_should_be_enabled(self, answer: str) -> None:
),
).get_by_label(answer).check()

def expect_alert_text(self, text: str) -> None:
expect(self.page.get_by_role("alert")).to_contain_text(text)

def expect_details(self, key: str, value: str) -> None:
detail_key = self.page.locator(
".nhsuk-summary-list__key",
has_text=re.compile(f"^{key}$"),
).first
detail_value = detail_key.locator("xpath=following-sibling::*[1]")

expect(detail_value).to_contain_text(value)


class SessionsChildrenPage(SearchBarMixin, SessionsTabsMixin):
def __init__(self, page: Page) -> None:
Expand Down Expand Up @@ -860,11 +854,11 @@ def invalidate_parent_refusal(self, parent: Parent) -> None:
self.click_mark_as_invalid_link()
self.fill_notes(invalidation_notes)
self.click_mark_as_invalid_button()
self.expect_details("Response", "Invalid")
self.expect_details("Notes", invalidation_notes)
expect_details(self.page, "Response", "Invalid")
expect_details(self.page, "Notes", invalidation_notes)

self.click_back()
self.expect_details("Response", "Invalid")
expect_details(self.page, "Response", "Invalid")
expect(self.page.get_by_text("No requests have been sent.")).to_be_visible()

@step("Click Back")
Expand All @@ -879,15 +873,6 @@ def click_continue_button(self) -> None:
def fill_notes(self, notes: str) -> None:
self.notes_textbox.fill(notes)

def expect_details(self, key: str, value: str) -> None:
detail_key = self.page.locator(
".nhsuk-summary-list__key",
has_text=re.compile(f"^{key}$"),
).first
detail_value = detail_key.locator("xpath=following-sibling::*[1]")

expect(detail_value).to_contain_text(value)

@step("Click on Yes")
def select_identity_confirmed_by_child(self, child: Child) -> None:
self.page.get_by_role(
Expand Down Expand Up @@ -967,10 +952,7 @@ def go_back_to_session_for_school(self, school: School) -> None:
expect(self.page.get_by_role("heading", name=school.name).first).to_be_visible()

def verify_triage_updated_for_child(self) -> None:
self.expect_alert_text("Triage outcome updated")

def expect_alert_text(self, text: str) -> None:
expect(self.page.get_by_role("alert")).to_contain_text(text)
expect_alert_text(self.page, "Triage outcome updated")

@step("Triage MMR patient")
def triage_mmr_patient(self, consent_option: ConsentOption) -> None:
Expand Down Expand Up @@ -1037,15 +1019,12 @@ def add_note(self, note: str) -> None:
with self.page.expect_navigation():
self.click_save_note()

self.expect_alert_text("Note added")
expect_alert_text(self.page, "Note added")
reload_until_element_is_visible(self.page, self.page.get_by_text(note))

def check_session_activity_entry(self, text: str) -> None:
expect(self.page.get_by_role("heading", name=text).first).to_be_visible()

def expect_alert_text(self, text: str) -> None:
expect(self.page.get_by_role("alert")).to_contain_text(text)


class SessionsVaccinationWizardPage:
def __init__(self, page: Page) -> None:
Expand Down Expand Up @@ -1082,18 +1061,6 @@ def choose_batch(self, batch_name: str) -> None:
self.page.get_by_role("radio", name=batch_name).check()
self.click_continue_button()

def expect_details(self, key: str, value: str) -> None:
detail_key = self.page.locator(
".nhsuk-summary-list__key",
has_text=re.compile(f"^{key}$"),
).first
detail_value = detail_key.locator("xpath=following-sibling::*[1]")

expect(detail_value).to_contain_text(value)

def expect_alert_text(self, text: str) -> None:
expect(self.page.get_by_role("alert")).to_contain_text(text)

def record_vaccination(
self,
vaccination_record: VaccinationRecord,
Expand All @@ -1106,9 +1073,9 @@ def record_vaccination(

if at_school: # only skips MAV-854
if psd_option:
self.expect_details("Protocol", "Patient Specific Direction")
expect_details(self.page, "Protocol", "Patient Specific Direction")
else:
self.expect_details("Protocol", "Patient Group Direction (PGD)")
expect_details(self.page, "Protocol", "Patient Group Direction (PGD)")

self.vaccination_notes.fill(notes)
self.click_confirm_button()
Expand All @@ -1118,6 +1085,7 @@ def record_vaccination(
self.vaccination_notes.fill("Confirmation notes")
self.click_confirm_button()

self.expect_alert_text(
f"Vaccination outcome recorded for {vaccination_record.programme}"
expect_alert_text(
self.page,
f"Vaccination outcome recorded for {vaccination_record.programme}",
)
14 changes: 14 additions & 0 deletions mavis/test/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,17 @@ def reload_until_element_is_not_visible(
page.reload()
else:
expect(tag).to_be_hidden()


def expect_alert_text(page: Page, text: str) -> None:
expect(page.get_by_role("alert")).to_contain_text(text)


def expect_details(page: Page, key: str, value: str) -> None:
detail_key = page.locator(
".nhsuk-summary-list__key",
has_text=re.compile(f"^{key}$"),
).first
detail_value = detail_key.locator("xpath=following-sibling::*[1]")

expect(detail_value).to_contain_text(value)
6 changes: 3 additions & 3 deletions tests/test_children.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from mavis.test.annotations import issue
from mavis.test.data import ClassFileMapping, CohortsFileMapping, VaccsFileMapping
from mavis.test.models import Programme
from mavis.test.utils import get_offset_date
from mavis.test.utils import expect_alert_text, get_offset_date

pytestmark = pytest.mark.children

Expand Down Expand Up @@ -169,7 +169,7 @@ def test_invalid_nhs_number_change_is_rejected(
child_edit_page.click_change_nhs_no()
child_edit_page.fill_nhs_no_for_child(child, "9123456789")
child_edit_page.click_continue()
child_record_page.expect_text_in_alert("Enter a valid NHS number")
expect_alert_text(child_record_page.page, "Enter a valid NHS number")


@issue("MAV-1839")
Expand Down Expand Up @@ -200,7 +200,7 @@ def test_merge_child_records_does_not_crash(
child_record_page.click_archive_child_record()
child_archive_page.click_its_a_duplicate(child2.nhs_number)
child_archive_page.click_archive_record()
child_record_page.expect_text_in_alert("This record has been archived")
expect_alert_text(child_record_page.page, "This record has been archived")


@pytest.mark.accessibility
Expand Down
4 changes: 2 additions & 2 deletions tests/test_nurse_consent.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from mavis.test.annotations import issue
from mavis.test.data import CohortsFileMapping
from mavis.test.models import ConsentMethod, DeliverySite, Programme, Vaccine
from mavis.test.utils import MAVIS_NOTE_LENGTH_LIMIT, get_offset_date
from mavis.test.utils import MAVIS_NOTE_LENGTH_LIMIT, expect_alert_text, get_offset_date

pytestmark = pytest.mark.consent

Expand Down Expand Up @@ -328,7 +328,7 @@ def test_conflicting_consent_with_gillick_consent(

nurse_consent_wizard_page.select_gillick_competent_child()
nurse_consent_wizard_page.record_child_positive_consent()
nurse_consent_wizard_page.expect_text_in_alert(f"Consent recorded for {child!s}")
expect_alert_text(nurse_consent_wizard_page.page, f"Consent recorded for {child!s}")

sessions_consent_page.select_consent_given_filters_for_programme(Programme.HPV)
sessions_consent_page.search_and_click_child(child)
Expand Down
5 changes: 4 additions & 1 deletion tests/test_programmes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from mavis.test.annotations import issue
from mavis.test.data import CohortsFileMapping
from mavis.test.models import Programme, ReportFormat
from mavis.test.utils import expect_alert_text


@pytest.fixture
Expand Down Expand Up @@ -174,7 +175,9 @@ def test_edit_vaccination_dose_to_not_given(
edit_vaccination_record_page.click_they_refused_it()
edit_vaccination_record_page.click_continue()
edit_vaccination_record_page.click_save_changes()
programme_children_page.expect_alert_text("Vaccination outcome recorded for HPV")
expect_alert_text(
programme_children_page.page, "Vaccination outcome recorded for HPV"
)


@pytest.mark.reports
Expand Down
10 changes: 6 additions & 4 deletions tests/test_sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from mavis.test.annotations import issue
from mavis.test.data import ClassFileMapping
from mavis.test.models import ConsentMethod, Programme, VaccinationRecord, Vaccine
from mavis.test.utils import get_offset_date
from mavis.test.utils import expect_alert_text, expect_details, get_offset_date

pytestmark = pytest.mark.sessions

Expand Down Expand Up @@ -325,7 +325,7 @@ def test_consent_refused_and_activity_log(
nurse_consent_wizard_page.select_parent(child.parents[0])
nurse_consent_wizard_page.select_consent_method(ConsentMethod.PAPER)
nurse_consent_wizard_page.record_parent_refuse_consent()
nurse_consent_wizard_page.expect_text_in_alert(str(child))
expect_alert_text(nurse_consent_wizard_page.page, str(child))

sessions_consent_page.select_consent_refused()
sessions_consent_page.search_and_click_child(child)
Expand Down Expand Up @@ -406,7 +406,9 @@ def test_verify_excel_export_and_clinic_invitation(
sessions_vaccination_wizard_page.check_location_radio(clinics[0])
sessions_vaccination_wizard_page.click_continue_button()
sessions_vaccination_wizard_page.click_confirm_button()
sessions_patient_page.expect_alert_text("Vaccination outcome recorded for HPV")
expect_alert_text(
sessions_patient_page.page, "Vaccination outcome recorded for HPV"
)
dashboard_page.click_mavis()
dashboard_page.click_sessions()
sessions_search_page.click_session_for_programme_group(school, Programme.HPV)
Expand Down Expand Up @@ -459,7 +461,7 @@ def test_editing_session_programmes(
sessions_edit_page.click_change_programmes()
sessions_edit_page.add_programme(Programme.FLU)
sessions_edit_page.click_continue_button()
sessions_edit_page.expect_details("Programmes", "Flu HPV")
expect_details(sessions_edit_page.page, "Programmes", "Flu HPV")
sessions_edit_page.click_save_changes()
sessions_edit_page.expect_session_to_have_programmes([Programme.FLU, Programme.HPV])
sessions_overview_page.click_consent_tab()
Expand Down