Skip to content

Commit

Permalink
is_visible.py
Browse files Browse the repository at this point in the history
  • Loading branch information
bandophahita committed Feb 26, 2024
1 parent 2976de2 commit 16f1db1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
16 changes: 9 additions & 7 deletions screenpy_selenium/resolutions/is_visible.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,27 @@

from typing import TYPE_CHECKING

from screenpy.resolutions.base_resolution import BaseResolution
from screenpy import beat

from .custom_matchers import is_visible_element

if TYPE_CHECKING:
from .custom_matchers.is_visible_element import IsVisibleElement


class IsVisible(BaseResolution):
class IsVisible:
"""Match on a visible element.
Examples::
the_actor.should(See.the(Element(WELCOME_BANNER), IsVisible()))
"""

matcher: IsVisibleElement
line = "visible"
matcher_function = is_visible_element
def describe(self) -> str:
"""Describe the Resolution's expectation."""
return "visible"

def __init__(self) -> None: # pylint: disable=useless-super-delegation
super().__init__()
@beat("... hoping it's visible")
def resolve(self) -> IsVisibleElement:
"""Produce the Matcher to make the assertion."""
return is_visible_element()
18 changes: 12 additions & 6 deletions tests/test_resolutions.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def test_matches_a_clickable_element(self) -> None:
element.is_displayed.return_value = True
ic = IsClickable().resolve()

assert ic.matches(element)
assert ic._matches(element)

def test_does_not_match_unclickable_element(self) -> None:
invisible_element = get_mocked_element()
Expand Down Expand Up @@ -121,14 +121,14 @@ def test_can_be_instantiated(self) -> None:
def test_matches_a_visible_element(self) -> None:
element = get_mocked_element()
element.is_displayed.return_value = True
iv = IsVisible()
iv: IsVisibleElement = IsVisible().resolve()

assert iv._matches(element)

def test_does_not_match_invisible_element(self) -> None:
element = get_mocked_element()
element.is_displayed.return_value = False
iv = IsVisible()
iv = IsVisible().resolve()

assert not iv._matches(None) # element was not found by Element()
assert not iv._matches(element)
Expand All @@ -141,14 +141,16 @@ def test_descriptions(self) -> None:
describe_mismatch="was not visible",
describe_none="was not even present",
)
iv = IsVisible()

_assert_descriptions(IsVisible(), element, expected)
assert iv.describe() == "visible"
_assert_descriptions(iv.resolve(), element, expected)

def test_type_hint(self) -> None:
iv = IsVisible()
annotation = iv.__annotations__["matcher"]
annotation = iv.resolve.__annotations__["return"]
assert annotation == "IsVisibleElement"
assert type(iv.matcher) == IsVisibleElement
assert type(iv.resolve()) == IsVisibleElement


class TestIsInvisible:
Expand Down Expand Up @@ -197,6 +199,10 @@ def test_descriptions(self) -> None:
assert describe_mismatch.out == expected.describe_mismatch
assert describe_none.out == expected.describe_none

ii = IsInvisible()

assert ii.describe() == "invisible"

def test_type_hint(self) -> None:
ii = IsInvisible()
annotation = ii.resolve.__annotations__["return"]
Expand Down

0 comments on commit 16f1db1

Please sign in to comment.