-
Notifications
You must be signed in to change notification settings - Fork 652
/
Copy pathimportable_test.go
65 lines (56 loc) · 1.86 KB
/
importable_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
package share
import (
"os"
"path"
"testing"
jsoniter "github.com/json-iterator/go"
"github.com/stretchr/testify/assert"
)
func init() {
rootLib := path.Join(os.Getenv("YAO_DEV"), "/tests/libs")
LoadFrom(rootLib)
}
func TestColumn(t *testing.T) {
content := `{ "@": "column.Image", "in": ["LOGO", ":logo", 40] }`
column := Column{}
jsoniter.Unmarshal([]byte(content), &column)
assert.Equal(t, "upload", column.Edit.Type)
assert.Equal(t, ":logo", column.Edit.Props["value"])
assert.Equal(t, "image", column.View.Type)
assert.Equal(t, float64(40), column.View.Props["height"])
assert.Equal(t, float64(40), column.View.Props["width"])
assert.Equal(t, ":logo", column.View.Props["value"])
}
func TestColumnInIsNil(t *testing.T) {
content := `{ "@": "column.创建时间" }`
column := Column{}
jsoniter.Unmarshal([]byte(content), &column)
assert.Equal(t, ":created_at", column.View.Props["value"])
assert.Equal(t, "创建时间", column.Label)
}
func TestFilter(t *testing.T) {
content := `{ "@": "filter.关键词", "in": ["where.name.match"] }`
filter := Filter{}
jsoniter.Unmarshal([]byte(content), &filter)
assert.Equal(t, "where.name.match", filter.Bind)
}
func TestRender(t *testing.T) {
content := `{ "@": "render.Image", "in": [":image", 40, 60] }`
render := Render{}
jsoniter.Unmarshal([]byte(content), &render)
assert.Equal(t, ":image", render.Props["value"])
assert.Equal(t, float64(40), render.Props["width"])
assert.Equal(t, float64(60), render.Props["height"])
}
func TestPage(t *testing.T) {
content := `{ "@": "pages.static.Page", "in": ["id"] }`
page := Page{}
jsoniter.Unmarshal([]byte(content), &page)
assert.Equal(t, "id", page.Primary)
}
func TestAPI(t *testing.T) {
content := `{ "@": "apis.table.Search", "in": [10] }`
api := API{}
jsoniter.Unmarshal([]byte(content), &api)
assert.Equal(t, []interface{}{nil, nil, float64(10)}, api.Default)
}