Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
linkdata committed Oct 20, 2023
1 parent 366e29e commit 8a09593
Showing 1 changed file with 48 additions and 10 deletions.
58 changes: 48 additions & 10 deletions uihtml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,36 @@ import (

type testJawsEvent struct {
eventCalled chan string
*testSetter[template.HTML]
}

func (tje *testJawsEvent) JawsClick(e *Element, name string) (err error) {
tje.eventCalled <- fmt.Sprintf("JawsClick: %q", name)
return
}

func (tje *testJawsEvent) JawsEvent(e *Element, wht what.What, val string) (err error) {
if err = tje.err; err == nil {
tje.eventCalled <- fmt.Sprintf("%s %q", wht, val)
}
tje.eventCalled <- fmt.Sprintf("JawsEvent: %s %q", wht, val)
return
}

func (tje *testJawsEvent) JawsGetTag(*Request) (tag any) {
return
}

var _ ClickHandler = (*testJawsEvent)(nil)
var _ EventHandler = (*testJawsEvent)(nil)
var _ TagGetter = (*testJawsEvent)(nil)

func TestRequest_Register(t *testing.T) {
func TestUiHtml_JawsEvent(t *testing.T) {
tmr := time.NewTimer(testTimeout)
defer tmr.Stop()
nextJid = 0
rq := newTestRequest()
defer rq.Close()

tje := &testJawsEvent{
eventCalled: make(chan string),
testSetter: newTestSetter(template.HTML("meh")),
}
eventCalled := make(chan string)
defer close(eventCalled)
tje := &testJawsEvent{eventCalled: eventCalled}

id := rq.Register(Tag("zomg"), tje, "attr1", []string{"attr2"}, template.HTML("attr3"), []template.HTML{"attr4"})

Expand All @@ -42,7 +49,38 @@ func TestRequest_Register(t *testing.T) {
case <-tmr.C:
t.Error("timeout")
case s := <-tje.eventCalled:
if s != "Input \"text\"" {
if s != "JawsEvent: Input \"text\"" {
t.Error(s)
}
}

rq.inCh <- wsMsg{Data: "name", Jid: id, What: what.Click}
select {
case <-tmr.C:
t.Error("timeout")
case s := <-eventCalled:
if s != "JawsClick: \"name\"" {
t.Error(s)
}
}

id2 := rq.Register(tje)
rq.inCh <- wsMsg{Data: "text", Jid: id2, What: what.Input}
select {
case <-tmr.C:
t.Error("timeout")
case s := <-tje.eventCalled:
if s != "JawsEvent: Input \"text\"" {
t.Error(s)
}
}

rq.inCh <- wsMsg{Data: "name", Jid: id2, What: what.Click}
select {
case <-tmr.C:
t.Error("timeout")
case s := <-eventCalled:
if s != "JawsClick: \"name\"" {
t.Error(s)
}
}
Expand Down

0 comments on commit 8a09593

Please sign in to comment.