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
57 changes: 36 additions & 21 deletions mavis/test/pages/team/team_schools_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ def __init__(self, page: Page) -> None:
self.confirm_site_button = self.page.get_by_role("button", name="Add site")
self.name_error_summary = self.page.locator("#draft-school-site-name-error")
self.confirm_school_name = self.page.locator("#confirm-school-site-name")
self.change_parent_school_link = self.page.get_by_role(
"link", name="Change parent school"
)

@step("Check only schools associated with the team are visible")
def check_only_expected_schools_visible(
Expand All @@ -62,33 +65,26 @@ def check_only_expected_schools_visible(
def click_add_new_school_site(self) -> None:
self.add_new_school_site_link.click()

@step("Check only schools associated with the team are visible in the dropdown")
def check_only_expected_schools_visible_in_dropdown(
self, schools: dict[str, list[School]]
) -> None:
expected_school_names = {
school.name for school_list in schools.values() for school in school_list
}

self.page.wait_for_load_state()
hidden_select = self.page.locator("#draft-school-site-urn-field-select")
options = hidden_select.locator("option[value]").all()

actual_school_names = {
option.inner_text().strip().rsplit(" (URN:", 1)[0]
for option in options
if option.get_attribute("value")
}

assert actual_school_names == expected_school_names

@step("Select a school")
def select_school(self, school: School) -> None:
self.page.wait_for_load_state()
self.page.reload() # to allow combobox to be interactable

self.select_a_school_combobox.fill(str(school))
self.page.get_by_role("option", name=str(school)).click()
options = self.page.locator('[class*="app-autocomplete__option"]')
count = options.count()

for i in range(count):
option = options.nth(i)
text = option.inner_text().strip()
first_line = text.split("\n", 1)[0].strip()
location_name = first_line.split(" (URN:", 1)[0]
if location_name == str(school):
option.click()
break
else:
msg = f"No autocomplete option found for location: {school!s}"
raise AssertionError(msg)

self.click_continue()

Expand All @@ -98,6 +94,7 @@ def check_site_details_form(self, school: School) -> None:
self._check_name_is_blank()
self._check_validation_error_if_same_name_used(school)
self._check_validation_error_if_empty_string_used()
self._check_validation_error_if_invalid_characters_used()

@step("Add new site details")
def add_new_site_details(self) -> None:
Expand All @@ -107,6 +104,10 @@ def add_new_site_details(self) -> None:
self.address_postcode_textbox.fill("SW1A 1AA")
self.click_continue()

@step("Click Change parent school")
def click_change_parent_school(self) -> None:
self.change_parent_school_link.click()

@step("Fill site name {1}")
def fill_site_name(self, site_name: str) -> None:
self.name_textbox.fill(site_name)
Expand Down Expand Up @@ -173,3 +174,17 @@ def _check_validation_error_if_empty_string_used(self) -> None:

expect(self.name_error_summary).to_be_visible()
expect(self.name_error_summary).to_contain_text("can't be blank")

@step("Check validation error if invalid characters used")
def _check_validation_error_if_invalid_characters_used(self) -> None:
self.name_textbox.fill("𒐫")
self.click_continue()

expect(self.name_error_summary).to_be_visible()
expect(self.name_error_summary).to_contain_text("invalid character")

self.name_textbox.fill("😭")
self.click_continue()

expect(self.name_error_summary).to_be_visible()
expect(self.name_error_summary).to_contain_text("invalid character")
51 changes: 37 additions & 14 deletions tests/test_team.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,46 +45,69 @@ def test_team_page_lists_correct_schools(page, log_in_as_nurse, schools):
TeamSchoolsPage(page).check_only_expected_schools_visible(schools)


def test_team_page_add_school_site(page, log_in_as_nurse, schools):
def test_team_page_add_school_sites(page, log_in_as_nurse, schools):
"""
Test: Verify that the user can add a new school site to the team.
Test: Verify that the user can add multiple school sites to the team.
Steps:
1. Navigate to the team page.
2. Click on the 'Schools' link.
3. Click on the 'Add new school site' button.
4. Select the school from the dropdown.
5. Fill in the school site details.
6. Confirm the details are correct.
3. Create first site (Site B) for a school.
4. Start creating a site for a different school,
then change parent school back to original.
5. Create second site (Site C) for the original school.
Verification:
- The dropdown only shows schools associated with the team.
- The new school site form is pre-filled with the school's address,
but not the name.
- Name of the site must be different from original school name and cannot be blank.
- Address of the site can be edited.
- The confirm screen shows the correct name and address details.
- The new school site is listed on the Schools page.
- The URNs of the new and original schools are updated with site identifiers.
- Both new school sites are listed on the Schools page.
- The URNs of the sites and original school are
updated with site identifiers (A, B, C).
- The "Change parent school" link allows switching schools during site creation.
"""
school = schools[Programme.HPV.group][0]
school_to_not_use = schools[Programme.HPV.group][1]

new_site_name = f"{school} (Site B)"
new_site_urn = f"{school.urn}B"
new_site_name_1 = f"{school} (Site B)"
new_site_urn_1 = f"{school.urn}B"
old_school_urn = f"{school.urn}A"

DashboardPage(page).click_your_team()
TeamContactDetailsPage(page).links.click_schools()
TeamSchoolsPage(page).click_add_new_school_site()
TeamSchoolsPage(page).check_only_expected_schools_visible_in_dropdown(schools)
TeamSchoolsPage(page).select_school(school)
TeamSchoolsPage(page).check_site_details_form(school)
TeamSchoolsPage(page).fill_site_name(new_site_name)
TeamSchoolsPage(page).fill_site_name(new_site_name_1)
TeamSchoolsPage(page).add_new_site_details()
TeamSchoolsPage(page).check_confirm_screen_shows_right_details(
new_site_urn_1, new_site_name_1, "New Address Line 1"
)
TeamSchoolsPage(page).confirm_site()
TeamSchoolsPage(page).check_new_site_is_listed(
new_site_name_1, new_site_urn_1, old_school_urn
)

TeamSchoolsPage(page).click_add_new_school_site()
TeamSchoolsPage(page).select_school(school_to_not_use)
TeamSchoolsPage(page).fill_site_name(f"{school_to_not_use} (Site 0)")
TeamSchoolsPage(page).add_new_site_details()
TeamSchoolsPage(page).click_change_parent_school()

new_site_name_2 = f"{school} (Site C)"
new_site_urn_2 = f"{school.urn}C"

TeamSchoolsPage(page).select_school(school)
TeamSchoolsPage(page).check_site_details_form(school)
TeamSchoolsPage(page).fill_site_name(new_site_name_2)
TeamSchoolsPage(page).add_new_site_details()
TeamSchoolsPage(page).check_confirm_screen_shows_right_details(
new_site_urn, new_site_name, "New Address Line 1"
new_site_urn_2, new_site_name_2, "New Address Line 1"
)
TeamSchoolsPage(page).confirm_site()
TeamSchoolsPage(page).check_new_site_is_listed(
new_site_name, new_site_urn, old_school_urn
new_site_name_2, new_site_urn_2, old_school_urn
)


Expand Down