Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6.15.z] Search functionality for vertical navigation menu #1089

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions airgun/entities/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,12 @@ def create_bookmark(self, values, search_query=None):
view.submit.click()
view.flash.assert_no_error()
view.flash.dismiss()

def search_menu(self, query: str) -> list[str]:
"""Perform a search of the vertical navigation menu.

:param str query: search query for the vertical navigation menu
:return list[str]: search results
"""
view = self.navigate_to(self, 'All')
return view.menu_search.search(query)
2 changes: 2 additions & 0 deletions airgun/views/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
ItemsList,
LCESelector,
Pf4ConfirmationDialog,
PF4NavSearch,
PF4Search,
ProgressBar,
ReadOnlyEntry,
Expand All @@ -40,6 +41,7 @@ class BaseLoggedInView(View):
"""Base view for Satellite pages"""

menu = Navigation("Global")
menu_search = PF4NavSearch()
taxonomies = ContextSelector()
flash = SatFlashMessages()
validations = ValidationErrors()
Expand Down
58 changes: 57 additions & 1 deletion airgun/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
VerticalNavigation,
)
from widgetastic_patternfly4 import Pagination as PF4Pagination
from widgetastic_patternfly4.ouia import BaseSelect, Button as PF4Button, Dropdown
from widgetastic_patternfly4.ouia import BaseSelect, Button as PF4Button, Dropdown, Menu
from widgetastic_patternfly4.progress import Progress as PF4Progress

from airgun.exceptions import DisabledWidgetError, ReadOnlyWidgetError
Expand Down Expand Up @@ -835,6 +835,62 @@ def search(self, value):
self.search_button.click()


class PF4NavSearchMenu(Menu):
"""PF4 vertical navigation dropdown menu with search results."""

@property
def items(self):
"""Return list of :py:class:`WebElement` items in the menu."""
return self.browser.elements(self.ITEMS_LOCATOR)

def read(self):
"""Return all items in the menu as strings."""
return [self.browser.text(el) for el in self.items]


class PF4NavSearch(PF4Search):
"""PF4 vertical navigation menu search"""

ROOT = '//div[@id="navigation-search"]'
search_field = TextInput(locator=(".//input[@aria-label='Search input']"))
search_button = Button(locator=(".//button[@aria-label='Search']"))
clear_button = Button(locator=(".//button[@aria-label='Reset']"))
items = PF4NavSearchMenu("navigation-search-menu")
results_timeout = 2

def _wait_for_results(self, results_widget):
"""Read the search results widget `results_widget` for `self.results_timeout` seconds
and return the values. If timeout is exceeded, empty list is returned.

:return: list[str] if values are returned; empty list otherwise
"""
return (
wait_for(
lambda: results_widget.read(),
timeout=self.results_timeout,
delay=0.5,
handle_exception=NoSuchElementException,
silent_failure=True,
)[0]
or []
)

def search(self, value):
"""Search the vertical navigation menu.
The first clear() is a workaround for inconsistent behaviour (mostly in Chrome),
where the previous value is sometimes still shown.
Clear the input field afterward, so it does not interfere with the regular navigation menu.

:param str value: search query
:return: list of search results as strings
"""
self.clear()
super().search(value)
results = self._wait_for_results(results_widget=self.items)
self.clear()
return results


class SatVerticalNavigation(VerticalNavigation):
"""The Patternfly Vertical navigation."""

Expand Down
Loading