-
Notifications
You must be signed in to change notification settings - Fork 2
/
transformer_test.go
27 lines (23 loc) · 1.23 KB
/
transformer_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
package form
import (
"testing"
)
type ModelA struct {
TextField string `required:"true" name:"SomeRandomTextFieldName"`
IntField int64
FloatField float64
SubGroup struct {
SubTextField string `required:"true"`
SubIntField int64
} `legend:"legendSubGroup"`
}
func TestNewTransformer(t *testing.T) {
out, err := NewTransformer(&ModelA{})
if err != nil {
t.Error(err)
}
expected := `{"fields":[{"name":"SomeRandomTextFieldName","value":"","type":"input","inputType":"text","label":"SomeRandomTextFieldName","required":true},{"name":"IntField","value":0,"type":"input","inputType":"number","label":"IntField","step":"1","required":false},{"name":"FloatField","value":0,"type":"input","inputType":"number","label":"FloatField","step":"any","required":false},{"name":"SubGroup","value":{"SubTextField":"","SubIntField":0},"type":"group","label":"SubGroup","required":false,"fields":[{"name":"SubGroup.SubTextField","value":"","type":"input","inputType":"text","label":"SubTextField","required":true},{"name":"SubGroup.SubIntField","value":0,"type":"input","inputType":"number","label":"SubIntField","step":"1","required":false}],"legend":"legendSubGroup"}]}`
if string(out.JSON()) != expected {
t.Error("transformer render changed")
}
}