-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathinertia_test.go
128 lines (99 loc) · 2.48 KB
/
inertia_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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package inertia
import (
"context"
"testing"
)
func TestEnableSsr(t *testing.T) {
i := New("", "", "")
i.EnableSsr("ssr.test")
if i.ssrURL != "ssr.test" {
t.Errorf("expected: ssr.test, got: %v", i.ssrURL)
}
if i.ssrClient == nil {
t.Error("expected: *http.Client, got: nil")
}
}
func TestEnableSsrWithDefault(t *testing.T) {
i := New("", "", "")
i.EnableSsrWithDefault()
if i.ssrURL != "http://127.0.0.1:13714" {
t.Errorf("expected: http://127.0.0.1:13714, got: %v", i.ssrURL)
}
if i.ssrClient == nil {
t.Error("expected: *http.Client, got: nil")
}
}
func TestIsSsrEnabled(t *testing.T) {
i := New("", "", "")
if i.IsSsrEnabled() {
t.Error("expected: false, got: true")
}
i.EnableSsrWithDefault()
if !i.IsSsrEnabled() {
t.Error("expected: true, got: false")
}
}
func TestDisableSsr(t *testing.T) {
i := New("", "", "")
i.EnableSsrWithDefault()
i.DisableSsr()
if i.IsSsrEnabled() {
t.Error("expected: false, got: true")
}
if i.ssrClient != nil {
t.Error("expected: nil, got: *http.Client")
}
}
func TestShare(t *testing.T) {
i := New("", "", "")
i.Share("title", "Inertia.js Go")
title, ok := i.sharedProps["title"].(string)
if !ok {
t.Error("expected: title, got: empty value")
}
if title != "Inertia.js Go" {
t.Errorf("expected: Inertia.js Go, got: %s", title)
}
}
func TestShareFunc(t *testing.T) {
i := New("", "", "")
i.ShareFunc("asset", func(path string) (string, error) {
return "/" + path, nil
})
_, ok := i.sharedFuncMap["asset"].(func(string) (string, error))
if !ok {
t.Error("expected: asset func, got: empty value")
}
}
func TestWithProp(t *testing.T) {
ctx := context.TODO()
i := New("", "", "")
ctx = i.WithProp(ctx, "user", "test-user")
contextProps, ok := ctx.Value(ContextKeyProps).(map[string]interface{})
if !ok {
t.Error("expected: context props, got: empty value")
}
user, ok := contextProps["user"].(string)
if !ok {
t.Error("expected: user, got: empty value")
}
if user != "test-user" {
t.Errorf("expected: test-user, got: %s", user)
}
}
func TestWithViewData(t *testing.T) {
ctx := context.TODO()
i := New("", "", "")
ctx = i.WithViewData(ctx, "meta", "test-meta")
contextViewData, ok := ctx.Value(ContextKeyViewData).(map[string]interface{})
if !ok {
t.Error("expected: context view data, got: empty value")
}
meta, ok := contextViewData["meta"].(string)
if !ok {
t.Error("expected: meta, got: empty value")
}
if meta != "test-meta" {
t.Errorf("expected: test-meta, got: %s", meta)
}
}