-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinput_test.go
More file actions
44 lines (36 loc) · 1018 Bytes
/
Copy pathinput_test.go
File metadata and controls
44 lines (36 loc) · 1018 Bytes
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
package tui
import (
"testing"
tea "github.com/charmbracelet/bubbletea"
)
func TestInputSetHandlerUpdatesOriginalModel(t *testing.T) {
model := NewInput("title")
returned := model.SetHandler(func() {})
if returned != model {
t.Fatalf("SetHandler returned a different model pointer")
}
if model.handler == nil {
t.Fatalf("SetHandler did not update the original model")
}
}
func TestInputEnterDefersHandlerUntilRunCompletes(t *testing.T) {
model := NewInput("title")
called := 0
model = model.SetHandler(func() {
called++
})
_, _ = model.Update(tea.KeyMsg{Type: tea.KeyEnter})
if called != 0 {
t.Fatalf("handler called during Update, want deferred execution")
}
if !model.handlerPending {
t.Fatalf("handlerPending = false, want true after enter")
}
model.runPendingHandler()
if called != 1 {
t.Fatalf("handler call count = %d, want 1 after pending handler runs", called)
}
if model.handlerPending {
t.Fatalf("handlerPending = true, want false after pending handler runs")
}
}