release / go (push) Successful in 1m55s
release / web (push) Successful in 1m27s
release / govulncheck (push) Successful in 21s
release / integration (push) Successful in 4m31s
release / android (push) Successful in 4m43s
release / Build signed APK (push) Successful in 5m23s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 25s
release / Verify release artifacts (tag releases only) (push) Skipped
Where Minstrel names itself to a person it now gives its full name: - the README heading, logo text and first line; - the default app name, which feeds the browser tab, link previews and the header; - the login heading, which now follows the app-name setting too; - the emails' brand line and sign-off; - the default From name for email. On a phone the header shows the mark alone, as the nav shows its icons alone; the left lane is too narrow for the full name, and the link's label still names it. Running text, email subjects, code identifiers and the Android launcher label keep "Minstrel". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
125 lines
4.5 KiB
Go
125 lines
4.5 KiB
Go
package mailer
|
|
|
|
import (
|
|
"regexp"
|
|
"strings"
|
|
"testing"
|
|
"testing/fstest"
|
|
)
|
|
|
|
// Every email Minstrel sends goes out in the one layout: the Fabled Minstrel name,
|
|
// its heading on the card, and a footer naming the sending server and why.
|
|
func TestEveryEmailIsFramedByTheLayout(t *testing.T) {
|
|
reset := func() (string, string, error) {
|
|
return RenderResetEmail(ResetEmailVars{
|
|
Username: "alice", ResetURL: "https://music.example/reset/abc", ExpiryHours: 1, Server: "https://music.example",
|
|
})
|
|
}
|
|
smtpTest := func() (string, string, error) { return RenderSMTPTestEmail("https://music.example/") }
|
|
|
|
for name, render := range map[string]func() (string, string, error){"reset": reset, "smtp test": smtpTest} {
|
|
text, html, err := render()
|
|
if err != nil {
|
|
t.Fatalf("%s: %v", name, err)
|
|
}
|
|
for _, want := range []string{
|
|
`">Fabled Minstrel</td>`,
|
|
`<h1 class="m-heading" style=`,
|
|
"Sent by the Minstrel server at https://music.example because ",
|
|
"— Fabled Minstrel",
|
|
} {
|
|
if !strings.Contains(html, want) {
|
|
t.Errorf("%s html is missing %q", name, want)
|
|
}
|
|
}
|
|
if !strings.Contains(text, "Sent by the Minstrel server at https://music.example because ") ||
|
|
!strings.HasSuffix(strings.TrimSpace(text), "— Fabled Minstrel") {
|
|
t.Errorf("%s text lacks the layout's footer:\n%s", name, text)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestFrameWithoutAPublicAddress(t *testing.T) {
|
|
content := fstest.MapFS{"c.txt": {Data: []byte("Hi.")}, "c.html": {Data: []byte("<p>Hi.</p>")}}
|
|
text, html, err := Render(content, "c.txt", "c.html", nil, Frame{
|
|
Heading: "Hello", Reason: "you asked", NotificationSettings: true,
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, body := range []string{text, html} {
|
|
if !strings.Contains(body, "Sent by your Minstrel server because you asked.") {
|
|
t.Errorf("footer should name the server generically:\n%s", body)
|
|
}
|
|
if !strings.Contains(body, "under Settings → Notifications") || strings.Contains(body, "http") {
|
|
t.Errorf("with no address, the settings line says where to look, without a link:\n%s", body)
|
|
}
|
|
}
|
|
}
|
|
|
|
// A misspelt style name fails the render rather than shipping an unstyled email.
|
|
func TestUnknownStyleFailsTheRender(t *testing.T) {
|
|
content := fstest.MapFS{"c.txt": {Data: []byte("x")}, "c.html": {Data: []byte(`<p style="{{style "lnik"}}">x</p>`)}}
|
|
if _, _, err := Render(content, "c.txt", "c.html", nil, Frame{Heading: "h", Reason: "r"}); err == nil {
|
|
t.Fatal("want an error for an unknown style")
|
|
}
|
|
}
|
|
|
|
// An email is dark unless the reader's system is light. Every element drawn
|
|
// in a dark colour carries the class that gives it the light one, and every
|
|
// style with a colour has light colours to give.
|
|
func TestEveryColouredElementFollowsALightTheme(t *testing.T) {
|
|
for name, s := range styles {
|
|
if strings.Contains(s, "#") && name != "button" {
|
|
if _, ok := lightStyles[name]; !ok {
|
|
t.Errorf("style %q has a colour and no light colours", name)
|
|
}
|
|
}
|
|
}
|
|
reset, err := func() (string, error) {
|
|
_, html, err := RenderResetEmail(ResetEmailVars{
|
|
Username: "alice", ResetURL: "https://music.example/reset/abc", ExpiryHours: 1, Server: "https://music.example",
|
|
})
|
|
return html, err
|
|
}()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
_, smtpTest, err := RenderSMTPTestEmail("https://music.example/")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for name, html := range map[string]string{"reset": reset, "smtp test": smtpTest} {
|
|
if !strings.Contains(html, "@media (prefers-color-scheme: light)") ||
|
|
!strings.Contains(html, ".m-card { background:"+lightCard+" !important;") {
|
|
t.Errorf("%s html has no light theme", name)
|
|
}
|
|
for _, tag := range unthemed(html) {
|
|
t.Errorf("%s: %s is drawn dark with no light class", name, tag)
|
|
}
|
|
}
|
|
if got := unthemed(`<p style="color:` + colourText + `;">x</p>`); len(got) != 1 {
|
|
t.Errorf("an element without its class went unnoticed: %v", got)
|
|
}
|
|
}
|
|
|
|
// unthemed lists the tags in html whose inline style uses a dark colour that
|
|
// has a light one, but which carry no m- class. A button is the action
|
|
// colour with its own text colour, the same in both themes.
|
|
func unthemed(html string) []string {
|
|
dark := []string{colourPage, colourCard, colourBorder, colourText, colourSecondary, colourTertiary, colourLink}
|
|
var out []string
|
|
for _, tag := range regexp.MustCompile(`<[a-z0-9]+\s[^>]*style="[^"]*"[^>]*>`).FindAllString(html, -1) {
|
|
if strings.Contains(tag, colourAction) {
|
|
continue
|
|
}
|
|
for _, c := range dark {
|
|
if strings.Contains(tag, c) && !strings.Contains(tag, `class="m-`) {
|
|
out = append(out, tag)
|
|
break
|
|
}
|
|
}
|
|
}
|
|
return out
|
|
}
|