-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathintercom_reply_test.go
More file actions
69 lines (63 loc) · 2.15 KB
/
Copy pathintercom_reply_test.go
File metadata and controls
69 lines (63 loc) · 2.15 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"strings"
"testing"
tea "charm.land/bubbletea/v2"
)
// TestIntercomEmptyEnterNudges guards against the regression where hitting
// Enter on an empty intercom reply was a SILENT no-op. The banner reads
// "↵ reply", so users pressed Enter expecting it to reply, got nothing, then
// Esc'd out with the "[no reply]" nudge — see the worker run that failed at
// the contact_supervisor timeout. Empty Enter must now pulse a "type a reply"
// hint and must NOT send an intercom_reply (Esc still owns the "[no reply]").
func TestIntercomEmptyEnterNudges(t *testing.T) {
s := initialSession()
s.ready = true
s.width, s.height = 80, 24
s.authed = true
s.pendingIntercom = &intercomPrompt{
requestID: "ask-1",
from: "worker",
reason: "need_decision",
message: "A or B?",
}
s.input.SetValue("")
s.input.Focus()
s.layout()
// Empty Enter: must not clear the prompt (no reply sent) and must arm the nudge.
s.handleKey(tea.KeyPressMsg{Code: tea.KeyEnter})
if s.pendingIntercom == nil {
t.Fatal("empty Enter must NOT send an intercom_reply (pendingIntercom was cleared)")
}
if s.intercomNudge.IsZero() {
t.Fatal("empty Enter should arm the intercomNudge hint")
}
// The banner should surface the nudge while it is armed.
if got := s.renderIntercomBanner(); !strings.Contains(got, "type a reply") {
t.Fatalf("banner should show the nudge hint while armed; got %q", got)
}
}
// TestIntercomTypedEnterReplies ensures a non-empty Enter still takes the reply
// path: clears the prompt and the input (sendCore is a no-op without a core).
func TestIntercomTypedEnterReplies(t *testing.T) {
s := initialSession()
s.ready = true
s.width, s.height = 80, 24
s.authed = true
s.pendingIntercom = &intercomPrompt{
requestID: "ask-1",
from: "worker",
reason: "need_decision",
message: "A or B?",
}
s.input.SetValue("A")
s.input.Focus()
s.layout()
s.handleKey(tea.KeyPressMsg{Code: tea.KeyEnter})
if s.pendingIntercom != nil {
t.Fatal("typed Enter should send the reply and clear pendingIntercom")
}
if s.input.Value() != "" {
t.Fatalf("input should be cleared after sending the reply; got %q", s.input.Value())
}
}