-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathktea_test.go
123 lines (106 loc) · 4.23 KB
/
ktea_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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package main
import (
tea "github.com/charmbracelet/bubbletea"
"github.com/stretchr/testify/assert"
"ktea/config"
"ktea/kadmin"
"ktea/tests/keys"
"testing"
)
func TestKtea(t *testing.T) {
t.Run("No clusters configured", func(t *testing.T) {
t.Run("Shows create cluster page", func(t *testing.T) {
model := NewModel(kadmin.NewMockKadmin(), config.NewInMemoryConfigIO(&config.Config{}))
model.Update(config.LoadedMsg{
Config: &config.Config{},
})
view := model.View()
assert.Contains(t, view, "┃ Name")
})
})
t.Run("Tabs", func(t *testing.T) {
t.Run("Cycle through tabs", func(t *testing.T) {
io := config.NewInMemoryConfigIO(
&config.Config{
Clusters: []config.Cluster{
{
Name: "prd",
Color: "#808080",
Active: true,
BootstrapServers: []string{":19092"},
SchemaRegistry: &config.SchemaRegistryConfig{
Url: "",
Username: "",
Password: "",
},
SASLConfig: nil,
},
{
Name: "tst",
Color: "#808080",
Active: true,
BootstrapServers: []string{":19092"},
SchemaRegistry: nil,
SASLConfig: nil,
},
},
},
)
model := NewModel(kadmin.NewMockKadmin(), io)
model.Update(config.LoadedMsg{Config: config.New(io)})
//model.Update(config.LoadedMsg{
// Config: &config.Config{
// },
//})
model.Update(tea.WindowSizeMsg{
Width: 100,
Height: 100,
})
model.Update(tea.KeyMsg{
Type: tea.KeyRunes,
Runes: []rune{'2'},
Alt: true,
Paste: false,
})
view := model.View()
var expectedLayout = `
╭────────────────╮╭─────────────────────────╮╭─────────────────────────╮╭──────────────────╮
│ Topics (Alt-1) ││ Consumer Groups (Alt-2) ││ Schema Registry (Alt-3) ││ Clusters (Alt-4) │
┴────────────────┴┘ └┴─────────────────────────┴┴──────────────────┴────────
`
assert.Contains(t, view, expectedLayout)
model.Update(tea.KeyMsg{
Type: tea.KeyRunes,
Runes: []rune{'3'},
Alt: true,
Paste: false,
})
view = model.View()
expectedLayout = `
╭────────────────╮╭─────────────────────────╮╭─────────────────────────╮╭──────────────────╮
│ Topics (Alt-1) ││ Consumer Groups (Alt-2) ││ Schema Registry (Alt-3) ││ Clusters (Alt-4) │
┴────────────────┴┴─────────────────────────┴┘ └┴──────────────────┴────────
`
assert.Contains(t, view, expectedLayout)
model.Update(tea.KeyMsg{
Type: tea.KeyRunes,
Runes: []rune{'4'},
Alt: true,
Paste: false,
})
assert.Contains(t, view, expectedLayout)
model.View()
_, cmd := model.Update(keys.Key(tea.KeyDown))
_, cmd = model.Update(keys.Key(tea.KeyEnter))
model.Update(cmd())
view = model.View()
expectedLayout = `
╭────────────────╮╭─────────────────────────╮╭──────────────────╮
│ Topics (Alt-1) ││ Consumer Groups (Alt-2) ││ Clusters (Alt-3) │
┴────────────────┴┴─────────────────────────┴┘ └───────────────────────────────────
`
assert.Regexp(t, "X\\W+tst", view)
assert.NotRegexp(t, "X\\W+prd", view)
})
})
}