mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Improve OptionList test coverage (#2701)
* Cover the penultimate uncovered line in OptionList Sort of moot, but worth a test that the control of a message is the option list. * Test OptionList hover over disabled option I *would* have liked to have tested this sort of thing via snapshot tests, but it seems that pilot.hover isn't quite behaving as desired there. But this provides a useful test anyway.
This commit is contained in:
@@ -13,7 +13,9 @@ class OptionListApp(App[None]):
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
yield Label("Something else to hover over")
|
||||
yield OptionList(*[Option(str(n), id=str(n)) for n in range(10)])
|
||||
yield OptionList(
|
||||
*[Option(str(n), id=str(n), disabled=n == 3) for n in range(10)]
|
||||
)
|
||||
|
||||
|
||||
async def test_no_hover() -> None:
|
||||
@@ -41,6 +43,18 @@ async def test_hover_no_highlight() -> None:
|
||||
assert option_list._mouse_hovering_over != option_list.highlighted
|
||||
|
||||
|
||||
async def test_hover_disabled() -> None:
|
||||
"""The mouse hover value should react to the mouse hover over a disabled option."""
|
||||
async with OptionListApp().run_test() as pilot:
|
||||
await pilot.hover(OptionList, Offset(1, 3))
|
||||
option_list = pilot.app.query_one(OptionList)
|
||||
assert option_list._mouse_hovering_over == 3
|
||||
assert option_list.get_option_at_index(
|
||||
option_list._mouse_hovering_over
|
||||
).disabled
|
||||
assert option_list._mouse_hovering_over != option_list.highlighted
|
||||
|
||||
|
||||
async def test_hover_then_leave() -> None:
|
||||
"""After a mouse has been over an OptionList and left _mouse_hovering_over should be None again."""
|
||||
async with OptionListApp().run_test() as pilot:
|
||||
|
||||
@@ -20,6 +20,7 @@ class OptionListApp(App[None]):
|
||||
|
||||
def _record(self, event: OptionList.OptionMessage) -> None:
|
||||
assert isinstance(event.option_id, str)
|
||||
assert event.option_list is event.control
|
||||
self.messages.append(
|
||||
(event.__class__.__name__, event.option_id, event.option_index)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user