-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcomponent_test.go
More file actions
94 lines (75 loc) · 2.14 KB
/
Copy pathcomponent_test.go
File metadata and controls
94 lines (75 loc) · 2.14 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
86
87
88
89
90
91
92
93
94
package vuego_test
import (
"testing"
"testing/fstest"
"github.com/stretchr/testify/require"
"github.com/titpetric/vuego"
)
func TestNewComponent(t *testing.T) {
fs := fstest.MapFS{
"test.vuego": &fstest.MapFile{Data: []byte("<div>test</div>")},
}
comp := vuego.NewLoader(fs)
require.NotNil(t, comp)
}
func TestComponent_Stat(t *testing.T) {
fs := fstest.MapFS{
"exists.html": &fstest.MapFile{Data: []byte("<div>test</div>")},
}
comp := vuego.NewLoader(fs)
t.Run("file exists", func(t *testing.T) {
err := comp.Stat("exists.html")
require.NoError(t, err)
})
t.Run("file not found", func(t *testing.T) {
err := comp.Stat("missing.html")
require.Error(t, err)
})
}
func TestComponent_Load(t *testing.T) {
fs := fstest.MapFS{
"doc.html": &fstest.MapFile{Data: []byte("<html><body><h1>Test</h1></body></html>")},
}
comp := vuego.NewLoader(fs)
t.Run("valid document", func(t *testing.T) {
nodes, err := comp.Load("doc.html")
require.NoError(t, err)
require.NotNil(t, nodes)
require.Greater(t, len(nodes), 0)
})
t.Run("file not found", func(t *testing.T) {
_, err := comp.Load("missing.html")
require.Error(t, err)
})
t.Run("invalid html", func(t *testing.T) {
fs := fstest.MapFS{
"bad.html": &fstest.MapFile{Data: []byte("<<<>>>")},
}
comp := vuego.NewLoader(fs)
nodes, err := comp.Load("bad.html")
require.NoError(t, err)
require.NotNil(t, nodes)
})
}
func TestComponent_LoadFragment(t *testing.T) {
fs := fstest.MapFS{
"fragment.html": &fstest.MapFile{Data: []byte("<div>content</div>")},
"document.html": &fstest.MapFile{Data: []byte("<html><body><div>doc</div></body></html>")},
}
comp := vuego.NewLoader(fs)
t.Run("fragment without html tag", func(t *testing.T) {
nodes, err := comp.LoadFragment("fragment.html")
require.NoError(t, err)
require.NotNil(t, nodes)
require.Greater(t, len(nodes), 0)
})
t.Run("full document falls back to Load", func(t *testing.T) {
nodes, err := comp.LoadFragment("document.html")
require.NoError(t, err)
require.NotNil(t, nodes)
})
t.Run("file not found", func(t *testing.T) {
_, err := comp.LoadFragment("missing.html")
require.Error(t, err)
})
}