Skip to content

Commit

Permalink
feat(domtest): add queryAll helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
crhntr committed Jul 9, 2024
1 parent a021a0b commit 2b1301d
Show file tree
Hide file tree
Showing 4 changed files with 321 additions and 180 deletions.
47 changes: 0 additions & 47 deletions domtest/error.go

This file was deleted.

133 changes: 0 additions & 133 deletions domtest/error_test.go

This file was deleted.

75 changes: 75 additions & 0 deletions domtest/query.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package domtest

import (
"net/http"

"golang.org/x/net/html/atom"

"github.com/crhntr/dom/spec"
)

func DocumentResponseQuery(t T, res *http.Response, statusCode int, selector string) spec.Element {
t.Helper()
if res.StatusCode != statusCode {
t.Errorf("unexpected status code: %d", res.StatusCode)
}

document := Response(t, res)
if document == nil {
return nil
}

errEl := document.QuerySelector(selector)
if errEl == nil {
t.Errorf("error message element not found for query: %s", selector)
return nil
}
return errEl
}

func DocumentFragmentQuery(t T, res *http.Response, statusCode int, selector string, parent atom.Atom) spec.Element {
t.Helper()
if res.StatusCode != statusCode {
t.Errorf("unexpected status code: %d", res.StatusCode)
}

document := DocumentFragmentResponse(t, res, parent)
if document == nil {
return nil
}

errEl := document.QuerySelector(selector)
if errEl == nil {
t.Errorf("error message element not found for query: %s", selector)
return nil
}
return errEl
}

func DocumentResponseQueryAll(t T, res *http.Response, statusCode int, selector string) spec.NodeList[spec.Element] {
t.Helper()
if res.StatusCode != statusCode {
t.Errorf("unexpected status code: %d", res.StatusCode)
}

document := Response(t, res)
if document == nil {
return nil
}

return document.QuerySelectorAll(selector)
}

func DocumentFragmentQueryAll(t T, res *http.Response, statusCode int, selector string, parent atom.Atom) spec.NodeList[spec.Element] {
t.Helper()
if res.StatusCode != statusCode {
t.Errorf("unexpected status code: %d", res.StatusCode)
}

document := DocumentFragmentResponse(t, res, parent)
if document == nil {
return nil
}

return document.QuerySelectorAll(selector)
}
Loading

0 comments on commit 2b1301d

Please sign in to comment.