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
46
47
48
49
50
51
from __future__ import annotations
from unittest.mock import MagicMock, patch
from pyratatui import Rect
from pygittools.tui.keys import key
from pygittools.tui.tasks_list import TasksBoardList, _Row
from pygittools.tui.types import PageContext
def test_draw_error_offsets_list_selection() -> None:
tasks = TasksBoardList()
tasks._rows = [
_Row(kind="board", status=None, task_ref=None, label="Board: Tasks (0 tasks)"),
_Row(kind="status_header", status="todo", task_ref=None, label="[v] Todo (0)"),
]
tasks._list_state.select(0)
tasks._error = "sync failed"
frame = MagicMock()
tasks.draw(frame, Rect(0, 0, 80, 20), highlight=True)
assert frame.render_stateful_list.called
list_state = frame.render_stateful_list.call_args.args[2]
assert list_state.selected == 1
assert (tasks._list_state.selected or 0) == 0
def test_collapse_rebuilds_without_git(page_ctx: PageContext) -> None:
tasks = TasksBoardList()
tasks._boards = [{"name": "Tasks", "description": "", "task_count": 1}]
tasks._board_index = 0
tasks._board_name = "Tasks"
tasks._columns = [
{
"status": "TODO",
"label": "Todo",
"tasks": [{"title": "one", "ref": "refs/tasks/one"}],
},
]
tasks._rebuild_rows()
header = next(index for index, row in enumerate(tasks._rows) if row.kind == "status_header")
tasks._list_state.select(header)
with (
patch("pygittools.tui.tasks_list.list_boards") as list_boards,
patch("pygittools.tui.tasks_list.get_board_tasks_grouped") as grouped,
):
tasks.handle_nav_key(key(" "), page_ctx.repo)
list_boards.assert_not_called()
grouped.assert_not_called()
assert all(row.kind != "task" for row in tasks._rows)