@@ -11,10 +11,10 @@ import (
11
11
"github.com/gost-dom/browser/html"
12
12
"github.com/gost-dom/browser/internal/gosthttp"
13
13
"github.com/gost-dom/browser/internal/testing/eventtest"
14
- . "github.com/gost-dom/browser/internal/testing/exp/fixture"
15
14
. "github.com/gost-dom/browser/internal/testing/gomega-matchers"
16
15
"github.com/gost-dom/browser/internal/testing/htmltest"
17
16
. "github.com/gost-dom/browser/testing/gomega-matchers"
17
+ "github.com/gost-dom/fixture"
18
18
"github.com/onsi/gomega"
19
19
"github.com/onsi/gomega/types"
20
20
"github.com/stretchr/testify/assert"
@@ -24,7 +24,7 @@ type InitialHTMLFixture string
24
24
type BaseLocationFixture string
25
25
26
26
type AssertFixture struct {
27
- Fixture
27
+ fixture. Fixture
28
28
assert * assert.Assertions
29
29
gomega gomega.Gomega
30
30
}
@@ -54,7 +54,7 @@ func (f *HTTPHandlerFixture) Setup() {
54
54
55
55
type WindowFixture struct {
56
56
AssertFixture
57
- BaseLocationFixture
57
+ * BaseLocationFixture
58
58
InitialHTMLFixture
59
59
* HTTPHandlerFixture
60
60
Window htmltest.WindowHelper
@@ -66,11 +66,17 @@ type WindowFixture struct {
66
66
}
67
67
68
68
func (f * WindowFixture ) Setup () {
69
+ if f .Window .Window != nil {
70
+ return
71
+ }
69
72
fmt .Println ("Setup window" )
70
- win := html .NewWindow (html.WindowOptions {
71
- HttpClient : gosthttp .NewHttpClientFromHandler (f .HTTPHandlerFixture ),
72
- BaseLocation : string (f .BaseLocationFixture ),
73
- })
73
+ opts := html.WindowOptions {
74
+ HttpClient : gosthttp .NewHttpClientFromHandler (f .HTTPHandlerFixture ),
75
+ }
76
+ if f .BaseLocationFixture != nil {
77
+ opts .BaseLocation = string (* f .BaseLocationFixture )
78
+ }
79
+ win := html .NewWindow (opts )
74
80
f .Window = htmltest .NewWindowHelper (f .TB , win )
75
81
76
82
f .Helper ()
@@ -86,18 +92,25 @@ func (f *WindowFixture) Setup() {
86
92
type DefaultWindowFixture struct {
87
93
WindowFixture
88
94
* HTTPHandlerFixture
95
+ initialized bool
89
96
}
90
97
91
98
func (f * DefaultWindowFixture ) Setup () {
92
- fmt .Println ("Setup default window" )
93
- f .HTTPHandlerFixture .ServeMux .HandleFunc ("/" , func (res http.ResponseWriter , req * http.Request ) {
94
- if req .ParseForm () != nil {
95
- panic ("Error parsing form" )
96
- }
97
- f .actualRequest = req
98
- f .submittedForm = req .Form
99
- f .requests = append (f .requests , req )
100
- })
99
+ if ! f .initialized {
100
+ fmt .Println ("Setup default window" )
101
+ f .HTTPHandlerFixture .ServeMux .HandleFunc (
102
+ "/" ,
103
+ func (res http.ResponseWriter , req * http.Request ) {
104
+ if req .ParseForm () != nil {
105
+ panic ("Error parsing form" )
106
+ }
107
+ f .actualRequest = req
108
+ f .submittedForm = req .Form
109
+ f .requests = append (f .requests , req )
110
+ },
111
+ )
112
+ f .initialized = true
113
+ }
101
114
}
102
115
103
116
func AssertType [T any ](t testing.TB , actual any ) (res T ) {
@@ -124,9 +137,11 @@ type HTMLFormFixture struct {
124
137
}
125
138
126
139
func TestSubmitForm (t * testing.T ) {
127
- w , setup := InitFixture (t , & DefaultWindowFixture {}, BaseLocationFixture (
128
- "http://example.com/forms/example-form.html?original-query=original-value" ,
129
- ))
140
+ w , setup := fixture .Init (t , & struct {
141
+ DefaultWindowFixture
142
+ Location * BaseLocationFixture
143
+ }{})
144
+ * w .Location = "http://example.com/forms/example-form.html?original-query=original-value"
130
145
setup .Setup ()
131
146
132
147
var submitEventDispatched bool
@@ -148,9 +163,11 @@ func TestSubmitForm(t *testing.T) {
148
163
}
149
164
150
165
func TestHTMLFormElementSubmitPost (t * testing.T ) {
151
- w , setup := InitFixture (t , & DefaultWindowFixture {}, BaseLocationFixture (
152
- "http://example.com/forms/example-form.html?original-query=original-value" ,
153
- ))
166
+ w , setup := fixture .Init (t , & struct {
167
+ DefaultWindowFixture
168
+ Location * BaseLocationFixture
169
+ }{})
170
+ * w .Location = "http://example.com/forms/example-form.html?original-query=original-value"
154
171
setup .Setup ()
155
172
156
173
form := w .Form ()
@@ -181,7 +198,7 @@ func (f *HTMLFormSubmitButtonFixture) Setup() {
181
198
}
182
199
183
200
func TestHTMLFormElementSubmitWithClickButton (t * testing.T ) {
184
- w , setup := InitFixture (t , & HTMLFormSubmitButtonFixture {})
201
+ w , setup := fixture . Init (t , & HTMLFormSubmitButtonFixture {})
185
202
setup .Setup ()
186
203
187
204
w .Submitter .Click ()
@@ -192,7 +209,7 @@ func TestHTMLFormElementSubmitWithClickButton(t *testing.T) {
192
209
}
193
210
194
211
func TestHTMLFormElementSubmitWithClickButtonAndWeirdCasing (t * testing.T ) {
195
- w , setup := InitFixture (t , & HTMLFormSubmitButtonFixture {})
212
+ w , setup := fixture . Init (t , & HTMLFormSubmitButtonFixture {})
196
213
setup .Setup ()
197
214
198
215
w .Submitter .SetType ("SuBMit" )
@@ -204,7 +221,7 @@ func TestHTMLFormElementSubmitWithClickButtonAndWeirdCasing(t *testing.T) {
204
221
}
205
222
206
223
func TestHTMLFormElementSubmitWithClickResetButton (t * testing.T ) {
207
- w , setup := InitFixture (t , & HTMLFormSubmitButtonFixture {})
224
+ w , setup := fixture . Init (t , & HTMLFormSubmitButtonFixture {})
208
225
setup .Setup ()
209
226
210
227
w .Submitter .SetType ("reset" )
@@ -213,7 +230,7 @@ func TestHTMLFormElementSubmitWithClickResetButton(t *testing.T) {
213
230
}
214
231
215
232
func TestHTMLFormElementRequestSubmitWithoutSubmitter (t * testing.T ) {
216
- w , setup := InitFixture (t , & HTMLFormSubmitButtonFixture {})
233
+ w , setup := fixture . Init (t , & HTMLFormSubmitButtonFixture {})
217
234
setup .Setup ()
218
235
219
236
w .Assert ().NoError (w .Form ().RequestSubmit (nil ))
@@ -223,7 +240,7 @@ func TestHTMLFormElementRequestSubmitWithoutSubmitter(t *testing.T) {
223
240
}
224
241
225
242
func TestHTMLFormElementRequestSubmitPreventDefault (t * testing.T ) {
226
- w , setup := InitFixture (t , & HTMLFormSubmitButtonFixture {})
243
+ w , setup := fixture . Init (t , & HTMLFormSubmitButtonFixture {})
227
244
setup .Setup ()
228
245
229
246
var submitEventDispatched bool
@@ -237,7 +254,7 @@ func TestHTMLFormElementRequestSubmitPreventDefault(t *testing.T) {
237
254
}
238
255
239
256
func TestHTMLFormElementRequestSubmitWithSubmitter (t * testing.T ) {
240
- w , setup := InitFixture (t , & HTMLFormSubmitButtonFixture {})
257
+ w , setup := fixture . Init (t , & HTMLFormSubmitButtonFixture {})
241
258
setup .Setup ()
242
259
243
260
w .Assert ().NoError (w .Form ().RequestSubmit (w .Submitter ))
@@ -247,7 +264,7 @@ func TestHTMLFormElementRequestSubmitWithSubmitter(t *testing.T) {
247
264
}
248
265
249
266
func TestHTMLFormElementPreventDefaultOnSubmitButton (t * testing.T ) {
250
- w , setup := InitFixture (t , & HTMLFormSubmitButtonFixture {})
267
+ w , setup := fixture . Init (t , & HTMLFormSubmitButtonFixture {})
251
268
setup .Setup ()
252
269
253
270
w .Submitter .AddEventListener ("click" , eventtest .NewTestHandler (func (e * event.Event ) {
@@ -258,7 +275,7 @@ func TestHTMLFormElementPreventDefaultOnSubmitButton(t *testing.T) {
258
275
}
259
276
260
277
func TestHTMLFormElementFormDataEvent (t * testing.T ) {
261
- w , setup := InitFixture (t , & HTMLFormSubmitButtonFixture {})
278
+ w , setup := fixture . Init (t , & HTMLFormSubmitButtonFixture {})
262
279
setup .Setup ()
263
280
264
281
var eventBubbles bool
@@ -300,7 +317,7 @@ func (f *HTMLFormSubmitInputFixture) Setup() {
300
317
}
301
318
302
319
func TestHTMLFormElementSubmitButtonWithClickButton (t * testing.T ) {
303
- w , setup := InitFixture (t , & HTMLFormSubmitInputFixture {})
320
+ w , setup := fixture . Init (t , & HTMLFormSubmitInputFixture {})
304
321
setup .Setup ()
305
322
306
323
w .Submitter .Click ()
@@ -311,7 +328,7 @@ func TestHTMLFormElementSubmitButtonWithClickButton(t *testing.T) {
311
328
}
312
329
313
330
func TestHTMLFormElementSubmitInputWithClickResetButton (t * testing.T ) {
314
- w , setup := InitFixture (t , & HTMLFormSubmitInputFixture {})
331
+ w , setup := fixture . Init (t , & HTMLFormSubmitInputFixture {})
315
332
setup .Setup ()
316
333
317
334
w .Submitter .SetType ("reset" )
@@ -325,14 +342,15 @@ func TestResubmitFormOn307Redirects(t *testing.T) {
325
342
submittedForm url.Values
326
343
)
327
344
328
- w , setup := InitFixture (
345
+ w , setup := fixture . Init (
329
346
t ,
330
347
& struct {
331
348
HTMLFormSubmitInputFixture
332
349
* HTTPHandlerFixture
350
+ * BaseLocationFixture
333
351
}{},
334
- BaseLocationFixture ("http://example.com/forms" ),
335
352
)
353
+ * w .BaseLocationFixture = "http://example.com/forms"
336
354
fmt .Println ("*** SETUP" )
337
355
338
356
setup .Setup ()
0 commit comments