diff --git a/tests/end2end/helpers/components/node/requirement.py b/tests/end2end/helpers/components/node/requirement.py index cd408e53c..1eada2983 100644 --- a/tests/end2end/helpers/components/node/requirement.py +++ b/tests/end2end/helpers/components/node/requirement.py @@ -81,6 +81,14 @@ def assert_requirement_title( by=By.XPATH, ) + def assert_requirement_has_no_uid(self) -> None: + """Use it with full requirement. """ + self.test_case.assert_element_not_present( + f"{self.node_xpath}" + "//sdoc-requirement-field[@data-field-label='UID']", + by=By.XPATH, + ) + def assert_requirement_uid_contains( self, uid: str, diff --git a/tests/end2end/helpers/screens/document/form_edit_requirement.py b/tests/end2end/helpers/screens/document/form_edit_requirement.py index 8622bebfe..288da0021 100644 --- a/tests/end2end/helpers/screens/document/form_edit_requirement.py +++ b/tests/end2end/helpers/screens/document/form_edit_requirement.py @@ -115,3 +115,35 @@ def do_fill_in_field_statement(self, field_value: str) -> None: def do_fill_in_field_rationale(self, field_value: str) -> None: assert isinstance(field_value, str) super().do_fill_in("requirement-field-RATIONALE", field_value) + + # Reset UID button + + def assert_uid_field_contains(self, string: str) -> None: + self.test_case.assert_element_present( + "//*[@data-testid='form-field-requirement-field-UID']" + f"[contains(., '{string}')]", + by=By.XPATH, + ) + + def assert_uid_field_does_not_contain(self, string: str) -> None: + self.test_case.assert_element_not_present( + "//*[@data-testid='form-field-requirement-field-UID']" + f"[contains(., '{string}')]", + by=By.XPATH, + ) + + def assert_uid_field_has_reset_button(self) -> None: + self.test_case.assert_element_present( + "//*[@data-testid='reset-uid-field-action']", + by=By.XPATH, + ) + + def assert_uid_field_has_not_reset_button(self) -> None: + self.test_case.assert_element_not_present( + "//*[@data-testid='reset-uid-field-action']", + by=By.XPATH, + ) + + def do_reset_uid_field(self, field_name: str = "") -> None: + assert isinstance(field_name, str) + self.test_case.click_xpath("//*[@data-testid='reset-uid-field-action']") diff --git a/tests/end2end/screens/document/update_requirement/update_requirement_uid_reset_button/__init__.py b/tests/end2end/screens/document/update_requirement/update_requirement_uid_reset_button/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/end2end/screens/document/update_requirement/update_requirement_uid_reset_button/expected_output/document.sdoc b/tests/end2end/screens/document/update_requirement/update_requirement_uid_reset_button/expected_output/document.sdoc new file mode 100644 index 000000000..d3b165c94 --- /dev/null +++ b/tests/end2end/screens/document/update_requirement/update_requirement_uid_reset_button/expected_output/document.sdoc @@ -0,0 +1,18 @@ +[DOCUMENT] +TITLE: Document 1 + +[FREETEXT] +Hello world! +[/FREETEXT] + +[REQUIREMENT] +UID: REQ-1 +STATEMENT: >>> +Requirement statement. +<<< + +[REQUIREMENT] +UID: REQ-2 +STATEMENT: >>> +Requirement statement. +<<< diff --git a/tests/end2end/screens/document/update_requirement/update_requirement_uid_reset_button/input/document.sdoc b/tests/end2end/screens/document/update_requirement/update_requirement_uid_reset_button/input/document.sdoc new file mode 100644 index 000000000..890664709 --- /dev/null +++ b/tests/end2end/screens/document/update_requirement/update_requirement_uid_reset_button/input/document.sdoc @@ -0,0 +1,17 @@ +[DOCUMENT] +TITLE: Document 1 + +[FREETEXT] +Hello world! +[/FREETEXT] + +[REQUIREMENT] +UID: REQ-1 +STATEMENT: >>> +Requirement statement. +<<< + +[REQUIREMENT] +STATEMENT: >>> +Requirement statement. +<<< diff --git a/tests/end2end/screens/document/update_requirement/update_requirement_uid_reset_button/test_case.py b/tests/end2end/screens/document/update_requirement/update_requirement_uid_reset_button/test_case.py new file mode 100644 index 000000000..29c68a76e --- /dev/null +++ b/tests/end2end/screens/document/update_requirement/update_requirement_uid_reset_button/test_case.py @@ -0,0 +1,73 @@ +from tests.end2end.e2e_case import E2ECase +from tests.end2end.end2end_test_setup import End2EndTestSetup +from tests.end2end.helpers.screens.document.form_edit_requirement import ( + Form_EditRequirement, +) +from tests.end2end.helpers.screens.project_index.screen_project_index import ( + Screen_ProjectIndex, +) +from tests.end2end.server import SDocTestServer + + +class Test(E2ECase): + def test(self): + test_setup = End2EndTestSetup(path_to_test_file=__file__) + + with SDocTestServer( + input_path=test_setup.path_to_sandbox + ) as test_server: + self.open(test_server.get_host_and_port()) + + screen_project_index = Screen_ProjectIndex(self) + + screen_project_index.assert_on_screen() + screen_project_index.assert_contains_document("Document 1") + + screen_document = screen_project_index.do_click_on_first_document() + + screen_document.assert_on_screen_document() + screen_document.assert_header_document_title("Document 1") + screen_document.assert_text("Hello world!") + + # Requirement 1 has UID. + # It shouldn't have a reset button. + requirement1 = screen_document.get_requirement(1) + requirement1.assert_requirement_uid_contains("REQ-1") + form_edit_requirement1: Form_EditRequirement = ( + requirement1.do_open_form_edit_requirement() + ) + form_edit_requirement1.assert_on_form() + form_edit_requirement1.assert_uid_field_contains("REQ-1") + form_edit_requirement1.assert_uid_field_has_not_reset_button() + form_edit_requirement1.do_form_cancel() + + # New requirement form shouldn't have a reset button, + # but must have the correct UID entered in the field. + node_menu = requirement1.do_open_node_menu() + form_add_requirement: Form_EditRequirement = ( + node_menu.do_node_add_requirement_above() + ) + form_add_requirement.assert_on_form() + form_add_requirement.assert_uid_field_has_not_reset_button() + form_add_requirement.assert_uid_field_contains("REQ-2") + form_add_requirement.do_form_cancel() + + # Requirement 2 has UID. + # It shouldn't have a reset button. + requirement2 = screen_document.get_requirement(2) + requirement2.assert_requirement_has_no_uid() + form_edit_requirement2: Form_EditRequirement = ( + requirement2.do_open_form_edit_requirement() + ) + form_edit_requirement2.assert_on_form() + form_edit_requirement2.assert_uid_field_has_reset_button() + form_edit_requirement2.assert_uid_field_does_not_contain("REQ-2") + # Use the reset button. + form_edit_requirement2.do_reset_uid_field() + form_edit_requirement2.assert_uid_field_contains("REQ-2") + form_edit_requirement2.do_form_submit() + + # Checking the success of the button. + requirement2.assert_requirement_uid_contains("REQ-2") + + assert test_setup.compare_sandbox_and_expected_output()