-
Notifications
You must be signed in to change notification settings - Fork 6
/
vnode_test.go
executable file
·115 lines (87 loc) · 2.56 KB
/
vnode_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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package vn
import (
"testing"
vnd "github.com/mfrachet/go-vdom-wasm/dom"
"github.com/stretchr/testify/assert"
)
func TestVnode_IsSame(t *testing.T) {
a := H("div", "Hello world")
b := H("div", "Hello world")
c := H("span", "Hello world")
d := H("span", &Props{"hello": "world"}, "Hello world")
e := H("span", &Props{"hello": "world"}, "Hello world")
f := H("div", &Props{"hello": "world"}, "Hello worldx")
j := H("span", &Props{"hello": "world2"}, "Hello world")
k := H("li", "Hello world")
l := H("li", "Hello world2")
m := H("li", Children{})
assert.Equal(t, true, a.IsSame(b))
assert.Equal(t, true, d.IsSame(e))
assert.Equal(t, false, a.IsSame(c))
assert.Equal(t, false, d.IsSame(f))
assert.Equal(t, false, d.IsSame(j))
assert.Equal(t, false, k.IsSame(l))
assert.Equal(t, false, m.IsSame(a))
assert.Equal(t, false, a.IsSame(m))
}
func TestVnode_IsSame_WithChildren(t *testing.T) {
a := H("ul", &Props{"class": "navbar"}, Children{
H("li", "First item"),
H("li", "Second item"),
})
b := H("ul", &Props{"class": "navbar"}, Children{
H("li", "First item"),
H("li", "Second item"),
})
assert.Equal(t, true, a.IsSame(b))
}
func TestVnode_IsSame_WithKey(t *testing.T) {
a := H("ul", &Props{"class": "navbar"}, Children{
H("li", "First item"),
H("li", "Second item"),
}, &Key{"1"})
b := H("ul", &Props{"class": "navbar"}, Children{
H("li", "First item"),
H("li", "Second item"),
}, &Key{"2"})
assert.Equal(t, false, a.IsSame(b))
}
func TestVnode_ChildrenCount(t *testing.T) {
a := H("div", Children{
H("span", "Hello"),
H("span", "Hello"),
})
assert.Equal(t, 2, a.ChildrenCount())
}
func TestVnode_ChildAt(t *testing.T) {
childAtOne := H("span", "Hello World")
a := H("div", Children{
H("span", "Hello"),
childAtOne,
})
b := H("span", "Hello")
assert.Equal(t, childAtOne, a.ChildAt(1))
assert.Equal(t, nil, b.ChildAt(1))
}
func TestVnode_HasElement(t *testing.T) {
element := H("span", "Hello world")
assert.Equal(t, false, element.HasElement())
element.SetElement(vnd.DomElement{})
assert.Equal(t, true, element.HasElement())
}
func TestVnode_GetTagName(t *testing.T) {
element := H("span", "Hello world")
assert.Equal(t, "span", element.GetTagName())
}
func TestVnode_GetAttrs(t *testing.T) {
props := &Props{"class": "navbar"}
ev := &Ev{}
attrs := &Attrs{Props: props, Events: ev}
element := H("span", props, ev, "Hello world")
assert.Equal(t, attrs, element.GetAttrs())
}
func TestVnode_GetChildren(t *testing.T) {
children := Children{}
element := H("span", children)
assert.Equal(t, children, element.GetChildren())
}