aboutsummaryrefslogtreecommitdiff
path: root/app/tests/test_tui.py
diff options
context:
space:
mode:
Diffstat (limited to 'app/tests/test_tui.py')
-rw-r--r--app/tests/test_tui.py67
1 files changed, 48 insertions, 19 deletions
diff --git a/app/tests/test_tui.py b/app/tests/test_tui.py
index d5cbb7e..7c9c800 100644
--- a/app/tests/test_tui.py
+++ b/app/tests/test_tui.py
@@ -744,16 +744,36 @@ class CheckboxTreeTests(TuiTestCase):
"options": [{"key": "pkg-c", "label": "pkg-c", "recommended": True}]},
]
- def test_nothing_selected_by_default(self):
- # Nothing is pre-checked: Enter alone flashes and waits, and a
- # selection only happens after Space checks an option. The first
- # Enter and the flash each consume a key.
- screen = FakeScreen(keys=[10, 10, ord(" "), 10])
+ def test_all_nodes_start_collapsed(self):
+ # Nothing is pre-checked and no family is expanded on the initial
+ # draw: only family rows are visible, each with a '+' collapse
+ # arrow, and no option rows are drawn.
+ screen = FakeScreen(keys=[27]) # Esc aborts after the first draw
+ with self.assertRaises(tui.WizardCancelled):
+ tui.checkbox_tree(screen, "Pick models", self.FAMILIES)
+ texts = [text for _, _, text, _ in screen.strings]
+ self.assertIn("+ Family one", texts)
+ self.assertIn("+ Family two", texts)
+ for label in ("pkg-a", "pkg-b", "pkg-c"):
+ self.assertNotIn(label, texts)
+
+ def test_enter_checks_like_space(self):
+ # Enter on a family row checks its recommended option, exactly
+ # like Space; Tab then Confirm accepts the selection.
+ screen = FakeScreen(keys=[10, 9, 10])
+ picked = tui.checkbox_tree(screen, "Pick models", self.FAMILIES)
+ self.assertEqual(picked, [(0, "pkg-a")])
+
+ def test_confirm_without_selection_flashes(self):
+ # Confirm with nothing checked flashes and stays; the user then
+ # checks a model and confirms for real.
+ keys = [9, 10, ord(" "), 9, 10, 9, 10]
+ screen = FakeScreen(keys=keys)
picked = tui.checkbox_tree(screen, "Pick models", self.FAMILIES)
self.assertEqual(picked, [(0, "pkg-a")])
def test_rows_left_justified_inside_the_border(self):
- screen = FakeScreen(keys=[ord(" "), 10])
+ screen = FakeScreen(keys=[ord(" "), 9, 10])
tui.checkbox_tree(screen, "Pick models", self.FAMILIES)
x0, x_right = self.dialog_box(screen)
margin = x0 + 1 + tui.Frame.LIST_MARGIN
@@ -776,27 +796,27 @@ class CheckboxTreeTests(TuiTestCase):
families = [{"label": "F", "detail": "tts",
"options": [{"key": "long", "label": "x" * 60,
"recommended": True}]}]
- screen = FakeScreen(keys=[ord(" "), 10], width=120)
+ screen = FakeScreen(keys=[ord(" "), 9, 10], width=120)
picked = tui.checkbox_tree(screen, "Pick", families)
self.assertEqual(picked, [(0, "long")])
self.assert_inside_border(screen)
- def test_space_checks_then_enter_accepts(self):
- screen = FakeScreen(keys=[ord(" "), 10])
+ def test_space_checks_then_confirm_accepts(self):
+ screen = FakeScreen(keys=[ord(" "), 9, 10])
picked = tui.checkbox_tree(screen, "Pick models", self.FAMILIES)
self.assertEqual(picked, [(0, "pkg-a")])
- def test_prechecked_selection_accepted_directly(self):
- # checked= seeds the tree (modify flow): Enter alone accepts the
- # pre-checked option without any key presses in between.
- screen = FakeScreen(keys=[10])
+ def test_prechecked_selection_confirmed(self):
+ # checked= seeds the tree (modify flow): Tab then Confirm accepts
+ # the pre-checked options without any extra key presses.
+ screen = FakeScreen(keys=[9, 10])
picked = tui.checkbox_tree(
screen, "Pick models", self.FAMILIES,
checked={(0, "pkg-b"), (1, "pkg-c")})
self.assertEqual(picked, [(0, "pkg-b"), (1, "pkg-c")])
def test_prechecked_options_draw_as_checked(self):
- screen = FakeScreen(keys=[10])
+ screen = FakeScreen(keys=[9, 10])
tui.checkbox_tree(screen, "Pick models", self.FAMILIES,
checked={(0, "pkg-b")})
texts = [text for _, _, text, _ in screen.strings]
@@ -807,16 +827,25 @@ class CheckboxTreeTests(TuiTestCase):
def test_prechecked_family_cursor_starts_on_it(self):
# Only the second family is pre-checked, so the cursor starts on it:
- # Space clears then re-checks that family (the cursor never moves).
- # If the cursor were still on the first family, the two Spaces would
- # check then clear family one and Enter would flash instead of
- # accepting anything.
- screen = FakeScreen(keys=[ord(" "), ord(" "), 10])
+ # two Spaces clear then re-check that family (the cursor never
+ # moves). If the cursor were still on the first family, the two
+ # Spaces would check then clear family one and Confirm would flash
+ # instead of accepting anything.
+ screen = FakeScreen(keys=[ord(" "), ord(" "), 9, 10])
picked = tui.checkbox_tree(
screen, "Pick models", self.FAMILIES,
checked={(1, "pkg-c")})
self.assertEqual(picked, [(1, "pkg-c")])
+ def test_back_button_returns_back_value(self):
+ marker = object()
+ # Tab -> buttons, Right -> Back, Enter.
+ screen = FakeScreen(keys=[9, FakeCurses.KEY_RIGHT, 10])
+ self.assertIs(
+ tui.checkbox_tree(screen, "Pick models", self.FAMILIES,
+ back_value=marker),
+ marker)
+
def test_empty_families_rejected(self):
with self.assertRaises(ValueError):
tui.checkbox_tree(self.screen, "Pick", [])