From 76272bcefe2630e88fc5522287f4980598aba3d7 Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Wed, 18 Jan 2023 10:42:42 +0000 Subject: [PATCH] Extend ListView test to test an empty inherited list For testing permutations of #1588. --- tests/listview/test_inherit_listview.py | 29 ++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/tests/listview/test_inherit_listview.py b/tests/listview/test_inherit_listview.py index bb9197646d..2f147a28a5 100644 --- a/tests/listview/test_inherit_listview.py +++ b/tests/listview/test_inherit_listview.py @@ -3,23 +3,42 @@ class MyListView(ListView): + """Test child class of a ListView.""" + + def __init__(self, items: int = 0) -> None: + super().__init__() + self._items = items + def compose(self) -> ComposeResult: """Compose the child widgets.""" - for n in range(20): - yield ListView(Label(f"This is item {n}")) + for n in range(self._items): + yield ListItem(Label(f"This is item {n}")) class ListViewApp(App[None]): """ListView test app.""" + def __init__(self, items: int = 0) -> None: + super().__init__() + self._items = items + def compose(self) -> ComposeResult: """Compose the child widgets.""" - yield MyListView() + yield MyListView(self._items) -async def test_inherited_list_view() -> None: - """A self-populating inherited ListView should work as normal.""" +async def test_empty_inherited_list_view() -> None: + """An empty self-populating inherited ListView should work as expected.""" async with ListViewApp().run_test() as pilot: + await pilot.press("tab") + assert pilot.app.query_one(MyListView).index is None + await pilot.press("down") + assert pilot.app.query_one(MyListView).index is None + + +async def test_populated_inherited_list_view() -> None: + """A self-populating inherited ListView should work as normal.""" + async with ListViewApp(30).run_test() as pilot: await pilot.press("tab") assert pilot.app.query_one(MyListView).index == 0 await pilot.press("down")