This commit is contained in:
@@ -4,9 +4,11 @@
|
||||
package integration
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"testing"
|
||||
|
||||
"gitea.dev/modules/test"
|
||||
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
@@ -17,7 +19,7 @@ type HTMLDoc struct {
|
||||
}
|
||||
|
||||
// NewHTMLParser parse html file
|
||||
func NewHTMLParser(t testing.TB, body *bytes.Buffer) *HTMLDoc {
|
||||
func NewHTMLParser(t testing.TB, body io.Reader) *HTMLDoc {
|
||||
t.Helper()
|
||||
doc, err := goquery.NewDocumentFromReader(body)
|
||||
assert.NoError(t, err)
|
||||
@@ -39,6 +41,7 @@ func (doc *HTMLDoc) Find(selector string) *goquery.Selection {
|
||||
|
||||
// AssertHTMLElement check if the element by selector exists or does not exist depending on checkExists
|
||||
func AssertHTMLElement[T int | bool](t testing.TB, doc *HTMLDoc, selector string, checkExists T) {
|
||||
t.Helper()
|
||||
sel := doc.doc.Find(selector)
|
||||
switch v := any(checkExists).(type) {
|
||||
case bool:
|
||||
@@ -47,3 +50,13 @@ func AssertHTMLElement[T int | bool](t testing.TB, doc *HTMLDoc, selector string
|
||||
assert.Equal(t, v, sel.Length())
|
||||
}
|
||||
}
|
||||
|
||||
func assertHTMLEq(t testing.TB, expected, actual string) {
|
||||
t.Helper()
|
||||
if expected == actual { // fast path
|
||||
return
|
||||
}
|
||||
exp := test.NormalizeHTMLAttributes(t, expected)
|
||||
act := test.NormalizeHTMLAttributes(t, actual)
|
||||
assert.Equal(t, exp, act)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user