-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from jrusz/expandable-section
Add Expandable section
- Loading branch information
Showing
4 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/widgetastic_patternfly5/components/expandable_section.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from wait_for import wait_for_decorator | ||
from widgetastic.widget import View | ||
|
||
|
||
class ExpandableSection(View): | ||
"""Represents the Patternfly Expandable section widget. | ||
Expands itself automatically when any child widget gets accessed, ensuring | ||
that the widget is visible. | ||
https://www.patternfly.org/components/expandable-section | ||
NOTE: When using this in your code you need to set the ROOT yourself! | ||
Example code with a button underneath the section: | ||
class MySection(ExpandableSection): | ||
ROOT = ".//div[contains(@data-testid, 'my-expandable-section')]" | ||
my-button = Button(locator=".//button") | ||
After creating the view you can run `MySection.my-button.click()` and it | ||
will automatically expand and click on your button. | ||
""" | ||
|
||
ROOT = './/div[contains(@class, "-c-expandable-section")]' | ||
BUTTON_LOCATOR = ".//button" | ||
|
||
@property | ||
def is_expanded(self): | ||
"""Returns a boolean.""" | ||
if self.browser.get_attribute("aria-expanded", self.BUTTON_LOCATOR) == "true": | ||
return True | ||
else: | ||
return False | ||
|
||
def click(self): | ||
"""Clicks the expandable section button.""" | ||
return self.browser.click(self.BUTTON_LOCATOR) | ||
|
||
def expand(self): | ||
"""Expands the section (checks if not expanded already first).""" | ||
if not self.is_expanded: | ||
|
||
@wait_for_decorator(timeout=3) | ||
def _click(): | ||
self.click() | ||
return self.is_expanded | ||
|
||
def collapse(self): | ||
"""Collapses the section (checks if expanded already first).""" | ||
if self.is_expanded: | ||
|
||
@wait_for_decorator(timeout=3) | ||
def _click(): | ||
self.click() | ||
return not self.is_expanded | ||
|
||
def child_widget_accessed(self, widget): | ||
# Expand the section | ||
self.expand() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from widgetastic.widget import Text | ||
from widgetastic.widget import View | ||
|
||
from widgetastic_patternfly5 import ExpandableSection | ||
|
||
TESTING_PAGE_URL = "https://patternfly-react-main.surge.sh/components/expandable-section" | ||
|
||
|
||
class SectionView(View): | ||
@View.nested | ||
class basic(ExpandableSection): | ||
text = Text(".//div[contains(@class, '-c-expandable-section__content')]") | ||
|
||
|
||
def test_section_expansion(browser): | ||
view = SectionView(browser) | ||
view.basic.expand() | ||
assert view.basic.is_expanded | ||
view.basic.collapse() | ||
assert not view.basic.is_expanded | ||
|
||
|
||
def test_section_text(browser): | ||
view = SectionView(browser) | ||
assert view.basic.is_displayed | ||
assert view.basic.text.is_displayed | ||
assert view.basic.text.read() == "This content is visible only when the component is expanded." | ||
view.basic.collapse() |