-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
messages_test.go
67 lines (55 loc) · 1.26 KB
/
messages_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
// Copyright (c) Liam Stanley <me@liamstanley.io>. All rights reserved. Use
// of this source code is governed by the MIT license that can be found in
// the LICENSE file.
package zone
import (
"testing"
"time"
tea "github.com/charmbracelet/bubbletea"
)
type testModel struct {
received []tea.Msg
}
func newTestModel() *testModel {
return &testModel{}
}
func (m *testModel) Init() tea.Cmd {
return nil
}
func (m *testModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.MouseMsg:
go AnyInBounds(m, msg)
return m, nil
case MsgZoneInBounds:
m.received = append(m.received, msg)
}
return m, nil
}
func (m *testModel) View() string {
// Starts at X:4, Y:2, ends at X:12, Y:3.
return "test\nfoo\naaa " + Mark("foo", "bar\ntest123456789") + " aaa\nbaz"
}
func TestAnyInBounds(t *testing.T) {
m := newTestModel()
_ = Scan(m.View())
time.Sleep(100 * time.Millisecond)
xy := Get("foo")
if xy.IsZero() {
t.Error("id not found")
}
_, _ = m.Update(tea.MouseMsg{X: 4, Y: 2})
time.Sleep(100 * time.Millisecond)
var contains bool
for _, msg := range m.received {
if evt, ok := msg.(MsgZoneInBounds); ok {
if evt.Zone.id == xy.id {
contains = true
break
}
}
}
if !contains {
t.Error("expected true")
}
}