Skip to content

Commit a14e469

Browse files
authored
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.
1 parent 0849e6f commit a14e469

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

tests/option_list/test_option_list_mouse_hover.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ class OptionListApp(App[None]):
1313

1414
def compose(self) -> ComposeResult:
1515
yield Label("Something else to hover over")
16-
yield OptionList(*[Option(str(n), id=str(n)) for n in range(10)])
16+
yield OptionList(
17+
*[Option(str(n), id=str(n), disabled=n == 3) for n in range(10)]
18+
)
1719

1820

1921
async def test_no_hover() -> None:
@@ -41,6 +43,18 @@ async def test_hover_no_highlight() -> None:
4143
assert option_list._mouse_hovering_over != option_list.highlighted
4244

4345

46+
async def test_hover_disabled() -> None:
47+
"""The mouse hover value should react to the mouse hover over a disabled option."""
48+
async with OptionListApp().run_test() as pilot:
49+
await pilot.hover(OptionList, Offset(1, 3))
50+
option_list = pilot.app.query_one(OptionList)
51+
assert option_list._mouse_hovering_over == 3
52+
assert option_list.get_option_at_index(
53+
option_list._mouse_hovering_over
54+
).disabled
55+
assert option_list._mouse_hovering_over != option_list.highlighted
56+
57+
4458
async def test_hover_then_leave() -> None:
4559
"""After a mouse has been over an OptionList and left _mouse_hovering_over should be None again."""
4660
async with OptionListApp().run_test() as pilot:

tests/option_list/test_option_messages.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def compose(self) -> ComposeResult:
2020

2121
def _record(self, event: OptionList.OptionMessage) -> None:
2222
assert isinstance(event.option_id, str)
23+
assert event.option_list is event.control
2324
self.messages.append(
2425
(event.__class__.__name__, event.option_id, event.option_index)
2526
)

0 commit comments

Comments
 (0)