-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathreconciler_test.go
81 lines (56 loc) · 1.93 KB
/
reconciler_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
package vn_test
import (
"syscall/js"
"testing"
"github.com/stretchr/testify/assert"
"github.com/golang/mock/gomock"
vn "github.com/mfrachet/go-vdom-wasm"
vnd "github.com/mfrachet/go-vdom-wasm/dom"
"github.com/mfrachet/go-vdom-wasm/mock"
)
func TestReconciler_Append(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
mockParentNode := mock.NewMockDomNode(ctrl)
mockChildNode := mock.NewMockDomNode(ctrl)
mockParentNode.EXPECT().AppendChild(mockChildNode).Times(1)
vn.Append(mockParentNode, mockChildNode)
}
func TestReconciler_Remove(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
mockDNode := mock.NewMockDomNode(ctrl)
mockDNode.EXPECT().Remove().Times(1)
vn.Remove(mockDNode)
}
func TestReconciler_CreateText(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
textNode := vn.NewTextnode("Hello world")
mockDNode := mock.NewMockDomNode(ctrl)
mockDNode.EXPECT().CreateTextNode("Hello world").Times(1)
vn.CreateText(mockDNode, textNode)
}
func handleClick(arg []js.Value) {}
func TestReconciler_CreateInstance(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
vnode := vn.H("li", &vn.Props{"class": "navbar"}, &vn.Ev{"click": nil}, "Hello world")
mockParent := mock.NewMockDomNode(ctrl)
mockChild := mock.NewMockDomNode(ctrl)
mockParent.EXPECT().CreateElement("li").Return(mockChild).Times(1)
mockChild.EXPECT().SetAttribute("class", "navbar").Times(1)
mockChild.EXPECT().AddEventListener("click", nil).Times(1)
domNode := vn.CreateInstance(mockParent, vnode)
assert.Equal(t, domNode, mockChild)
}
func TestReconciler_CreateIfNotExist_WithElement(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
domElement := vnd.DomElement{}
vnode := vn.H("div", vn.Children{})
vnode.SetElement(domElement)
mockParent := mock.NewMockDomNode(ctrl)
domNode := vn.CreateIfNotExist(mockParent, vnode)
assert.Equal(t, domNode, domElement)
}