-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtui_test.go
100 lines (84 loc) · 2.09 KB
/
tui_test.go
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package main
import (
"bytes"
"os"
"os/exec"
"testing"
"time"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/x/exp/teatest"
)
func withUntrackedFile(d string) error {
cmd := exec.Command("touch", "foo.txt")
cmd.Dir = d
err := cmd.Run()
if err != nil {
return err
}
return nil
}
func TestSearchOutput(t *testing.T) {
d, err := os.MkdirTemp(os.TempDir(), "test")
if err != nil {
t.Error(err)
}
defer os.RemoveAll(d)
cmd := exec.Command("git", "init")
cmd.Dir = d
err = cmd.Run()
if err != nil {
t.Error(err)
}
err = withUntrackedFile(d)
if err != nil {
t.Error(err)
}
tm := teatest.NewTestModel(t, initialModel(d), teatest.WithInitialTermSize(300, 100))
if err != nil {
t.Error(err)
}
teatest.WaitFor(t, tm.Output(), func(bts []byte) bool {
return bytes.Contains(bts, []byte("1 file to commit"))
}, teatest.WithCheckInterval(time.Millisecond*100), teatest.WithDuration(time.Second*3))
tm.Send(tea.KeyMsg{
Type: tea.KeyRunes,
Runes: []rune("q"),
})
tm.WaitFinished(t, teatest.WithFinalTimeout(time.Second))
}
func TestUpdate(t *testing.T) {
d, err := os.MkdirTemp(os.TempDir(), "test")
if err != nil {
t.Error(err)
}
defer os.RemoveAll(d)
cmd := exec.Command("git", "init")
cmd.Dir = d
err = cmd.Run()
if err != nil {
t.Error(err)
}
tm := teatest.NewTestModel(t, initialModel(d), teatest.WithInitialTermSize(300, 100))
if err != nil {
t.Error(err)
}
teatest.WaitFor(t, tm.Output(), func(bts []byte) bool {
return bytes.Contains(bts, []byte("missing upstream"))
}, teatest.WithCheckInterval(time.Millisecond*100), teatest.WithDuration(time.Second*3))
err = withUntrackedFile(d)
if err != nil {
t.Error(err)
}
tm.Send(tea.KeyMsg{
Type: tea.KeyRunes,
Runes: []rune("u"),
})
teatest.WaitFor(t, tm.Output(), func(bts []byte) bool {
return bytes.Contains(bts, []byte("1 file to commit, missing upstream"))
}, teatest.WithCheckInterval(time.Millisecond*100), teatest.WithDuration(time.Second*3))
tm.Send(tea.KeyMsg{
Type: tea.KeyRunes,
Runes: []rune("q"),
})
tm.WaitFinished(t, teatest.WithFinalTimeout(time.Second))
}