template testing helpers

This commit is contained in:
41666 2025-04-06 19:57:42 -07:00
parent df33164b08
commit 1c533926ca
5 changed files with 84 additions and 34 deletions

View file

@ -1,31 +1,20 @@
package components_test
import (
"bytes"
"fmt"
"html/template"
"testing"
"git.sapphic.engineer/roleypoly/v4/presentation"
"git.sapphic.engineer/roleypoly/v4/templates"
"git.sapphic.engineer/roleypoly/v4/templates/templatetesting"
"git.sapphic.engineer/roleypoly/v4/types"
"git.sapphic.engineer/roleypoly/v4/types/fixtures"
"git.sapphic.engineer/roleypoly/v4/utils"
"github.com/stretchr/testify/assert"
)
var (
Templates = template.Must(template.ParseFS(templates.FS, "components/*.html"))
)
func renderRole(t *testing.T, c *types.Category, r *types.Role, s bool) string {
data := presentation.Role(c, r, s)
buf := bytes.Buffer{}
err := Templates.ExecuteTemplate(&buf, "role.html", data)
if err != nil {
t.Fatal("template failed to render", err)
}
return buf.String()
return templatetesting.Template(t, "components/role", data)
}
func TestRole(t *testing.T) {