-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalpine_test.go
83 lines (79 loc) · 1.92 KB
/
alpine_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
package alpine_test
import (
"testing"
a "github.com/jlucasnsilva/gomponents-alpine"
g "github.com/maragudk/gomponents"
"github.com/stretchr/testify/assert"
)
func TestCases(t *testing.T) {
cases := map[string]struct {
input g.Node
expected g.Node
}{
"Data": {
input: a.Data("{ open: false }"),
expected: g.Attr("x-data", "{ open: false }"),
},
"Bind": {
input: a.Bind("class", "! open ? 'hidden' : ''"),
expected: g.Attr("x-bind:class", "! open ? 'hidden' : ''"),
},
"On": {
input: a.On("click", "open = ! open"),
expected: g.Attr("x-on:click", "open = ! open"),
},
"Text": {
input: a.Text("new Date().getFullYear()"),
expected: g.Attr("x-text", "new Date().getFullYear()"),
},
"HTML": {
input: a.HTML("(await axios.get('/some/html/partial')).data"),
expected: g.Attr("x-html", "(await axios.get('/some/html/partial')).data"),
},
"Model": {
input: a.Model("search"),
expected: g.Attr("x-model", "search"),
},
"Show": {
input: a.Show("open"),
expected: g.Attr("x-show", "open"),
},
"Transition": {
input: a.Transition(),
expected: g.Attr("x-transition"),
},
"For": {
input: a.For("post in posts"),
expected: g.Attr("x-for", "post in posts"),
},
"If": {
input: a.If("open"),
expected: g.Attr("x-if", "open"),
},
"Init": {
input: a.Init("date = new Date()"),
expected: g.Attr("x-init", "date = new Date()"),
},
"Effect": {
input: a.Effect("console.log('Count is '+count)"),
expected: g.Attr("x-effect", "console.log('Count is '+count)"),
},
"Ref": {
input: a.Ref("content"),
expected: g.Attr("x-ref", "content"),
},
"Cloak": {
input: a.Cloak(),
expected: g.Attr("x-cloak"),
},
"Ignore": {
input: a.Ignore(),
expected: g.Attr("x-ignore"),
},
}
for label, c := range cases {
t.Run(label, func(t *testing.T) {
assert.Equal(t, c.expected, c.input)
})
}
}