返回 DeepSeek-Reasonix
chooser_digit_test.go
根目录 / internal / cli / chooser_digit_test.go
1 package cli
2
3 import (
4 "testing"
5
6 tea "charm.land/bubbletea/v2"
7
8 "reasonix/internal/control"
9 "reasonix/internal/event"
10 )
11
12 // TestChooserDigitKeysReachSpecialRows pins that number keys cover every
13 // numbered row — a real option, the "Type something" free-text row, and the
14 // "Chat about this" dismissal row — matching what Enter does on the same row.
15 func TestChooserDigitKeysReachSpecialRows(t *testing.T) {
16 ask := event.Ask{
17 ID: "ask-1",
18 Questions: []event.AskQuestion{{
19 ID: "q1",
20 Prompt: "Pick one",
21 Options: []event.AskOption{
22 {Label: "Option A"},
23 {Label: "Option B"},
24 },
25 }},
26 }
27 ctrl := control.New(control.Options{})
28 m := newChatTUI(ctrl, "", make(chan event.Event, 1), 80)
29
30 // Digit 1 = Option A (commits the single-select).
31 m.chooser = newChooser(ask)
32 mm, _ := m.handleChooserKey(tea.KeyPressMsg{Code: '1'})
33 if mm.(chatTUI).chooser != nil {
34 t.Fatal("digit 1 must select Option A and advance")
35 }
36
37 // Digit 3 = "Type something" (len(options)+1): opens free-text entry.
38 m.chooser = newChooser(ask)
39 mm, _ = m.handleChooserKey(tea.KeyPressMsg{Code: '3'})
40 cm := mm.(chatTUI)
41 if cm.chooser == nil || !cm.chooser.typing {
42 t.Fatal("digit 3 must open the Type-something free-text row")
43 }
44
45 // Digit 4 = "Chat about this" (len(options)+2): dismisses the prompt.
46 m.chooser = newChooser(ask)
47 mm, _ = m.handleChooserKey(tea.KeyPressMsg{Code: '4'})
48 if mm.(chatTUI).chooser != nil {
49 t.Fatal("digit 4 must dismiss the chooser (chat instead)")
50 }
51 }
52
52 lines GO