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

Modify BootstrapNav TEXT_DISABLED #114

Merged
merged 2 commits into from
Dec 11, 2019
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
8 changes: 6 additions & 2 deletions src/widgetastic_patternfly/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,9 @@ class BootstrapNav(Widget):
PARTIAL_TEXT = './/li/a[contains(normalize-space(.), {txt})]'
ATTR_MATCHING = './/li/a[@{attr}={txt}]'
TEXT_DISABLED = './/li[contains(@class, "disabled")]/a[text()={txt}]'
PARTIAL_TEXT_DISABLED = (
'.//li[contains(@class, "disabled")]/a[contains(normalize-space(.), {txt})]'
)
ATTR_DISABLED = './/li[contains(@class, "disabled")]/a[@{attr}={txt}]'
VALID_ATTRS = {'href', 'title', 'class', 'id'}

Expand Down Expand Up @@ -575,8 +578,9 @@ def is_disabled(self, text=None, **kwargs):
# Check if an item is disabled based on the text of that item
if isinstance(text, partial_match):
partial_text = text.item
text = self.browser.element(self.PARTIAL_TEXT.format(txt=quote(partial_text))).text
xpath = self.TEXT_DISABLED.format(txt=quote(text))
xpath = self.PARTIAL_TEXT_DISABLED.format(txt=quote(partial_text))
else:
xpath = self.TEXT_DISABLED.format(txt=quote(text))
elif self.VALID_ATTRS & set(kwargs.keys()):
# Check if an item is disabled based on an attribute, if it is one of the VALID_ATTRS
attr = (self.VALID_ATTRS & set(kwargs.keys())).pop()
Expand Down
1 change: 1 addition & 0 deletions testing/test_bootstrap_nav.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class TestView(View):
"ALL (Default)",
"Environment / Dev",
"Environment / Prod",
"UAT",
"Environment / UAT",
"",
]
Expand Down
3 changes: 3 additions & 0 deletions testing/testing_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,9 @@ <h4 class="modal-title" id="myModalLabel">Modal Title</h4>
<li class="">
<a href="#">Environment / Prod</a>
</li>
<li class="">
<a href="#">UAT</a>
</li>
<li class="disabled">
<a href="#">Environment / UAT</a>
</li>
Expand Down