Skip to content

Commit

Permalink
Vertical navigation search widget & function
Browse files Browse the repository at this point in the history
Added new widget(s) for PF4 vertical navigation search.

New method `BaseEntity.search_menu()`.
  • Loading branch information
pnovotny committed Dec 13, 2023
1 parent d68431f commit 5a72feb
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
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
40 changes: 39 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,44 @@ 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")

def search(self, value):
"""Search the vertical navigation menu.
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
"""
super().search(value)
try:
results = self.items.read()
self.clear()
except NoSuchElementException:
results = []
return results


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

Expand Down

0 comments on commit 5a72feb

Please sign in to comment.