Skip to content

Commit

Permalink
tests/end2end: add update_requirement_uid_reset_button/test_case.py; …
Browse files Browse the repository at this point in the history
…add the helpers needed for that
  • Loading branch information
mettta committed Nov 13, 2023
1 parent 97eec0f commit 6964e09
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tests/end2end/helpers/components/node/requirement.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ def assert_requirement_title(
by=By.XPATH,
)

def assert_requirement_has_no_uid(self) -> None:
"""Use it with full requirement. <sdoc-requirement-field ...>"""
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,
Expand Down
32 changes: 32 additions & 0 deletions tests/end2end/helpers/screens/document/form_edit_requirement.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']")
Original file line number Diff line number Diff line change
@@ -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.
<<<
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[DOCUMENT]
TITLE: Document 1

[FREETEXT]
Hello world!
[/FREETEXT]

[REQUIREMENT]
UID: REQ-1
STATEMENT: >>>
Requirement statement.
<<<

[REQUIREMENT]
STATEMENT: >>>
Requirement statement.
<<<
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 6964e09

Please sign in to comment.