11package html_test
22
33import (
4+ "log/slog"
45 "net/http"
56 "net/url"
67 "reflect"
@@ -9,13 +10,15 @@ import (
910 "github.com/gost-dom/browser/dom/event"
1011 "github.com/gost-dom/browser/html"
1112 "github.com/gost-dom/browser/internal/gosthttp"
13+ "github.com/gost-dom/browser/internal/testing/browsertest"
1214 "github.com/gost-dom/browser/internal/testing/eventtest"
1315 "github.com/gost-dom/browser/internal/testing/fixtures"
1416 . "github.com/gost-dom/browser/internal/testing/gomega-matchers"
1517 "github.com/gost-dom/browser/internal/testing/gosttest"
1618 "github.com/gost-dom/browser/internal/testing/htmltest"
1719 . "github.com/gost-dom/browser/testing/gomega-matchers"
1820 "github.com/gost-dom/fixture"
21+ "github.com/stretchr/testify/assert"
1922)
2023
2124type HTTPHandlerFixture struct { * http.ServeMux }
@@ -296,6 +299,7 @@ func TestHTMLFormElementSubmitInputWithClickResetButton(t *testing.T) {
296299}
297300
298301func TestResubmitFormOn307Redirects (t * testing.T ) {
302+ assert := assert .New (t )
299303 w , setup := fixture .Init (t , & HTMLFormSubmitInputFixture {})
300304 w .BaseLocation = "http://example.com/forms"
301305 setup .Setup ()
@@ -309,6 +313,25 @@ func TestResubmitFormOn307Redirects(t *testing.T) {
309313 form .SetAction ("/form-destination" )
310314 form .Submit ()
311315
312- w .Assert ().Equal (1 , len (rec .Requests ), "Request sent to the redirected location" )
313- w .Assert ().Equal ([]string {"bar" }, rec .Single ().PostForm ["foo" ])
316+ assert .Equal (1 , len (rec .Requests ), "Request sent to the redirected location" )
317+ assert .Equal ([]string {"bar" }, rec .Single ().PostForm ["foo" ])
318+ }
319+
320+ func TestFormSubmitDisplaysPageOnNewLocation (t * testing.T ) {
321+ h := gosttest.HttpHandlerMap {
322+ "/" : gosttest .StaticHTML (`<body>
323+ <form method="post" action="/post/action">
324+ <input type="submit" id="btn">Submit</input>
325+ </form>
326+ </body>` ),
327+ "/post/action" : gosttest .StaticHTML (`<body><h1>Target page</h1></body>` ),
328+ }
329+ b := browsertest .InitBrowser (t , h , nil , browsertest .WithMinLogLevel (slog .LevelDebug ))
330+ win := b .OpenWindow ("http://example.com/" )
331+ t .Log (win .HTMLDocument ().DocumentElement ().OuterHTML ())
332+ btn := win .HTMLDocument ().GetHTMLElementById ("btn" )
333+ btn .Click ()
334+ t .Log (win .HTMLDocument ().Body ().OuterHTML ())
335+ h1 := win .HTMLDocument ().MustQuerySelectorHTML ("h1" )
336+ assert .Equal (t , "Target page" , h1 .TextContent ())
314337}
0 commit comments