package homeconnect
import (
"bytes"
"html/template"
"strings"
"testing"
)
func render(t *testing.T, name string, data any) string {
t.Helper()
view, err := template.New("view").ParseFS(Templates(), "templates/*.html")
if err != nil {
t.Fatal(err)
}
var out bytes.Buffer
if err := view.ExecuteTemplate(&out, name, data); err != nil {
t.Fatal(err)
}
return out.String()
}
func TestCallerTranslationsAndScriptlessActions(t *testing.T) {
labels := map[string]string{"en": "Continue", "de": "Weiter", "es": "Continuar", "fr": "Continuer", "it": "Continua", "pt": "Continuar", "nl": "Doorgaan", "pl": "Kontynuuj", "ar": "متابعة", "ja": "続行", "zh": "继续", "ko": "계속"}
for locale, label := range labels {
t.Run(locale, func(t *testing.T) {
data := PageData{Title: label, Body: label, Address: "person@example.test", Action: "/account/home", ActionLabel: label, CancelLabel: label, PostAction: true}
html := render(t, "home-connect", data)
for _, want := range []string{label, `method="post" action="/account/home"`, `person@example.test`, `rst-btn="ghost"`} {
if !strings.Contains(html, want) {
t.Fatalf("missing %q", want)
}
}
if strings.Contains(html, "`, Address: `
`, Action: "javascript:bad", ActionLabel: "Go"})
if strings.Contains(html, "