-
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 #36 from digitronik/card_view
Card views
- Loading branch information
Showing
4 changed files
with
140 additions
and
21 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,97 @@ | ||
import pytest | ||
from widgetastic.widget import View | ||
from widgetastic.widget import ParametrizedView | ||
from widgetastic.widget import Text | ||
|
||
from widgetastic_patternfly5 import Card | ||
from widgetastic_patternfly5 import CardCheckBox | ||
from widgetastic_patternfly5 import CardForCardGroup | ||
from widgetastic_patternfly5 import CardGroup | ||
from widgetastic_patternfly5 import CardWithActions | ||
from widgetastic_patternfly5 import Dropdown | ||
|
||
TESTING_PAGE_URL = "https://patternfly-react-main.surge.sh/components/card" | ||
TESTING_PAGE_URL = ( | ||
"https://patternfly-react-main.surge.sh/patterns/card-view/react-demos/card-view/" | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def view(browser): | ||
class TestView(View): | ||
card = Card(locator='.//div[@id="ws-react-c-card-basic-cards"]') | ||
card_with_actions = CardWithActions( | ||
locator='.//div[@id="ws-react-c-card-header-images-and-actions"]' | ||
) | ||
def pfy_card(browser): | ||
return CardWithActions(browser, locator='.//div[@id="PatternFly"]') | ||
|
||
return TestView(browser) | ||
|
||
def test_cards_displayed(pfy_card): | ||
assert pfy_card.wait_displayed() | ||
|
||
def test_cards_displayed(view): | ||
assert view.card.is_displayed | ||
assert view.card_with_actions.is_displayed | ||
|
||
def test_card_content(pfy_card): | ||
assert pfy_card.title == "PatternFly" | ||
assert pfy_card.body.text == ( | ||
"PatternFly is a community project that promotes design commonality and " | ||
"improves user experience." | ||
) | ||
|
||
def test_card_content(view): | ||
assert view.card.title == "Title" | ||
assert view.card.body.text == "Body" | ||
assert view.card.footer.text == "Footer" | ||
|
||
def test_card_actionable_items_displayed(pfy_card): | ||
assert pfy_card.dropdown.is_displayed | ||
assert pfy_card.checkbox.is_displayed | ||
|
||
def test_card_actionable_items_displayed(view): | ||
assert view.card_with_actions.dropdown.is_displayed | ||
assert view.card_with_actions.checkbox.is_displayed | ||
|
||
class PageCard(CardForCardGroup): | ||
dropdown = Dropdown(locator=".//div[contains(@class, '-c-card__actions')]") | ||
|
||
def delete_action(self): | ||
self.dropdown.item_select("Delete") | ||
|
||
checked = CardCheckBox() | ||
|
||
header_text = Text(locator=".//div[contains(@class, '-c-card__title')]") | ||
|
||
|
||
class Cards(CardGroup): | ||
def __init__(self, parent, locator=None, logger=None, **kwargs): | ||
super().__init__(parent, logger=logger, **kwargs) | ||
self.locator = locator or './/div[contains(@class, "pf-v5-l-gallery")]' | ||
|
||
cards = ParametrizedView.nested(PageCard) | ||
|
||
|
||
@pytest.fixture | ||
def cards(browser): | ||
cards = Cards(browser) | ||
cards.wait_displayed("15s") | ||
return cards | ||
|
||
|
||
def test_read_and_drop_second_card(cards, browser): | ||
second = [*cards][1] | ||
|
||
assert second.header_text.read() == "PatternFly" | ||
|
||
second.delete_action() | ||
|
||
new_second = [*cards][1] | ||
|
||
assert new_second.header_text.read() != "PatternFly" | ||
# refresh to get it back :) | ||
browser.refresh() | ||
|
||
|
||
def read_cards_2_checkmap(cards): | ||
data = cards.cards.read() | ||
return {card["header_text"]: card["checked"] for card in list(data.values())[1:]} | ||
|
||
|
||
def test_select_all_cards(browser, cards): | ||
name2checked = read_cards_2_checkmap(cards) | ||
assert not any(name2checked.values()) | ||
assert all(name2checked.keys()) | ||
|
||
# first card doesn't have header and checkbox | ||
for card in list(cards)[1:]: | ||
browser.execute_script("arguments[0].scrollIntoView({block: 'center'});", card.checked) | ||
card.checked.fill(True) | ||
|
||
name2checked_after = read_cards_2_checkmap(cards) | ||
assert all(name2checked_after.values()) | ||
assert all(name2checked_after.keys()) | ||
|
||
assert name2checked.keys() == name2checked_after.keys() |