-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalpine_test.go
99 lines (88 loc) · 2.38 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package apline_test
import (
"fmt"
"testing"
x "github.com/glsubri/gomponents-alpine"
"github.com/glsubri/gomponents-alpine/internal/assert"
g "maragu.dev/gomponents"
)
func TestAttributesWithString(t *testing.T) {
cases := map[string]func(string) g.Node{
// Alpine directives
"data": x.Data,
"init": x.Init,
"show": x.Show,
"text": x.Text,
"html": x.Html,
"model": x.Model,
"modelable": x.Modelable,
"for": x.For,
"effect": x.Effect,
"ref": x.Ref,
"teleport": x.Teleport,
"if": x.If,
"id": x.Id,
// Mask Plugin directives
"mask": x.Mask,
"mask:dynamic": x.MaskDynamic,
}
for name, fn := range cases {
t.Run(fmt.Sprintf(`should output x-%v="balloon"`, name), func(t *testing.T) {
n := g.El("div", fn("balloon"))
assert.Equal(t, fmt.Sprintf(`<div x-%v="balloon"></div>`, name), n)
})
}
}
func TestAttributesWithNoArgs(t *testing.T) {
cases := map[string]func() g.Node{
"cloak": x.Cloak,
"ignore": x.Ignore,
}
for name, fn := range cases {
t.Run(fmt.Sprintf(`should output x-%v"`, name), func(t *testing.T) {
n := g.El("div", fn())
assert.Equal(t, fmt.Sprintf(`<div x-%v></div>`, name), n)
})
}
}
func TestAttributesWithAttrAndValue(t *testing.T) {
cases := map[string]func(string, string) g.Node{
"bind": x.Bind,
"on": x.On,
}
for name, fn := range cases {
t.Run(fmt.Sprintf(`should output x-%v:hot-air"`, name), func(t *testing.T) {
n := g.El("div", fn("hot-air", "balloon"))
assert.Equal(t, fmt.Sprintf(`<div x-%v:hot-air="balloon"></div>`, name), n)
})
}
}
func TestTransition(t *testing.T) {
cases := map[string]struct {
args []string
expected string
}{
"no argument": {
args: nil,
expected: "<div x-transition></div>",
},
"an empty argument": {
args: []string{""},
expected: "<div x-transition></div>",
},
"a customizer": {
args: []string{".duration.500ms"},
expected: "<div x-transition.duration.500ms></div>",
},
"a directive and custom classes classes": {
args: []string{":enter", "transition ease-out duration-300"},
expected: `<div x-transition:enter="transition ease-out duration-300"></div>`,
},
}
for name, data := range cases {
t.Run(fmt.Sprintf("x-transition: %s", name), func(t *testing.T) {
n := g.El("div", x.Transition(data.args...))
assert.Equal(t, data.expected, n)
})
}
}