forked from chasefleming/elem-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils_test.go
76 lines (60 loc) · 1.74 KB
/
utils_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
package elem
import (
"github.com/chasefleming/elem-go/styles"
"github.com/stretchr/testify/assert"
"testing"
)
func TestStyleString(t *testing.T) {
style := Style{
"background-color": "blue",
"color": "white",
"font-size": "16px",
}
assert.Equal(t, "background-color: blue; color: white; font-size: 16px;", style.String())
}
func TestStyleString_Empty(t *testing.T) {
style := Style{}
assert.Equal(t, "", style.String())
}
func TestStyleString_SinglePair(t *testing.T) {
style := Style{
"color": "red",
}
assert.Equal(t, "color: red;", style.String())
}
func TestStyleString_UnorderedKeys(t *testing.T) {
style := Style{
"font-size": "16px",
"color": "red",
}
assert.Equal(t, "color: red; font-size: 16px;", style.String())
}
func TestApplyStyle(t *testing.T) {
style := Style{
styles.BackgroundColor: "blue",
styles.Color: "white",
styles.FontSize: "16px",
}
expected := "background-color: blue; color: white; font-size: 16px;"
actual := ApplyStyle(style)
assert.Equal(t, expected, actual)
}
func TestIf(t *testing.T) {
trueElement := Div(nil, Text("True Condition"))
falseElement := Div(nil, Text("False Condition"))
resultTrue := If(true, trueElement, falseElement)
assert.Equal(t, trueElement.Render(), resultTrue.Render())
resultFalse := If(false, trueElement, falseElement)
assert.Equal(t, falseElement.Render(), resultFalse.Render())
}
func TestTransformEach(t *testing.T) {
items := []string{"Item 1", "Item 2", "Item 3"}
elements := TransformEach(items, func(item string) Node {
return Li(nil, Text(item))
})
assert.Equal(t, len(items), len(elements))
for i, el := range elements {
expected := `<li>` + items[i] + `</li>`
assert.Equal(t, expected, el.Render())
}
}