File: test_listview_navigation.py

package info (click to toggle)
textual 2.1.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 55,084 kB
  • sloc: python: 85,423; lisp: 1,669; makefile: 101
file content (45 lines) | stat: -rw-r--r-- 1,360 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from textual.app import App, ComposeResult
from textual.widgets import Label, ListItem, ListView


class ListViewDisabledItemsApp(App[None]):
    def compose(self) -> ComposeResult:
        self.highlighted = []
        yield ListView(
            ListItem(Label("0"), disabled=True),
            ListItem(Label("1")),
            ListItem(Label("2"), disabled=True),
            ListItem(Label("3"), disabled=True),
            ListItem(Label("4")),
            ListItem(Label("5")),
            ListItem(Label("6"), disabled=True),
            ListItem(Label("7")),
            ListItem(Label("8"), disabled=True),
        )

    def _on_list_view_highlighted(self, message: ListView.Highlighted) -> None:
        if message.item is None:
            self.highlighted.append(None)
        else:
            self.highlighted.append(str(message.item.children[0].renderable))


async def test_keyboard_navigation_with_disabled_items() -> None:
    """Regression test for https://github.com/Textualize/textual/issues/3881."""

    app = ListViewDisabledItemsApp()
    async with app.run_test() as pilot:
        for _ in range(5):
            await pilot.press("down")
        for _ in range(5):
            await pilot.press("up")

    assert app.highlighted == [
        "1",
        "4",
        "5",
        "7",
        "5",
        "4",
        "1",
    ]