Skip to content

Commit a00bcc9

Browse files
authored
Merge pull request #348 from NHSDigital/refactor-vaccine-page
Refactor vaccine pages
2 parents 4351c9f + a760f66 commit a00bcc9

File tree

9 files changed

+191
-101
lines changed

9 files changed

+191
-101
lines changed

mavis/test/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
pytest_sessionstart,
55
)
66
from .fixtures import (
7+
add_batch_page,
8+
add_vaccine_batch,
79
admin,
10+
archive_batch_page,
811
archive_consent_response_page,
912
base_url,
1013
basic_auth,
@@ -17,6 +20,7 @@
1720
create_new_record_consent_response_page,
1821
dashboard_page,
1922
download_school_moves_page,
23+
edit_batch_page,
2024
get_online_consent_url,
2125
import_records_page,
2226
log_in_as_admin,
@@ -45,7 +49,10 @@
4549

4650

4751
__all__ = [
52+
"add_batch_page",
53+
"add_vaccine_batch",
4854
"admin",
55+
"archive_batch_page",
4956
"archive_consent_response_page",
5057
"base_url",
5158
"basic_auth",
@@ -58,6 +65,7 @@
5865
"create_new_record_consent_response_page",
5966
"dashboard_page",
6067
"download_school_moves_page",
68+
"edit_batch_page",
6169
"get_online_consent_url",
6270
"import_records_page",
6371
"log_in_as_admin",

mavis/test/fixtures/__init__.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
1-
from .helpers import get_online_consent_url, log_in_as_admin, log_in_as_nurse, test_data
1+
from .helpers import (
2+
add_vaccine_batch,
3+
get_online_consent_url,
4+
log_in_as_admin,
5+
log_in_as_nurse,
6+
test_data,
7+
)
28
from .pages import (
9+
add_batch_page,
10+
archive_batch_page,
311
archive_consent_response_page,
412
children_page,
513
consent_page,
614
consent_response_page,
715
create_new_record_consent_response_page,
816
dashboard_page,
917
download_school_moves_page,
18+
edit_batch_page,
1019
import_records_page,
1120
log_in_page,
1221
match_consent_response_page,
@@ -40,7 +49,10 @@
4049
)
4150

4251
__all__ = [
52+
"add_vaccine_batch",
53+
"add_batch_page",
4354
"admin",
55+
"archive_batch_page",
4456
"archive_consent_response_page",
4557
"base_url",
4658
"basic_auth",
@@ -53,6 +65,7 @@
5365
"create_new_record_consent_response_page",
5466
"dashboard_page",
5567
"download_school_moves_page",
68+
"edit_batch_page",
5669
"get_online_consent_url",
5770
"import_records_page",
5871
"log_in_as_admin",

mavis/test/fixtures/helpers.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
1+
from datetime import date, timedelta
2+
13
import pytest
24

35
from ..data import TestData
6+
from ..models import Vaccine
7+
8+
9+
@pytest.fixture
10+
def add_vaccine_batch(add_batch_page, dashboard_page, vaccines_page):
11+
def wrapper(vaccine: Vaccine, batch_name: str = "ABC123"):
12+
vaccines_page.navigate()
13+
vaccines_page.click_add_batch(vaccine)
14+
add_batch_page.fill_name(batch_name)
15+
add_batch_page.fill_expiry_date(date.today() + timedelta(days=1))
16+
add_batch_page.confirm()
17+
return batch_name
18+
19+
return wrapper
420

521

622
@pytest.fixture

mavis/test/fixtures/pages.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import pytest
22

33
from ..pages import (
4+
AddBatchPage,
5+
ArchiveBatchPage,
46
ArchiveConsentResponsePage,
57
ChildrenPage,
68
ConsentPage,
79
ConsentResponsePage,
810
CreateNewRecordConsentResponsePage,
911
DashboardPage,
1012
DownloadSchoolMovesPage,
13+
EditBatchPage,
1114
ImportRecordsPage,
1215
LogInPage,
1316
MatchConsentResponsePage,
@@ -21,6 +24,16 @@
2124
)
2225

2326

27+
@pytest.fixture
28+
def add_batch_page(page):
29+
return AddBatchPage(page)
30+
31+
32+
@pytest.fixture
33+
def archive_batch_page(page):
34+
return ArchiveBatchPage(page)
35+
36+
2437
@pytest.fixture
2538
def archive_consent_response_page(page):
2639
return ArchiveConsentResponsePage(page)
@@ -56,6 +69,11 @@ def download_school_moves_page(page):
5669
return DownloadSchoolMovesPage(page)
5770

5871

72+
@pytest.fixture
73+
def edit_batch_page(page):
74+
return EditBatchPage(page)
75+
76+
5977
@pytest.fixture
6078
def import_records_page(test_data, page):
6179
return ImportRecordsPage(test_data, page)

mavis/test/pages/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,20 @@
1414
MatchConsentResponsePage,
1515
UnmatchedConsentResponsesPage,
1616
)
17-
from .vaccines import VaccinesPage
17+
from .vaccines import AddBatchPage, ArchiveBatchPage, EditBatchPage, VaccinesPage
1818

1919

2020
__all__ = [
21+
"AddBatchPage",
22+
"ArchiveBatchPage",
2123
"ArchiveConsentResponsePage",
2224
"ChildrenPage",
2325
"ConsentPage",
2426
"ConsentResponsePage",
2527
"CreateNewRecordConsentResponsePage",
2628
"DashboardPage",
2729
"DownloadSchoolMovesPage",
30+
"EditBatchPage",
2831
"ImportRecordsPage",
2932
"LogInPage",
3033
"MatchConsentResponsePage",

mavis/test/pages/vaccines.py

Lines changed: 75 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,95 @@
1-
from playwright.sync_api import Page, expect
1+
from datetime import date
2+
3+
from playwright.sync_api import Page
24

35
from ..models import Vaccine
46
from ..step import step
5-
from ..wrappers import get_current_datetime, get_offset_date
67

78

8-
class VaccinesPage:
9+
class BatchExpiryDateMixin:
10+
def __init__(self, page: Page):
11+
self.expiry_day_textbox = page.get_by_role("textbox", name="Day")
12+
self.expiry_month_textbox = page.get_by_role("textbox", name="Month")
13+
self.expiry_year_textbox = page.get_by_role("textbox", name="Year")
14+
15+
@step("Fill in expiry date with {1}")
16+
def fill_expiry_date(self, value: date):
17+
self.expiry_day_textbox.fill(str(value.day))
18+
self.expiry_month_textbox.fill(str(value.month))
19+
self.expiry_year_textbox.fill(str(value.year))
20+
21+
22+
class AddBatchPage(BatchExpiryDateMixin):
923
def __init__(self, page: Page):
24+
super().__init__(page)
25+
1026
self.page = page
1127

12-
self.batch_textbox = self.page.get_by_role("textbox", name="Batch")
13-
self.day_textbox = self.page.get_by_role("textbox", name="Day")
14-
self.month_textbox = self.page.get_by_role("textbox", name="Month")
15-
self.year_textbox = self.page.get_by_role("textbox", name="Year")
16-
self.add_batch_button = self.page.get_by_role("button", name="Add batch")
17-
self.save_changes_button = self.page.get_by_role("button", name="Save changes")
18-
self.confirm_archive_button = self.page.get_by_role(
19-
"button", name="Yes, archive this batch"
20-
)
21-
self.batch_added_alert = page.get_by_role("alert", name="Success").filter(
28+
self.name_textbox = page.get_by_role("textbox", name="Batch")
29+
self.confirm_button = page.get_by_role("button", name="Add batch")
30+
self.success_alert = page.get_by_role("alert", name="Success").filter(
2231
has_text="added"
2332
)
24-
self.batch_name_error = (
25-
page.locator("div").filter(has_text="There is a problemEnter a").nth(3)
26-
)
2733

28-
def _calculate_batch_details(self, vaccine: Vaccine, batch_name: str):
29-
self.batch_name = (
30-
f"{vaccine.replace(' ', '').replace('-', '')}{get_current_datetime()}"
31-
if batch_name == ""
32-
else batch_name
33-
)
34-
self.future_expiry_date = get_offset_date(offset_days=365)
35-
self.day = self.future_expiry_date[-2:]
36-
self.month = self.future_expiry_date[4:6]
37-
self.year = self.future_expiry_date[:4]
34+
error_alert = page.get_by_role("alert").filter(has_text="There is a problem")
35+
self.error_listitem = error_alert.get_by_role("listitem")
3836

39-
@step("Add a new batch for {1}")
40-
def add_batch(self, vaccine: Vaccine, batch_name: str = "") -> str:
41-
self._calculate_batch_details(vaccine, batch_name=batch_name)
42-
expect(self.page.get_by_role("main")).to_contain_text(vaccine)
37+
@step("Fill in name with {1}")
38+
def fill_name(self, value: str):
39+
self.name_textbox.fill(value)
4340

44-
self.page.get_by_role("link", name=f"Add a new {vaccine} batch").click()
41+
@step("Confirm add batch")
42+
def confirm(self):
43+
self.confirm_button.click()
4544

46-
expect(self.page.get_by_role("main")).to_contain_text(vaccine)
47-
self.fill_batch_details()
48-
self.click_add_batch_button()
49-
if len(batch_name) <= 100:
50-
expect(self.batch_added_alert).to_be_visible()
51-
else:
52-
expect(self.batch_name_error).to_be_visible()
5345

54-
return self.batch_name
46+
class EditBatchPage(BatchExpiryDateMixin):
47+
def __init__(self, page: Page):
48+
super().__init__(page)
5549

56-
@step("Fill the batch details")
57-
def fill_batch_details(self):
58-
self.batch_textbox.fill(value=self.batch_name)
59-
self.day_textbox.fill(value=self.day)
60-
self.month_textbox.fill(value=self.month)
61-
self.year_textbox.fill(value=self.year)
50+
self.page = page
6251

63-
@step("Click on Add batch")
64-
def click_add_batch_button(self):
65-
self.add_batch_button.click()
52+
self.confirm_button = page.get_by_role("button", name="Save changes")
53+
self.success_alert = page.get_by_role("alert", name="Success").filter(
54+
has_text="updated"
55+
)
6656

67-
@step("Click on Save changes")
68-
def click_save_changes(self):
69-
self.save_changes_button.click()
57+
@step("Confirm edit batch")
58+
def confirm(self):
59+
self.confirm_button.click()
7060

71-
@step("Click on Archive this batch")
72-
def click_archive_this_batch(self):
73-
self.confirm_archive_button.click()
74-
75-
@step("Change the batch for {1}")
76-
def change_batch(self, vaccine: Vaccine):
77-
batch_name = self.batch_name or str(vaccine)
78-
self.__click_batch_option(batch_name, "Change")
79-
self.year_textbox.fill(value=get_offset_date(offset_days=730)[:4])
80-
self.click_save_changes()
81-
_success_message = f"Batch {self.batch_name} updated"
82-
expect(self.page.get_by_role("alert")).to_contain_text(_success_message)
83-
84-
@step("Archive the batch for {1}")
85-
def archive_batch(self, vaccine: Vaccine):
86-
batch_name = self.batch_name or str(vaccine)
87-
self.__click_batch_option(batch_name, "Archive")
88-
self.click_archive_this_batch()
89-
expect(self.page.get_by_role("alert")).to_contain_text("Batch archived.")
90-
91-
def __click_batch_option(self, batch_name: str, link_text: str):
92-
row = self.page.locator("tr").filter(
93-
has=self.page.locator("td:first-child", has_text=batch_name)
61+
62+
class ArchiveBatchPage:
63+
def __init__(self, page: Page):
64+
self.page = page
65+
self.confirm_button = page.get_by_role("button", name="Yes, archive this batch")
66+
self.success_alert = page.get_by_role("alert", name="Success").filter(
67+
has_text="archived"
9468
)
95-
row.locator("td:last-child").get_by_role("link", name=link_text).click()
69+
70+
@step("Click on Archive this batch")
71+
def confirm(self):
72+
self.confirm_button.click()
73+
74+
75+
class VaccinesPage:
76+
def __init__(self, page: Page):
77+
self.page = page
78+
79+
@step("Go to vaccines page")
80+
def navigate(self):
81+
self.page.goto("/vaccines")
82+
83+
@step("Add batch for {1}")
84+
def click_add_batch(self, vaccine: Vaccine):
85+
self.page.get_by_role("link", name=f"Add a new {vaccine} batch").click()
86+
87+
@step("Change {2} batch for {1}")
88+
def click_change_batch(self, vaccine: Vaccine, batch_name: str):
89+
name = f"Change {batch_name} batch of {vaccine}"
90+
self.page.get_by_role("link", name=name).click()
91+
92+
@step("Archive {2} batch for {1}")
93+
def click_archive_batch(self, vaccine: Vaccine, batch_name: str):
94+
name = f"Archive {batch_name} batch of {vaccine}"
95+
self.page.get_by_role("link", name=name).click()

tests/test_programmes.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,14 @@ def setup_mavis_1729(
5959
@pytest.fixture
6060
def setup_mav_854(
6161
log_in_as_nurse,
62+
add_vaccine_batch,
6263
schools,
6364
dashboard_page,
6465
import_records_page,
6566
sessions_page,
66-
vaccines_page,
6767
):
6868
try:
69-
community_clinics_session = "Community clinics"
70-
71-
dashboard_page.click_vaccines()
72-
batch_name = vaccines_page.add_batch(Vaccine.GARDASIL_9)
69+
batch_name = add_vaccine_batch(Vaccine.GARDASIL_9)
7370
dashboard_page.click_mavis()
7471
dashboard_page.click_sessions()
7572
sessions_page.schedule_a_valid_session(schools[0], for_today=True)
@@ -78,9 +75,7 @@ def setup_mav_854(
7875
sessions_page.click_location(schools[0])
7976
dashboard_page.click_mavis()
8077
dashboard_page.click_sessions()
81-
sessions_page.schedule_a_valid_session(
82-
community_clinics_session, for_today=True
83-
)
78+
sessions_page.schedule_a_valid_session("Community clinics", for_today=True)
8479
dashboard_page.click_mavis()
8580
dashboard_page.click_children()
8681
yield batch_name

tests/test_reset.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,15 @@
99
@pytest.fixture
1010
def setup_mav_965(
1111
log_in_as_nurse,
12+
add_vaccine_batch,
1213
schools,
1314
dashboard_page,
1415
import_records_page,
1516
sessions_page,
16-
vaccines_page,
1717
):
18-
dashboard_page.click_vaccines()
19-
gardasil_9_batch_name = vaccines_page.add_batch(Vaccine.GARDASIL_9)
20-
menquadfi_batch_name = vaccines_page.add_batch(Vaccine.MENQUADFI)
21-
revaxis_batch_name = vaccines_page.add_batch(Vaccine.REVAXIS)
18+
gardasil_9_batch_name = add_vaccine_batch(Vaccine.GARDASIL_9)
19+
menquadfi_batch_name = add_vaccine_batch(Vaccine.MENQUADFI)
20+
revaxis_batch_name = add_vaccine_batch(Vaccine.REVAXIS)
2221
dashboard_page.click_mavis()
2322
dashboard_page.click_sessions()
2423
sessions_page.schedule_a_valid_session(schools[0], for_today=True)

0 commit comments

Comments
 (0)