-
Notifications
You must be signed in to change notification settings - Fork 27
/
utils_test.go
43 lines (31 loc) · 1.23 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
package elem
import (
"testing"
"github.com/stretchr/testify/assert"
)
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 TestIfUsingNone(t *testing.T) {
trueElement := Div(nil, Text("True Condition"))
resultWithNone := If[Node](true, trueElement, None())
assert.Equal(t, trueElement.Render(), resultWithNone.Render(), "If should render the true element when the condition is true")
resultWithNoneFalse := If[Node](false, trueElement, None())
assert.Equal(t, "", resultWithNoneFalse.Render(), "If should render nothing (empty string) when the condition is false and None is used")
}
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())
}
}