-
Notifications
You must be signed in to change notification settings - Fork 6
/
ajax_timing.go
125 lines (102 loc) · 3.49 KB
/
ajax_timing.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package test
import (
"context"
"fmt"
"github.com/goradd/goradd/pkg/log"
"github.com/goradd/goradd/pkg/page"
"github.com/goradd/goradd/pkg/page/action"
. "github.com/goradd/goradd/pkg/page/control"
"github.com/goradd/goradd/pkg/page/event"
"github.com/goradd/goradd/test/browsertest"
)
const AjaxTimingPath = "/page/test/AjaxTiming.g"
const AjaxTimingId = "AjaxTimingForm"
const (
Txt1ChangeAction = iota + 1
Txt1KeyUpAction
ChkChangeAction
Txt2ChangeAction
BtnClickAction
)
/**
* AjaxTimingForm
*
* Tests the timing of ajax events and our ability to record a change to a control. There is a bit of a race condition
* that we need to get under control. For example, if the user clicks a checkbox that also has a "click" handler, and
* inside that handler, tests the value of the checkbox, the user should see the new value and not the one before the
* click. Other problems come up when a Click causes a Change or FocusOut, which in turn changes the focus. Typically
* in javascript, that would cause the Click to be lost. Our javascript tries to accommodate this by queueing all the
* event responses before processing them.
*
* This is currently a manual test. Using a browser tester like Selenium, we could maybe make this part of the regular
* continuous integration test.
*/
type AjaxTimingForm struct {
FormBase
Txt1 *Textbox
Txt1ChangeLabel *Span
Txt1KeyUpLabel *Span
Chk *Checkbox
ChkLabel *Span
Txt2 *Textbox
Btn *Button
}
func NewAjaxTimingForm(ctx context.Context) page.FormI {
f := &AjaxTimingForm{}
f.Init(ctx, f, AjaxTimingPath, AjaxTimingId)
f.AddRelatedFiles()
f.createControls(ctx)
return f
}
func (f *AjaxTimingForm) createControls(ctx context.Context) {
f.Txt1 = NewTextbox(f, "")
f.Txt1.SetColumnCount(30)
f.Txt1.SetLabel("TextBox KeyUp Test")
f.Txt1.SetText("Change Me")
f.Txt1.On(event.Change(), action.Ajax(f.ID(), Txt1ChangeAction))
f.Txt1.On(event.KeyUp(), action.Ajax(f.ID(), Txt1KeyUpAction))
f.Txt1ChangeLabel = NewSpan(f, "")
f.Txt1ChangeLabel.SetLabel("Value after Change: ")
f.Txt1KeyUpLabel = NewSpan(f, "")
f.Txt1KeyUpLabel.SetLabel("Value after Key Up: ")
f.Chk = NewCheckbox(f, "")
f.Chk.SetLabel("Checkbox Test")
f.Chk.On(event.Click(), action.Ajax(f.ID(), ChkChangeAction))
f.ChkLabel = NewSpan(f, "")
f.ChkLabel.SetLabel("Value after Click: ")
f.Txt2 = NewTextbox(f, "")
f.Txt2.SetLabel("TextBox Refocus Test")
f.Txt2.SetText("Change Me")
f.Txt2.On(event.Change(), action.Focus(f.Txt1.ID()))
f.Btn = NewButton(f, "")
f.Btn.SetLabel("Submit")
f.Btn.On(event.Click(), action.Ajax(f.ID(), BtnClickAction))
f.Btn.SetValidationType(page.ValidateNone)
}
func (f *AjaxTimingForm) Action(ctx context.Context, a page.ActionParams) {
switch a.ID {
case Txt1ChangeAction:
f.Txt1ChangeLabel.SetText(f.Txt1.Text())
case Txt1KeyUpAction:
f.Txt1KeyUpLabel.SetText(f.Txt1.Text())
case ChkChangeAction:
f.ChkLabel.SetText(fmt.Sprintf("%t", f.Chk.Checked()))
case BtnClickAction:
f.Txt1ChangeLabel.SetText("Button Was Clicked")
}
}
func TestForm(t *browsertest.TestForm) {
log.Debug("AjaxTiming test")
t.LoadUrl(AjaxTimingPath)
f := t.GetForm().(*AjaxTimingForm)
t.AssertEqual(AjaxTimingId, f.ID())
t.Focus(f.Txt1.ID())
//t.TypeValue(f.Txt1.ID(), "m")
t.Log("Complete")
/*
t.AssertEquals("A value is required", t.SelectorInnerText("#user-name_err"))*/
}
func init() {
page.RegisterPage(AjaxTimingPath, NewAjaxTimingForm, AjaxTimingId)
browsertest.RegisterTestFunction("AjaxTiming", TestForm)
}