-
Notifications
You must be signed in to change notification settings - Fork 9
/
views_test.go
95 lines (87 loc) · 3.34 KB
/
views_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
// Copyright 2017 NDP Systèmes. All Rights Reserved.
// See LICENSE file for full licensing details.
package web
import (
"testing"
"github.com/hexya-erp/hexya/src/models"
"github.com/hexya-erp/hexya/src/models/security"
"github.com/hexya-erp/hexya/src/tools/xmlutils"
"github.com/hexya-erp/pool/h"
. "github.com/smartystreets/goconvey/convey"
)
var viewDef1 = `
<view id="my_id" name="My View" model="ResUSers">
<form>
<group>
<field name="name" required="1" readonly="1"/>
<field name="tz" invisible="1"/>
</group>
</form>
</view>
`
var viewFieldInfos1 = map[string]*models.FieldInfo{
"name": {},
"tz": {},
}
var viewDef2 = `
<view id="my_id" name="My View" model="ResUSers">
<form>
<group>
<field name="name" attrs='{"readonly": [["Function", "ilike", "manager"]], "required": [["ID", "!=", false]]}'/>
<field name="tz" invisible="1" attrs='{"invisble": [["Login", "!=", "john"]]}'/>
</group>
</form>
</view>
`
var viewFieldInfos2 = map[string]*models.FieldInfo{
"name": {Required: true},
"tz": {ReadOnly: true},
}
func TestViewModifiers(t *testing.T) {
Convey("Testing correct modifiers injection in views", t, func() {
models.SimulateInNewEnvironment(security.SuperUserID, func(env models.Environment) {
Convey("'invisible', 'required' and 'readonly' field attributes should be set in modifiers", func() {
v, _ := xmlutils.XMLToDocument(viewDef1)
view := h.User().NewSet(env).ProcessView(v, viewFieldInfos1)
So(view, ShouldEqual, `
<view id="my_id" name="My View" model="ResUSers">
<form>
<group>
<field name="name" required="1" readonly="1" modifiers="{"readonly":true}"/>
<field name="tz" invisible="1" modifiers="{"invisible":true}"/>
</group>
</form>
</view>
`)
})
Convey("attrs should be set in modifiers", func() {
v, _ := xmlutils.XMLToDocument(viewDef2)
view := h.User().NewSet(env).ProcessView(v, viewFieldInfos1)
So(view, ShouldEqual, `
<view id="my_id" name="My View" model="ResUSers">
<form>
<group>
<field name="name" attrs="{"readonly": [["Function", "ilike", "manager"]], "required": [["ID", "!=", false]]}" modifiers="{"readonly":[["Function","ilike","manager"]],"required":[["ID","!=",false]]}"/>
<field name="tz" invisible="1" attrs="{"invisble": [["Login", "!=", "john"]]}" modifiers="{"invisible":true}"/>
</group>
</form>
</view>
`)
})
Convey("'Readonly' and 'Required' field data should be taken into account", func() {
v, _ := xmlutils.XMLToDocument(viewDef2)
view := h.User().NewSet(env).ProcessView(v, viewFieldInfos2)
So(view, ShouldEqual, `
<view id="my_id" name="My View" model="ResUSers">
<form>
<group>
<field name="name" attrs="{"readonly": [["Function", "ilike", "manager"]], "required": [["ID", "!=", false]]}" modifiers="{"readonly":[["Function","ilike","manager"]],"required":true}"/>
<field name="tz" invisible="1" attrs="{"invisble": [["Login", "!=", "john"]]}" modifiers="{"invisible":true,"readonly":true}"/>
</group>
</form>
</view>
`)
})
})
})
}