Skip to content

Commit 8df4b78

Browse files
As per PR 107 comments, Code change is implemented.
1 parent abe158d commit 8df4b78

File tree

1 file changed

+60
-16
lines changed

1 file changed

+60
-16
lines changed

pages/screening_subject_search/subject_episode_events_and_notes_page.py

Lines changed: 60 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,26 @@ def __init__(self, page: Page):
1111
super().__init__(page)
1212
self.page = page
1313
# List of episode events and notes - page locators
14-
self.latest_event_status_cell = self.page.locator("table >> td.epihdr_data").nth(0) # if it's the first one
15-
self.latest_event_cell = self.page.get_by_role("cell", name="Record Diagnosis Date", exact=True)
16-
self.latest_diagnosis_cell = self.page.locator("td[align='center']:has-text('Diag Date :')")
14+
self.latest_event_status_cell = self.page.locator(
15+
"table >> td.epihdr_data"
16+
).nth(
17+
0
18+
) # if it's the first one
19+
self.latest_event_cell = self.page.get_by_role(
20+
"cell", name="Record Diagnosis Date", exact=True
21+
)
22+
self.latest_diagnosis_cell = self.page.locator(
23+
"td[align='center']:has-text('Diag Date :')"
24+
)
1725

1826
# Episode details (Replace with actual selectors only for scenario 17)
1927
self.latest_episode_status = self.page.locator("#latestEpisodeStatus")
20-
self.latest_episode_has_diagnosis_date = self.page.locator("#latestEpisodeHasDiagnosisDate")
21-
self.latest_episode_diagnosis_reason = self.page.locator("#latestEpisodeDiagnosisDateReason")
28+
self.latest_episode_has_diagnosis_date = self.page.locator(
29+
"#latestEpisodeHasDiagnosisDate"
30+
)
31+
self.latest_episode_diagnosis_reason = self.page.locator(
32+
"#latestEpisodeDiagnosisDateReason"
33+
)
2234
self.process_sspi_update_button = self.page.get_by_text("Process SSPI Update")
2335
self.deduction_reason_dropdown = self.page.locator("#deductionReason")
2436
self.confirm_sspi_update_button = self.page.get_by_text("Confirm")
@@ -30,16 +42,25 @@ def expected_episode_event_is_displayed(self, event_description: str) -> None:
3042
).to_be_visible()
3143

3244
def get_latest_event_details(self) -> dict:
33-
"""Retrieves key details for the latest episode entry."""
45+
"""
46+
Retrieves key details for the latest episode entry from the UI.
47+
48+
Returns:
49+
dict: A dictionary containing the following keys:
50+
- "latest_event_status" (str): The current status text of the latest event.
51+
- "event" (str): A description or name of the latest event.
52+
- "item" (str): Details related to the latest diagnosis item.
53+
54+
Raises:
55+
pytest.fail: If any of the UI elements cannot be read, the test fails immediately.
56+
"""
3457
try:
3558
status_text = self.latest_event_status_cell.inner_text()
3659
event_text = self.latest_event_cell.inner_text()
3760
diagnosis_text = self.latest_diagnosis_cell.first.inner_text()
3861
logging.debug(f"DEBUG: {event_text}, {status_text}, {diagnosis_text}")
3962
except Exception as e:
40-
logging.error(f"Could not retrieve latest event details: {e}")
41-
pytest.fail("Failed to read latest episode event details from UI.")
42-
63+
pytest.fail(f"Failed to read latest episode event details from UI: {e}")
4364
return {
4465
"latest_event_status": status_text,
4566
"event": event_text,
@@ -49,15 +70,14 @@ def get_latest_event_details(self) -> dict:
4970
def validate_event_status_is_not_A50(self, event_details: dict) -> None:
5071
"""Validates that latest_event_status does not contain 'A50'."""
5172
latest_status = event_details.get("latest_event_status")
52-
5373
logging.info(f"Validating Latest Event Status: {latest_status}")
5474

5575
if latest_status is None:
5676
pytest.fail("Missing 'latest_event_status' in event_details.")
57-
58-
if "A50" in latest_status:
59-
pytest.fail(f"Invalid status detected: 'A50' is not allowed. Received: '{latest_status}'")
60-
77+
elif "A50" in str(latest_status):
78+
pytest.fail(
79+
f"Invalid status detected: 'A50' is not allowed. Received: '{latest_status}'"
80+
)
6181
logging.info(f"Status '{latest_status}' is allowed.")
6282

6383
def is_record_diagnosis_date_option_available(self) -> bool:
@@ -68,7 +88,9 @@ def is_record_diagnosis_date_option_available(self) -> bool:
6888
bool: True if the option is available, False otherwise.
6989
"""
7090
try:
71-
return self.page.get_by_role("button", name="Record Diagnosis Date").is_visible()
91+
return self.page.get_by_role(
92+
"button", name="Record Diagnosis Date"
93+
).is_visible()
7294
except Exception as e:
7395
logging.error(f"Error checking for 'Record Diagnosis Date' option: {e}")
7496
return False
@@ -81,17 +103,39 @@ def is_amend_diagnosis_date_option_available(self) -> bool:
81103
bool: True if the option is available, False otherwise.
82104
"""
83105
try:
84-
return self.page.get_by_role("button", name="Amend Diagnosis Date").is_visible()
106+
return self.page.get_by_role(
107+
"button", name="Amend Diagnosis Date"
108+
).is_visible()
85109
except Exception as e:
86110
logging.error(f"Error checking for 'Amend Diagnosis Date' option: {e}")
87111
return False
88112

89113
def process_sspi_update_for_death(self, deduction_reason: str):
114+
"""
115+
Submits an SSPI update for a death-related deduction reason through the UI workflow.
116+
117+
Args:
118+
deduction_reason (str): The label of the deduction reason to select from the dropdown.
119+
120+
Steps:
121+
- Clicks the SSPI update button.
122+
- Selects the specified deduction reason from the dropdown.
123+
- Confirms the SSPI update by clicking the confirmation button.
124+
"""
90125
self.process_sspi_update_button.click()
91126
self.deduction_reason_dropdown.select_option(label=deduction_reason)
92127
self.confirm_sspi_update_button.click()
93128

94129
def get_latest_episode_details(self):
130+
"""
131+
Retrieves details of the latest episode from the UI elements.
132+
133+
Returns:
134+
dict: A dictionary containing:
135+
- 'latest_episode_status' (str): The status text of the latest episode.
136+
- 'latest_episode_has_diagnosis_date' (str): Indicator text of whether a diagnosis date is present.
137+
- 'latest_episode_diagnosis_date_reason' (str): Reason text explaining the diagnosis date status.
138+
"""
95139
return {
96140
"latest_episode_status": self.latest_episode_status.inner_text(),
97141
"latest_episode_has_diagnosis_date": self.latest_episode_has_diagnosis_date.inner_text(),

0 commit comments

Comments
 (0)