diff options
Diffstat (limited to 'app/tests/test_tui.py')
| -rw-r--r-- | app/tests/test_tui.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/app/tests/test_tui.py b/app/tests/test_tui.py index ce408af..49960a1 100644 --- a/app/tests/test_tui.py +++ b/app/tests/test_tui.py @@ -857,6 +857,37 @@ class CheckboxTreeTests(TuiTestCase): 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]) + 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]) + tui.checkbox_tree(screen, "Pick models", self.FAMILIES, + checked={(0, "pkg-b")}) + texts = [text for _, _, text, _ in screen.strings] + # The pre-checked option row (indented) draws its box checked. + self.assertIn("[x] ", texts) + # ...and the family row is expanded (its options are listed). + self.assertIn("- Family one", texts) + + 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]) + picked = tui.checkbox_tree( + screen, "Pick models", self.FAMILIES, + checked={(1, "pkg-c")}) + self.assertEqual(picked, [(1, "pkg-c")]) + def test_empty_families_rejected(self): with self.assertRaises(ValueError): tui.checkbox_tree(self.screen, "Pick", []) |
