-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy patheval_visibility_test.go
More file actions
85 lines (79 loc) · 2.27 KB
/
Copy patheval_visibility_test.go
File metadata and controls
85 lines (79 loc) · 2.27 KB
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
package vuego_test
import (
"bytes"
"testing"
"testing/fstest"
"github.com/stretchr/testify/require"
"github.com/titpetric/vuego"
"github.com/titpetric/vuego/diff"
)
func TestVue_EvalVShow(t *testing.T) {
tests := []struct {
name string
template string
data map[string]any
expected string
}{
{
name: "v-show with truthy condition",
template: `<div v-show="visible"></div>`,
data: map[string]any{"visible": true},
expected: `<div></div>`,
},
{
name: "v-show with falsey condition",
template: `<div v-show="visible"></div>`,
data: map[string]any{"visible": false},
expected: `<div style="display:none;"></div>`,
},
{
name: "v-show hides when condition is false",
template: `<p v-show="show">Content</p>`,
data: map[string]any{"show": false},
expected: `<p style="display:none;">Content</p>`,
},
{
name: "v-show preserves existing styles",
template: `<div v-show="visible" style="color: red; font-size: 14px;"></div>`,
data: map[string]any{"visible": false},
expected: `<div style="color:red;font-size:14px;display:none;"></div>`,
},
{
name: "v-show with expression truthy",
template: `<span v-show="true"></span>`,
data: map[string]any{},
expected: `<span></span>`,
},
{
name: "v-show with expression falsey",
template: `<span v-show="count > 0"></span>`,
data: map[string]any{"count": 0},
expected: `<span style="display:none;"></span>`,
},
{
name: "v-show with missing variable",
template: `<div v-show="missing"></div>`,
data: map[string]any{},
expected: `<div style="display:none;"></div>`,
},
{
name: "v-show overwrites display property",
template: `<div v-show="visible" style="display: flex;"></div>`,
data: map[string]any{"visible": false},
expected: `<div style="display:none;"></div>`,
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
template := []byte(tc.template)
fs := fstest.MapFS{
"test.vuego": &fstest.MapFile{Data: template},
}
vue := vuego.NewVue(fs)
var buf bytes.Buffer
err := vue.RenderFragment(t.Context(), &buf, "test.vuego", tc.data)
require.NoError(t, err)
diff.EqualHTML(t, []byte(tc.expected), buf.Bytes(), nil, nil)
})
}
}