-
Notifications
You must be signed in to change notification settings - Fork 2
/
govuegui_test.go
88 lines (82 loc) · 1.87 KB
/
govuegui_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
package govuegui
import (
"reflect"
"testing"
)
func TestGuiForm(t *testing.T) {
gui := NewGui(GuiTemplate{})
testCases := []struct {
formid string
boxesid []string
}{
{
"form1",
[]string{"box1"},
},
{
"form2",
[]string{"box21", "box22", "box23"},
},
}
for _, tc := range testCases {
f := gui.Form(tc.formid)
for _, b := range tc.boxesid {
// Adding boxes
gui.Form(tc.formid).Box(b)
}
if f.ID() != tc.formid {
t.Errorf("Failed generating Forms.\nExpected: %s Got: %s", tc.formid, f.ID())
}
if len(f.Boxes) != len(tc.boxesid) {
t.Errorf("Form: %s\nNot all boxes are created!", tc.formid)
}
}
}
func TestForm(t *testing.T) {
form := &Form{
Key: "123",
Options: make(map[string]*Option),
}
b1 := form.Box("box1")
if b1 != form.Box("box1") {
t.Error("box1 has not been created correctly.")
}
testOpts := []string{"val1", "val2", "val3"}
form.Option("f1option", testOpts...)
if !reflect.DeepEqual(
form.Options["f1option"].Values,
testOpts,
) {
t.Errorf("Form Options not set correct\nExp: %v\nGot: %v",
testOpts,
form.Options["f1option"].Values,
)
}
}
func TestBox(t *testing.T) {
gui := NewGui(GuiTemplate{})
b1 := gui.Form("F1").Box("b1")
b1.Input("I1")
if b1.Elements[0].ID() != "F1-b1-I1" {
t.Errorf("Input field not added to Box1!\nGot: %s", b1.Elements[0].ID())
}
b1.Option("title", "This is my title")
if b1.Options["title"].Values[0] != "This is my title" {
t.Error("Option was not set correct at Box1")
}
}
func TestSetGet(t *testing.T) {
gui := NewGui(GuiTemplate{})
testString := "Value of a string"
err := gui.Form("myForm").Box("Box1").Textarea("t1").Set(testString)
if err != nil {
t.Error(err)
}
got := gui.Form("myForm").Box("Box1").Textarea("t1").Get()
if !reflect.DeepEqual(got, testString) {
t.Errorf("Another value expected.\nGot: %s\nExp: %s",
got,
testString,
)
}
}