-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin_test.go
74 lines (56 loc) · 1.45 KB
/
admin_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
package admin
import (
"testing"
"github.com/qor/qor"
"github.com/qor/qor/test/utils"
)
type User struct {
Name string
ID uint64
}
var db = utils.TestDB()
func TestAddResource(t *testing.T) {
admin := New(&qor.Config{DB: db})
user := admin.AddResource(&User{})
if user != admin.resources[0] {
t.Error("resource not added")
}
if admin.GetMenus()[0].Name != "Users" {
t.Error("resource not added to menu")
}
}
func TestAddResourceWithInvisibleOption(t *testing.T) {
admin := New(&qor.Config{DB: db})
user := admin.AddResource(&User{}, &Config{Invisible: true})
if user != admin.resources[0] {
t.Error("resource not added")
}
if len(admin.GetMenus()) != 0 {
t.Error("invisible resource registered in menu")
}
}
func TestGetResource(t *testing.T) {
admin := New(&qor.Config{DB: db})
user := admin.AddResource(&User{})
if admin.GetResource("User") != user {
t.Error("resource not returned")
}
}
func TestNewResource(t *testing.T) {
admin := New(&qor.Config{DB: db})
user := admin.NewResource(&User{})
if user.Name != "User" {
t.Error("default resource name didn't set")
}
}
type UserWithCustomizedName struct{}
func (u *UserWithCustomizedName) ResourceName() string {
return "CustomizedName"
}
func TestNewResourceWithCustomizedName(t *testing.T) {
admin := New(&qor.Config{DB: db})
user := admin.NewResource(&UserWithCustomizedName{})
if user.Name != "CustomizedName" {
t.Error("customize resource name didn't set")
}
}