|
| 1 | +from playwright.sync_api import Page, Locator |
| 2 | +from pages.base_page import BasePage |
| 3 | +from enum import StrEnum |
| 4 | +import logging |
| 5 | +import pytest |
| 6 | +from utils.table_util import TableUtils |
| 7 | + |
| 8 | + |
| 9 | +class SubjectEventsNotes(BasePage): |
| 10 | + """Subject Events Notes Page locators, and methods for interacting with the page.""" |
| 11 | + |
| 12 | + def __init__(self, page: Page): |
| 13 | + super().__init__(page) |
| 14 | + self.page = page |
| 15 | + self.table_utils = TableUtils( |
| 16 | + page, "#displayRS" |
| 17 | + ) # Initialize TableUtils for the table with id="displayRS" |
| 18 | + # Subject Events Notes - page filters |
| 19 | + self.additional_care_note_checkbox = self.page.get_by_label( |
| 20 | + "Additional Care Needs Note" |
| 21 | + ) |
| 22 | + self.subject_note_checkbox = self.page.get_by_label("Subject Note") |
| 23 | + self.kit_note_checkbox = self.page.get_by_label("Kit Note") |
| 24 | + self.note_title = self.page.get_by_label("Note Title") |
| 25 | + self.additional_care_note_type = self.page.locator("#UI_ADDITIONAL_CARE_NEED") |
| 26 | + self.notes_upto_500_char = self.page.get_by_label("Notes (up to 500 char)") |
| 27 | + self.update_notes_button = self.page.get_by_role("button", name="Update Notes") |
| 28 | + self.note_type = self.page.locator("#UI_ADDITIONAL_CARE_NEED_FILTER") |
| 29 | + self.note_status = self.page.locator( |
| 30 | + "//table[@id='displayRS']/tbody/tr[2]/td[3]/select" |
| 31 | + ) |
| 32 | + self.episode_note_status = self.page.locator( |
| 33 | + "//table[@id='displayRS']/tbody/tr[2]/td[4]/select" |
| 34 | + ) |
| 35 | + |
| 36 | + def select_additional_care_note(self) -> None: |
| 37 | + """Selects the 'Additional Care Needs Note' checkbox.""" |
| 38 | + self.additional_care_note_checkbox.check() |
| 39 | + |
| 40 | + def select_subject_note(self) -> None: |
| 41 | + """Selects the 'subject note' checkbox.""" |
| 42 | + self.subject_note_checkbox.check() |
| 43 | + |
| 44 | + def select_kit_note(self) -> None: |
| 45 | + """Selects the 'kit note' checkbox.""" |
| 46 | + self.kit_note_checkbox.check() |
| 47 | + |
| 48 | + def select_additional_care_note_type(self, option: str) -> None: |
| 49 | + """Selects an option from the 'Additional Care Note Type' dropdown. |
| 50 | +
|
| 51 | + Args: |
| 52 | + option (AdditionalCareNoteTypeOptions): The option to select from the dropdown. |
| 53 | + Use one of the predefined values from the |
| 54 | + AdditionalCareNoteTypeOptions enum, such as: |
| 55 | + - AdditionalCareNoteTypeOptions.LEARNING_DISABILITY |
| 56 | + - AdditionalCareNoteTypeOptions.SIGHT_DISABILITY |
| 57 | + - AdditionalCareNoteTypeOptions.HEARING_DISABILITY |
| 58 | + - AdditionalCareNoteTypeOptions.MOBILITY_DISABILITY |
| 59 | + - AdditionalCareNoteTypeOptions.MANUAL_DEXTERITY |
| 60 | + - AdditionalCareNoteTypeOptions.SPEECH_DISABILITY |
| 61 | + - AdditionalCareNoteTypeOptions.CONTINENCE_DISABILITY |
| 62 | + - AdditionalCareNoteTypeOptions.LANGUAGE |
| 63 | + - AdditionalCareNoteTypeOptions.OTHER |
| 64 | + """ |
| 65 | + self.additional_care_note_type.select_option(option) |
| 66 | + |
| 67 | + def select_note_type(self, option: str) -> None: |
| 68 | + """ |
| 69 | + Selects a note type from the dropdown menu. |
| 70 | +
|
| 71 | + Args: |
| 72 | + option (str): The value of the option to select from the dropdown. |
| 73 | + """ |
| 74 | + self.note_type.select_option(option) |
| 75 | + |
| 76 | + def select_note_status(self, option: str) -> None: |
| 77 | + """ |
| 78 | + Selects a note status from the dropdown menu. |
| 79 | +
|
| 80 | + Args: |
| 81 | + option (str): The value of the option to select from the dropdown. |
| 82 | + """ |
| 83 | + self.note_status.select_option(option) |
| 84 | + |
| 85 | + def fill_note_title(self, title: str) -> None: |
| 86 | + """Fills the title field with the provided text.""" |
| 87 | + self.note_title.fill(title) |
| 88 | + |
| 89 | + def fill_notes(self, notes: str) -> None: |
| 90 | + """Fills the notes field with the provided text.""" |
| 91 | + self.notes_upto_500_char.fill(notes) |
| 92 | + |
| 93 | + def accept_dialog_and_update_notes(self) -> None: |
| 94 | + """Clicks the 'Update Notes' button and handles the dialog by clicking 'OK'.""" |
| 95 | + self.page.once("dialog", lambda dialog: dialog.accept()) |
| 96 | + self.update_notes_button.click() |
| 97 | + |
| 98 | + def accept_dialog_and_add_replacement_note(self) -> None: |
| 99 | + """ |
| 100 | + Dismisses the dialog and clicks the 'Add Replacement Note' button. |
| 101 | + """ |
| 102 | + self.page.once("dialog", lambda dialog: dialog.accept()) |
| 103 | + self.page.get_by_role("button", name="Add Replacement Note").click() |
| 104 | + |
| 105 | + def get_title_and_note_from_row(self, row_number: int = 0) -> dict: |
| 106 | + """ |
| 107 | + Extracts title and note from a specific row's 'Notes' column using dynamic column index. |
| 108 | + """ |
| 109 | + cell_text = self.table_utils.get_cell_value("Notes", row_number) |
| 110 | + lines = cell_text.split("\n\n") |
| 111 | + title = lines[0].strip() if len(lines) > 0 else "" |
| 112 | + note = lines[1].strip() if len(lines) > 1 else "" |
| 113 | + logging.info( |
| 114 | + f"Extracted title: '{title}' and note: '{note}' from row {row_number}" |
| 115 | + ) |
| 116 | + return {"title": title, "note": note} |
| 117 | + |
| 118 | + |
| 119 | +class AdditionalCareNoteTypeOptions(StrEnum): |
| 120 | + """Enum for AdditionalCareNoteTypeOptions.""" |
| 121 | + |
| 122 | + LEARNING_DISABILITY = "4120" |
| 123 | + SIGHT_DISABILITY = "4121" |
| 124 | + HEARING_DISABILITY = "4122" |
| 125 | + MOBILITY_DISABILITY = "4123" |
| 126 | + MANUAL_DEXTERITY = "4124" |
| 127 | + SPEECH_DISABILITY = "4125" |
| 128 | + CONTINENCE_DISABILITY = "4126" |
| 129 | + LANGUAGE = "4128" |
| 130 | + OTHER = "4127" |
| 131 | + |
| 132 | + |
| 133 | +class NotesOptions(StrEnum): |
| 134 | + """Enum for NoteTypeOptions.""" |
| 135 | + |
| 136 | + SUBJECT_NOTE = "4111" |
| 137 | + KIT_NOTE = "308015" |
| 138 | + ADDITIONAL_CARE_NOTE = "4112" |
| 139 | + EPISODE_NOTE = "4110" |
| 140 | + |
| 141 | + |
| 142 | +class NotesStatusOptions(StrEnum): |
| 143 | + """Enum for NoteStatusOptions.""" |
| 144 | + |
| 145 | + ACTIVE = "4100" |
| 146 | + OBSOLETE = "4101" |
| 147 | + INVALID = "4102" |
0 commit comments