Skip to content

Commit 038bcf5

Browse files
committed
test: Replace fixture with new package
The fixture package developer in here as a side project has been extracted to it's own package.
1 parent e7e5906 commit 038bcf5

File tree

5 files changed

+56
-203
lines changed

5 files changed

+56
-203
lines changed

go.mod

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
module github.com/gost-dom/browser
22

3-
go 1.23.4
4-
5-
toolchain go1.23.6
3+
go 1.23.6
64

75
require (
86
github.com/dop251/goja v0.0.0-20241024094426-79f3a7efcdbd
97
github.com/gost-dom/css v0.1.0
8+
github.com/gost-dom/fixture v0.1.0
109
github.com/gost-dom/v8go v0.0.0-20250226155312-422158da51fa
1110
github.com/onsi/ginkgo/v2 v2.22.2
1211
github.com/onsi/gomega v1.36.2

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad h1:a6HEuzUHeKH6hwfN/Z
1919
github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad/go.mod h1:vavhavw2zAxS5dIdcRluK6cSGGPlZynqzFM8NdvU144=
2020
github.com/gost-dom/css v0.1.0 h1:O4aXjnYonQH1EDwKysXCQOgGVLwCWd/+HJeGO15sDIE=
2121
github.com/gost-dom/css v0.1.0/go.mod h1:BYfl+dr6Dzl6RoKn4op6TynJ7GmFqP0kFCM44NEVgNs=
22+
github.com/gost-dom/fixture v0.1.0 h1:7PnEpkuww1QBOh4gyoR8updPfyosHJfxmFRY+2t05+w=
23+
github.com/gost-dom/fixture v0.1.0/go.mod h1:7mSGaBhOfi/NO+YiD426CQ1DTkko62vYxoSVRmveqqY=
2224
github.com/gost-dom/v8go v0.0.0-20250226155312-422158da51fa h1:3aeBc/+rftAe2hHJy1YvUXI90qCQpmep2n26N+Ljhl4=
2325
github.com/gost-dom/v8go v0.0.0-20250226155312-422158da51fa/go.mod h1:JQOTnkUY77lDSgrMlPMlUCLONzDS/kycRc8ZtbiZDm0=
2426
github.com/onsi/ginkgo/v2 v2.22.2 h1:/3X8Panh8/WwhU/3Ssa6rCKqPLuAkVY2I0RoyDLySlU=

html/html_form_element_submit_test.go

+52-34
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import (
1111
"github.com/gost-dom/browser/html"
1212
"github.com/gost-dom/browser/internal/gosthttp"
1313
"github.com/gost-dom/browser/internal/testing/eventtest"
14-
. "github.com/gost-dom/browser/internal/testing/exp/fixture"
1514
. "github.com/gost-dom/browser/internal/testing/gomega-matchers"
1615
"github.com/gost-dom/browser/internal/testing/htmltest"
1716
. "github.com/gost-dom/browser/testing/gomega-matchers"
17+
"github.com/gost-dom/fixture"
1818
"github.com/onsi/gomega"
1919
"github.com/onsi/gomega/types"
2020
"github.com/stretchr/testify/assert"
@@ -24,7 +24,7 @@ type InitialHTMLFixture string
2424
type BaseLocationFixture string
2525

2626
type AssertFixture struct {
27-
Fixture
27+
fixture.Fixture
2828
assert *assert.Assertions
2929
gomega gomega.Gomega
3030
}
@@ -54,7 +54,7 @@ func (f *HTTPHandlerFixture) Setup() {
5454

5555
type WindowFixture struct {
5656
AssertFixture
57-
BaseLocationFixture
57+
*BaseLocationFixture
5858
InitialHTMLFixture
5959
*HTTPHandlerFixture
6060
Window htmltest.WindowHelper
@@ -66,11 +66,17 @@ type WindowFixture struct {
6666
}
6767

6868
func (f *WindowFixture) Setup() {
69+
if f.Window.Window != nil {
70+
return
71+
}
6972
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)
7480
f.Window = htmltest.NewWindowHelper(f.TB, win)
7581

7682
f.Helper()
@@ -86,18 +92,25 @@ func (f *WindowFixture) Setup() {
8692
type DefaultWindowFixture struct {
8793
WindowFixture
8894
*HTTPHandlerFixture
95+
initialized bool
8996
}
9097

9198
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+
}
101114
}
102115

103116
func AssertType[T any](t testing.TB, actual any) (res T) {
@@ -124,9 +137,11 @@ type HTMLFormFixture struct {
124137
}
125138

126139
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"
130145
setup.Setup()
131146

132147
var submitEventDispatched bool
@@ -148,9 +163,11 @@ func TestSubmitForm(t *testing.T) {
148163
}
149164

150165
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"
154171
setup.Setup()
155172

156173
form := w.Form()
@@ -181,7 +198,7 @@ func (f *HTMLFormSubmitButtonFixture) Setup() {
181198
}
182199

183200
func TestHTMLFormElementSubmitWithClickButton(t *testing.T) {
184-
w, setup := InitFixture(t, &HTMLFormSubmitButtonFixture{})
201+
w, setup := fixture.Init(t, &HTMLFormSubmitButtonFixture{})
185202
setup.Setup()
186203

187204
w.Submitter.Click()
@@ -192,7 +209,7 @@ func TestHTMLFormElementSubmitWithClickButton(t *testing.T) {
192209
}
193210

194211
func TestHTMLFormElementSubmitWithClickButtonAndWeirdCasing(t *testing.T) {
195-
w, setup := InitFixture(t, &HTMLFormSubmitButtonFixture{})
212+
w, setup := fixture.Init(t, &HTMLFormSubmitButtonFixture{})
196213
setup.Setup()
197214

198215
w.Submitter.SetType("SuBMit")
@@ -204,7 +221,7 @@ func TestHTMLFormElementSubmitWithClickButtonAndWeirdCasing(t *testing.T) {
204221
}
205222

206223
func TestHTMLFormElementSubmitWithClickResetButton(t *testing.T) {
207-
w, setup := InitFixture(t, &HTMLFormSubmitButtonFixture{})
224+
w, setup := fixture.Init(t, &HTMLFormSubmitButtonFixture{})
208225
setup.Setup()
209226

210227
w.Submitter.SetType("reset")
@@ -213,7 +230,7 @@ func TestHTMLFormElementSubmitWithClickResetButton(t *testing.T) {
213230
}
214231

215232
func TestHTMLFormElementRequestSubmitWithoutSubmitter(t *testing.T) {
216-
w, setup := InitFixture(t, &HTMLFormSubmitButtonFixture{})
233+
w, setup := fixture.Init(t, &HTMLFormSubmitButtonFixture{})
217234
setup.Setup()
218235

219236
w.Assert().NoError(w.Form().RequestSubmit(nil))
@@ -223,7 +240,7 @@ func TestHTMLFormElementRequestSubmitWithoutSubmitter(t *testing.T) {
223240
}
224241

225242
func TestHTMLFormElementRequestSubmitPreventDefault(t *testing.T) {
226-
w, setup := InitFixture(t, &HTMLFormSubmitButtonFixture{})
243+
w, setup := fixture.Init(t, &HTMLFormSubmitButtonFixture{})
227244
setup.Setup()
228245

229246
var submitEventDispatched bool
@@ -237,7 +254,7 @@ func TestHTMLFormElementRequestSubmitPreventDefault(t *testing.T) {
237254
}
238255

239256
func TestHTMLFormElementRequestSubmitWithSubmitter(t *testing.T) {
240-
w, setup := InitFixture(t, &HTMLFormSubmitButtonFixture{})
257+
w, setup := fixture.Init(t, &HTMLFormSubmitButtonFixture{})
241258
setup.Setup()
242259

243260
w.Assert().NoError(w.Form().RequestSubmit(w.Submitter))
@@ -247,7 +264,7 @@ func TestHTMLFormElementRequestSubmitWithSubmitter(t *testing.T) {
247264
}
248265

249266
func TestHTMLFormElementPreventDefaultOnSubmitButton(t *testing.T) {
250-
w, setup := InitFixture(t, &HTMLFormSubmitButtonFixture{})
267+
w, setup := fixture.Init(t, &HTMLFormSubmitButtonFixture{})
251268
setup.Setup()
252269

253270
w.Submitter.AddEventListener("click", eventtest.NewTestHandler(func(e *event.Event) {
@@ -258,7 +275,7 @@ func TestHTMLFormElementPreventDefaultOnSubmitButton(t *testing.T) {
258275
}
259276

260277
func TestHTMLFormElementFormDataEvent(t *testing.T) {
261-
w, setup := InitFixture(t, &HTMLFormSubmitButtonFixture{})
278+
w, setup := fixture.Init(t, &HTMLFormSubmitButtonFixture{})
262279
setup.Setup()
263280

264281
var eventBubbles bool
@@ -300,7 +317,7 @@ func (f *HTMLFormSubmitInputFixture) Setup() {
300317
}
301318

302319
func TestHTMLFormElementSubmitButtonWithClickButton(t *testing.T) {
303-
w, setup := InitFixture(t, &HTMLFormSubmitInputFixture{})
320+
w, setup := fixture.Init(t, &HTMLFormSubmitInputFixture{})
304321
setup.Setup()
305322

306323
w.Submitter.Click()
@@ -311,7 +328,7 @@ func TestHTMLFormElementSubmitButtonWithClickButton(t *testing.T) {
311328
}
312329

313330
func TestHTMLFormElementSubmitInputWithClickResetButton(t *testing.T) {
314-
w, setup := InitFixture(t, &HTMLFormSubmitInputFixture{})
331+
w, setup := fixture.Init(t, &HTMLFormSubmitInputFixture{})
315332
setup.Setup()
316333

317334
w.Submitter.SetType("reset")
@@ -325,14 +342,15 @@ func TestResubmitFormOn307Redirects(t *testing.T) {
325342
submittedForm url.Values
326343
)
327344

328-
w, setup := InitFixture(
345+
w, setup := fixture.Init(
329346
t,
330347
&struct {
331348
HTMLFormSubmitInputFixture
332349
*HTTPHandlerFixture
350+
*BaseLocationFixture
333351
}{},
334-
BaseLocationFixture("http://example.com/forms"),
335352
)
353+
*w.BaseLocationFixture = "http://example.com/forms"
336354
fmt.Println("*** SETUP")
337355

338356
setup.Setup()

0 commit comments

Comments
 (0)