Skip to content

Commit

Permalink
Report search query error message on UI
Browse files Browse the repository at this point in the history
  • Loading branch information
mplum committed Jan 31, 2025
1 parent 966eafb commit 2cca5ce
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 4 deletions.
4 changes: 2 additions & 2 deletions strictdoc/server/routers/main_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -2657,8 +2657,8 @@ def get_search(q: Optional[str] = None):
node_query = QueryObject(
query, export_action.traceability_index
)
except:
error = "error: Cannot parse query."
except Exception as e:
error = f"error: {e}"

if node_query is not None:
result = []
Expand Down
17 changes: 17 additions & 0 deletions tests/end2end/helpers/screens/search/search.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from selenium import webdriver
from selenium.webdriver.common.by import By

from tests.end2end.helpers.screens.screen import Screen
Expand All @@ -9,6 +10,11 @@ def do_click_on_search_requirements(self):
'//a[@data-testid="node.is_requirement"]',
)

def get_search_error_msg(self):
return self.test_case.find_element(
By.XPATH, "//div[@class='sdoc-form-error']"
).text

def assert_nr_results(self, nr_results: int):
content = (
f"Found {nr_results} results."
Expand All @@ -33,3 +39,14 @@ def do_click_on_search_sections(self) -> Screen_SearchResults:
'//a[@data-testid="node.is_section"]',
)
return Screen_SearchResults(self.test_case)

def do_search(self, query) -> Screen_SearchResults:
textBox = self.test_case.driver.find_element(
By.XPATH, "//input[@id='q']"
)
textBox.clear()
textBox.send_keys(query)
self.test_case.click_xpath(
'//button[@data-testid="form-submit-action"]',
)
return Screen_SearchResults(self.test_case)
40 changes: 38 additions & 2 deletions tests/end2end/screens/search/view_search_screen/test_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@


class Test(E2ECase):
def test(self):
def test_search_links(self):
with SDocTestServer(
input_path=path_to_this_test_file_folder
) 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_link_to_search_screen_present()
Expand All @@ -38,3 +37,40 @@ def test(self):

screen_search_results = screen_search.do_click_on_search_sections()
screen_search_results.assert_text("Section title")

def test_empty_search(self):
with SDocTestServer(
input_path=path_to_this_test_file_folder
) as test_server:
self.open(test_server.get_host_and_port())

screen_project_index = Screen_ProjectIndex(self)
screen_project_index.assert_on_screen()

screen_search: Screen_Search = (
screen_project_index.do_click_on_search_screen_link()
)
screen_search_results = screen_search.do_search(
"""(node.is_requirement and node["STATEMENT"] == "NONE")"""
)

screen_search_results.assert_nr_results(0)

def test_invalid_search(self):
with SDocTestServer(
input_path=path_to_this_test_file_folder
) as test_server:
self.open(test_server.get_host_and_port())

screen_project_index = Screen_ProjectIndex(self)
screen_project_index.assert_on_screen()

screen_search: Screen_Search = (
screen_project_index.do_click_on_search_screen_link()
)
screen_search_results = screen_search.do_search("""foo""")

self.assertRegex(
screen_search_results.get_search_error_msg(),
"error:.+Expected.+[*]foo",
)

0 comments on commit 2cca5ce

Please sign in to comment.