41 lines
1.3 KiB
Go
41 lines
1.3 KiB
Go
package builder
|
|
|
|
import (
|
|
"bytes"
|
|
"gitea-mail-templates/tools/upstream"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestParagraphRolesPreserveOfficialActions(t *testing.T) {
|
|
source := `<html><body><p>{{.locale.Tr "mail.hi_user_x" .Username}}</p><p>{{.locale.Tr "mail.register_notify.text_2"}}</p>{{printf "<p>not static</p>"}}<p class="existing">Kept</p></body></html>`
|
|
result, err := paragraphRoles([]byte(source), "register_notify")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
want := strings.Replace(source, `<p>`, `<p class="email-heading">`, 1)
|
|
want = strings.Replace(want, `<p>`, `<p class="email-subtext">`, 1)
|
|
if string(result) != want {
|
|
t.Fatalf("unexpected presentation annotation: %s", result)
|
|
}
|
|
}
|
|
|
|
func TestSharedAlignmentFailsOnDrift(t *testing.T) {
|
|
s, err := upstream.LoadPinned(filepath.Join("..", ".."))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
name := "mail/user/auth/activate.tmpl"
|
|
original := bytes.Clone(s.Templates[name])
|
|
s.Templates[name] = bytes.Replace(original, []byte(`href="{{$activate_url}}"`), []byte(`href="changed"`), 1)
|
|
if _, err := AdaptOfficial(s, name); err == nil {
|
|
t.Fatal("unreviewed URL anchor accepted")
|
|
}
|
|
s.Templates[name] = original
|
|
delete(s.Locales["en-US"], "mail.activate_account")
|
|
if _, err := AdaptOfficial(s, name); err == nil {
|
|
t.Fatal("missing button key accepted")
|
|
}
|
|
}
|