From df95e7034df683c38fde67890430ab4c2abfa4ba Mon Sep 17 00:00:00 2001 From: historia Date: Wed, 26 Aug 2026 18:39:33 -0400 Subject: feat: in-place toggle field, updated transcription tui to use new field --- app/tests/test_tui.py | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'app/tests/test_tui.py') diff --git a/app/tests/test_tui.py b/app/tests/test_tui.py index b839a71..7821ebb 100644 --- a/app/tests/test_tui.py +++ b/app/tests/test_tui.py @@ -684,6 +684,58 @@ class FormTests(TuiTestCase): result = tui.form(screen, "Settings", fields) self.assertEqual(result, {"combine": True}) + def test_toggle_field_cycles_with_enter(self): + # Enter steps the toggle to its next choice in place (no menu + # opens), Tab -> button, Enter saves. + fields = [{"key": "transcripts", "label": "Transcripts", + "kind": "toggle", "value": "missing", + "choices": [("New voices", "missing"), + ("All voices", "all")]}] + screen = FakeScreen(keys=[10, 9, 10]) + result = tui.form(screen, "Settings", fields) + self.assertEqual(result, {"transcripts": "all"}) + + def test_toggle_field_cycles_with_space(self): + fields = [{"key": "transcripts", "label": "Transcripts", + "kind": "toggle", "value": "missing", + "choices": [("New voices", "missing"), + ("All voices", "all")]}] + screen = FakeScreen(keys=[ord(" "), 9, 10]) + result = tui.form(screen, "Settings", fields) + self.assertEqual(result, {"transcripts": "all"}) + + def test_toggle_field_last_choice_wraps_to_the_first(self): + fields = [{"key": "transcripts", "label": "Transcripts", + "kind": "toggle", "value": "all", + "choices": [("New voices", "missing"), + ("All voices", "all")]}] + screen = FakeScreen(keys=[10, 9, 10]) + result = tui.form(screen, "Settings", fields) + self.assertEqual(result, {"transcripts": "missing"}) + + def test_toggle_field_renders_the_matching_label(self): + fields = [{"key": "transcripts", "label": "Transcripts", + "kind": "toggle", "value": "missing", + "choices": [("New voices", "missing"), + ("All voices", "all")]}] + screen = FakeScreen(keys=[9, 10]) # straight to Save + tui.form(screen, "Settings", fields) + texts = [text for _, _, text, _ in screen.strings] + self.assertTrue(any("New voices" in text for text in texts)) + self.assertFalse(any("All voices" in text for text in texts)) + + def test_toggle_field_fires_on_change(self): + calls = [] + fields = [{"key": "transcripts", "label": "Transcripts", + "kind": "toggle", "value": "missing", + "choices": [("New voices", "missing"), + ("All voices", "all")], + "on_change": lambda fs: calls.append(1)}] + screen = FakeScreen(keys=[10, 9, 10]) + result = tui.form(screen, "Settings", fields) + self.assertEqual(calls, [1]) + self.assertEqual(result, {"transcripts": "all"}) + def test_hidden_field_keeps_value_and_is_not_drawn(self): fields = self._fields() fields.append({"key": "hidden", "label": "Secret", "kind": "text", -- cgit v1.2.3