Skip to content

Commit 81f8ce8

Browse files
committed
test: Convert HTMLForm IDL attribute tests
Convert tests for method and action IDL attributes to testify suite.
1 parent aad9b01 commit 81f8ce8

File tree

1 file changed

+68
-58
lines changed

1 file changed

+68
-58
lines changed

html/html_form_element_test.go

+68-58
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,91 @@
11
package html_test
22

33
import (
4+
"fmt"
45
"net/http"
56
"net/url"
7+
"testing"
68

79
"github.com/gost-dom/browser/dom"
810
"github.com/gost-dom/browser/dom/event"
911
"github.com/gost-dom/browser/html"
1012
. "github.com/gost-dom/browser/html"
1113
"github.com/gost-dom/browser/internal/gosthttp"
1214
"github.com/gost-dom/browser/internal/testing/eventtest"
15+
"github.com/gost-dom/browser/internal/testing/gosttest"
1316
. "github.com/gost-dom/browser/internal/testing/htmltest"
1417
. "github.com/gost-dom/browser/testing/gomega-matchers"
18+
"github.com/stretchr/testify/suite"
1519

1620
. "github.com/onsi/ginkgo/v2"
1721
. "github.com/onsi/gomega"
1822
)
1923

20-
var _ = Describe("HTML Form", func() {
21-
Describe("Method property", func() {
22-
var form HTMLFormElement
23-
BeforeEach(func() {
24-
doc := NewHTMLDocument(nil)
25-
form = doc.CreateElement("form").(HTMLFormElement)
26-
})
27-
28-
Describe("Setting the value", func() {
29-
It("Should update the attribute", func() {
30-
form.SetMethod("new value")
31-
Expect(form).To(HaveAttribute("method", "new value"))
32-
Expect(form).ToNot(BeNil())
33-
})
34-
})
35-
36-
Describe("Getting the value", func() {
37-
It("Should return 'get' by default", func() {
38-
Expect(form.Method()).To(Equal("get"))
39-
})
40-
41-
It("Should return 'post' when set to 'post', 'POST', 'PoSt', etc.", func() {
42-
for _, value := range []string{"post", "POST", "PoSt"} {
43-
form.SetMethod(value)
44-
Expect(form.Method()).To(Equal("post"))
45-
}
46-
})
47-
48-
It("Should return 'get' when assigned an invalid value", func() {
49-
form.SetMethod("post")
50-
Expect(form.Method()).To(Equal("post"))
51-
form.SetMethod("invalid")
52-
Expect(form.Method()).To(Equal("get"))
53-
})
54-
})
55-
})
24+
type HTMLFormElementTestSuite struct {
25+
gosttest.GomegaSuite
26+
win html.Window
27+
doc html.HTMLDocument
28+
form html.HTMLFormElement
29+
}
30+
31+
func TestHTMLFormElement(t *testing.T) {
32+
suite.Run(t, new(HTMLFormElementTestSuite))
33+
}
34+
35+
func (s *HTMLFormElementTestSuite) SetupTest() {
36+
s.win = NewWindowHelper(s.T(), NewWindow(WindowOptions{
37+
BaseLocation: "http://example.com/forms/example-form.html?original-query=original-value",
38+
}))
39+
40+
s.doc = NewHTMLDocument(s.win)
41+
s.form = s.doc.CreateElement("form").(HTMLFormElement)
42+
}
43+
44+
func (s *HTMLFormElementTestSuite) createForm() HTMLFormElement {
45+
return s.doc.CreateElement("form").(HTMLFormElement)
46+
}
47+
48+
func (s *HTMLFormElementTestSuite) TestMethodIDLAttribute() {
49+
form := s.createForm()
50+
51+
s.Assert().Equal("get", form.Method(), "Default value for HTMLFormElement.method")
52+
53+
form.SetMethod("new value")
54+
s.Expect(form).To(HaveAttribute("method", "new value"),
55+
"Content attribute when setting IDL to invalid value")
56+
s.Expect(form.Method()).To(Equal("get"),
57+
"IDL method attribute when set to an invalid value")
58+
59+
for _, value := range []string{"post", "POST", "PoSt"} {
60+
form.SetMethod(value)
61+
s.Expect(form.Method()).To(Equal("post"),
62+
fmt.Sprintf("IDL method attribute, set to %s", value),
63+
)
64+
}
65+
}
66+
67+
func (s *HTMLFormElementTestSuite) TestActionIDLAttribute() {
68+
form := s.createForm()
69+
70+
s.Assert().Equal(s.win.LocationHREF(), form.Action(), "Default value for action IDL attribute")
71+
72+
form.SetAction("/foo-bar")
73+
s.Expect(form).
74+
To(HaveAttribute("action", "/foo-bar"), "Action content attribute with absolute path")
75+
s.Expect(form.Action()).
76+
To(Equal("http://example.com/foo-bar"), "Action IDL attribute when set to an absolute path")
77+
78+
form.SetAttribute("action", "submit-target")
79+
s.Expect(form).To(
80+
HaveAttribute("action", "submit-target"),
81+
"Action content attribute with relative path")
82+
83+
s.Expect(form.Action()).To(
84+
Equal("http://example.com/forms/submit-target"),
85+
"Action IDL attribute when set to a relative path")
86+
}
5687

88+
var _ = Describe("HTML Form", func() {
5789
Describe("Submit behaviour", func() {
5890
var window WindowHelper
5991
var requests []*http.Request
@@ -103,28 +135,6 @@ var _ = Describe("HTML Form", func() {
103135
})
104136

105137
Describe("Method and action behaviour", func() {
106-
107-
Describe("Action", func() {
108-
Describe("Get", func() {
109-
It("Should return the document location when not set", func() {
110-
Expect(form.Action()).To(Equal(window.Location().Href()))
111-
})
112-
})
113-
114-
Describe("Set", func() {
115-
It(
116-
"Should update the action attribute, and update action property to relative url",
117-
func() {
118-
form.SetAction("/foo-bar")
119-
Expect(
120-
form,
121-
).To(HaveAttribute("action", "/foo-bar"))
122-
Expect(form.Action()).To(Equal("http://example.com/foo-bar"))
123-
},
124-
)
125-
})
126-
})
127-
128138
Describe("No method of action specified", func() {
129139
It("Should make a GET request to the original location", func() {
130140
form.Submit()

0 commit comments

Comments
 (0)