Add some unit testing of the new navigation

This commit is contained in:
Dave Pearson
2023-04-25 12:06:46 +01:00
parent e16493bf81
commit a6a373161f

View File

@@ -52,6 +52,34 @@ async def test_radio_sets_toggle():
] ]
async def test_radioset_inner_navigation():
"""Using the cursor keys should navigate between buttons in a set."""
async with RadioSetApp().run_test() as pilot:
assert pilot.app.screen.focused is None
await pilot.press("tab")
assert (
pilot.app.screen.focused == pilot.app.query_one("#from_buttons").children[0]
)
for key, landing in (("down", 1), ("up", 0), ("right", 1), ("left", 0)):
await pilot.press(key)
assert (
pilot.app.screen.focused
== pilot.app.query_one("#from_buttons").children[landing]
)
async def test_radioset_breakout_navigation():
"""Shift/Tabbing while in a radioset should move to the previous/next focsuable after the set itself."""
async with RadioSetApp().run_test() as pilot:
assert pilot.app.screen.focused is None
await pilot.press("tab")
assert pilot.app.screen.focused.parent is pilot.app.query_one("#from_buttons")
await pilot.press("tab")
assert pilot.app.screen.focused.parent is pilot.app.query_one("#from_strings")
await pilot.press("shift+tab")
assert pilot.app.screen.focused.parent is pilot.app.query_one("#from_buttons")
class BadRadioSetApp(App[None]): class BadRadioSetApp(App[None]):
def compose(self) -> ComposeResult: def compose(self) -> ComposeResult:
with RadioSet(): with RadioSet():