-
Notifications
You must be signed in to change notification settings - Fork 1
/
jawsevent_test.go
101 lines (86 loc) · 2.24 KB
/
jawsevent_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
package jaws
import (
"fmt"
"html/template"
"io"
"testing"
"github.com/linkdata/jaws/what"
)
type testJawsEvent struct {
msgCh chan string
tag any
clickerr error
eventerr error
}
func (t *testJawsEvent) JawsClick(e *Element, name string) (err error) {
if err = t.clickerr; err == nil {
t.msgCh <- fmt.Sprintf("JawsClick: %q", name)
}
return
}
func (t *testJawsEvent) JawsEvent(e *Element, wht what.What, val string) (err error) {
if err = t.eventerr; err == nil {
t.msgCh <- fmt.Sprintf("JawsEvent: %s %q", wht, val)
} else {
t.msgCh <- err.Error()
}
return
}
func (t *testJawsEvent) JawsGetTag(*Request) (tag any) {
return t.tag
}
func (t *testJawsEvent) JawsRender(e *Element, w io.Writer, params []any) error {
w.Write([]byte(fmt.Sprint(params)))
t.msgCh <- fmt.Sprintf("JawsRender(%d)", e.jid)
return nil
}
func (t *testJawsEvent) JawsUpdate(e *Element) {
t.msgCh <- fmt.Sprintf("JawsUpdate(%d)", e.jid)
}
var _ ClickHandler = (*testJawsEvent)(nil)
var _ EventHandler = (*testJawsEvent)(nil)
var _ TagGetter = (*testJawsEvent)(nil)
var _ UI = (*testJawsEvent)(nil)
func Test_JawsEvent_ClickUnhandled(t *testing.T) {
th := newTestHelper(t)
nextJid = 0
rq := newTestRequest()
defer rq.Close()
msgCh := make(chan string, 1)
defer close(msgCh)
je := &testJawsEvent{msgCh: msgCh}
zomgItem := &testUi{}
id := rq.Register(zomgItem, je, "attr1", []string{"attr2"}, template.HTMLAttr("attr3"), []template.HTMLAttr{"attr4"})
je.clickerr = ErrEventUnhandled
rq.inCh <- wsMsg{Data: "name", Jid: id, What: what.Click}
select {
case <-th.C:
th.Timeout()
case s := <-msgCh:
if s != "JawsEvent: Click \"name\"" {
t.Error(s)
}
}
}
func Test_JawsEvent_AllUnhandled(t *testing.T) {
th := newTestHelper(t)
nextJid = 0
rq := newTestRequest()
defer rq.Close()
msgCh := make(chan string, 1)
defer close(msgCh)
je := &testJawsEvent{msgCh: msgCh}
zomgItem := &testUi{}
id := rq.Register(zomgItem, je, "attr1", []string{"attr2"}, template.HTMLAttr("attr3"), []template.HTMLAttr{"attr4"})
je.clickerr = ErrEventUnhandled
je.eventerr = ErrEventUnhandled
rq.inCh <- wsMsg{Data: "name", Jid: id, What: what.Click}
select {
case <-th.C:
th.Timeout()
case s := <-msgCh:
if s != ErrEventUnhandled.Error() {
t.Error(s)
}
}
}