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

Select: add support for typeahead select #51

Merged
merged 1 commit into from
Feb 26, 2024
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ itteration of [widgetastic.patternfly4](https://github.com/RedHatQE/widgetastic.
- [menu-toggle](https://www.patternfly.org/components/menus/menu-toggle)
- [options-menu](https://www.patternfly.org/components/menus/options-menu/)
- [select](https://www.patternfly.org/components/menus/select)
- [typeahedselect](https://www.patternfly.org/components/menus/select/#typeahead)
- [modal](https://www.patternfly.org/components/modal)
- [navigation](https://www.patternfly.org/components/navigation)
- [pagination](https://www.patternfly.org/components/pagination/)
Expand Down
17 changes: 17 additions & 0 deletions src/widgetastic_patternfly5/components/menus/select.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from widgetastic.exceptions import NoSuchElementException
from widgetastic.widget import TextInput

from .dropdown import Dropdown
from .dropdown import DropdownItemDisabled
Expand Down Expand Up @@ -182,3 +183,19 @@ def items(self):

class CheckboxSelect(BaseCheckboxSelect, Dropdown):
DEFAULT_LOCATOR = './/div[contains(@class, "-c-select")][1]'


class BaseTypeaheadSelect(BaseSelect):
BUTTON_LOCATOR = (
".//button[(contains(@class, '-c-select__toggle') "
"or contains(@class, '-c-menu-toggle')) "
"and not(contains(@class, '-c-select__toggle-clear'))]"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider creating a separate locator for the clear button, and a function to click it.

)
input = TextInput(locator=".//input")

def read(self):
return self.browser.get_attribute("value", self.input)


class TypeaheadSelect(BaseTypeaheadSelect, Dropdown):
DEFAULT_LOCATOR = './/div[contains(@class, "-c-select")][1]'
5 changes: 5 additions & 0 deletions src/widgetastic_patternfly5/ouia.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from widgetastic_patternfly5.components.menus.menu import BaseCheckboxMenu
from widgetastic_patternfly5.components.menus.menu import BaseMenu
from widgetastic_patternfly5.components.menus.select import BaseSelect
from widgetastic_patternfly5.components.menus.select import BaseTypeaheadSelect
from widgetastic_patternfly5.components.modal import BaseModal
from widgetastic_patternfly5.components.navigation import BaseNavigation
from widgetastic_patternfly5.components.pagination import BaseCompactPagination
Expand Down Expand Up @@ -129,5 +130,9 @@ class Select(BaseSelect, Dropdown):
OUIA_COMPONENT_TYPE = "Select"


class TypeaheadSelect(BaseTypeaheadSelect, Dropdown):
OUIA_COMPONENT_TYPE = "Select"


class ClipboardCopy(BaseClipboardCopy, OUIAGenericWidget):
OUIA_COMPONENT_TYPE = "ClipboardCopy"
49 changes: 49 additions & 0 deletions testing/components/menus/test_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from widgetastic_patternfly5 import CheckboxSelect
from widgetastic_patternfly5 import Select
from widgetastic_patternfly5 import SelectItemNotFound
from widgetastic_patternfly5.components.menus.select import TypeaheadSelect

TESTING_PAGE_URL = "https://patternfly-react-main.surge.sh/components/menus/select"

Expand Down Expand Up @@ -83,3 +84,51 @@ def test_checkbox_select_item_checkbox_select(checkbox_select):
with pytest.raises(SelectItemNotFound):
checkbox_select.fill({"Non existing item": True})
assert not checkbox_select.is_open


@pytest.fixture
def typeahead_select(browser):
class TestView(View):
typeahead_select = TypeaheadSelect(locator=".//div[@id='ws-react-c-select-typeahead']")

return TestView(browser).typeahead_select


def test_typeahead_select_is_displayed(typeahead_select):
assert typeahead_select.is_displayed


def test_typeahead_select_items(typeahead_select):
assert set(typeahead_select.items) == {
"Alabama",
"Florida",
"New Jersey",
"New Mexico",
"New York",
"North Carolina",
}
assert typeahead_select.has_item("Alabama")
assert not typeahead_select.has_item("Non existing item")
assert typeahead_select.item_enabled("Alabama")


def test_typeahead_select_open(typeahead_select):
assert not typeahead_select.is_open
typeahead_select.open()
assert typeahead_select.is_open
typeahead_select.close()
assert not typeahead_select.is_open


def test_typeahead_select_item_select(typeahead_select):
typeahead_select.fill("New Mexico")
assert typeahead_select.read() == "New Mexico"
assert not typeahead_select.is_open
# try again to verify it works when an item was selected previously (or in
# case there is a default value)
typeahead_select.fill("Florida")
assert typeahead_select.read() == "Florida"
assert not typeahead_select.is_open
with pytest.raises(SelectItemNotFound):
typeahead_select.fill("Non existing item")
assert not typeahead_select.is_open
Loading