-
Notifications
You must be signed in to change notification settings - Fork 1
/
clickhandler_test.go
58 lines (48 loc) · 1.02 KB
/
clickhandler_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
package jaws
import (
"testing"
"github.com/linkdata/jaws/what"
)
type testJawsClick struct {
clickCh chan string
*testSetter[string]
}
func (tjc *testJawsClick) JawsClick(e *Element, name string) (err error) {
if err = tjc.err; err == nil {
tjc.clickCh <- name
}
return
}
var _ ClickHandler = (*testJawsClick)(nil)
func Test_clickHandlerWapper_JawsEvent(t *testing.T) {
th := newTestHelper(t)
nextJid = 0
rq := newTestRequest()
defer rq.Close()
tjc := &testJawsClick{
clickCh: make(chan string),
testSetter: newTestSetter(""),
}
want := `<div id="Jid.1">inner</div>`
rq.Div("inner", tjc)
if got := rq.BodyString(); got != want {
t.Errorf("Request.Div() = %q, want %q", got, want)
}
rq.inCh <- wsMsg{Data: "text", Jid: 1, What: what.Input}
select {
case <-th.C:
th.Timeout()
case s := <-rq.outCh:
t.Errorf("%q", s)
default:
}
rq.inCh <- wsMsg{Data: "adam", Jid: 1, What: what.Click}
select {
case <-th.C:
th.Timeout()
case name := <-tjc.clickCh:
if name != "adam" {
t.Error(name)
}
}
}