Mail: merkkleur SLP Software (#ac0000) en dark-mode-robuuste knop

- SlpSoftware appsettings: Email:BrandColor = #ac0000 (primary uit de admin-CSS, BR-U1-07)
- Knop als bulletproof tabelknop (bgcolor + style, rand), tekstkleur automatisch >= 4.5:1
- color-scheme/supported-color-schemes meta + prefers-color-scheme: dark blok met lichtere accentkleur
- MailColours (contrastberekening); IsValidColour-pad ongewijzigd, tests incl. injectie

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-09 11:29:00 +01:00
co-authored by Claude Sonnet 5.5
parent 3a9e4ae7aa
commit f48642e6e8
4 changed files with 151 additions and 12 deletions
@@ -185,6 +185,55 @@ public class MailTemplateRendererTests
mail.Html.Should().NotContain("red;}");
}
[Fact]
public void AnInvalidBrandColour_NeverReachesTheDarkModeBlockEither()
{
foreach (var bad in new[] { "red;}</style><script>x</script>", "#12345", "#12345g", "url(x)", "#ac0000;background:red" })
{
var mail = _renderer.Render(MailKind.Invitation, "nl", Model() with { BrandColor = bad });
mail.Html.Should().NotContain("<script>").And.NotContain("url(x)").And.NotContain("background:red;}")
.And.Contain("#1f2937");
}
}
[Theory]
[InlineData("#ac0000")]
[InlineData("#5f6a58")]
[InlineData("#2b6cb0")]
[InlineData("#1f2937")]
[InlineData("#ffffff")]
[InlineData("#000000")]
[InlineData("#ffee00")]
public void TheButton_IsReadableInLightAndDark_AndHasABorder(string brand)
{
var mail = _renderer.Render(MailKind.Invitation, "nl", Model() with { BrandColor = brand });
var html = mail.Html;
// bulletproof table button: bgcolor attribute and style, a visible border
html.Should().Contain($"bgcolor=\"{brand}\"").And.Contain($"border:2px solid {brand}");
// client hints for dark mode
html.Should().Contain("name=\"color-scheme\" content=\"light dark\"").And.Contain("supported-color-schemes")
.And.Contain("@media (prefers-color-scheme: dark)");
var text = MailColours.ReadableText(brand);
MailColours.Contrast(text, brand).Should().BeGreaterThanOrEqualTo(4.5);
html.Should().Contain($"background:{brand};color:{text};");
var dark = MailColours.DarkAccent(brand, "#1f2937");
var darkText = MailColours.ReadableText(dark);
MailColours.Contrast(dark, "#1f2937").Should().BeGreaterThanOrEqualTo(4.5); // heading and border on the dark card
MailColours.Contrast(darkText, dark).Should().BeGreaterThanOrEqualTo(4.5); // button text on the dark button
html.Should().Contain($".mail-btn a{{background:{dark} !important;color:{darkText} !important;");
html.Should().Contain($".mail-accent{{color:{dark} !important;");
}
[Fact]
public void TheSlpRed_GivesAWhiteButtonText()
{
MailColours.ReadableText("#ac0000").Should().Be("#ffffff");
MailColours.Contrast("#ffffff", "#ac0000").Should().BeGreaterThan(7);
}
[Fact]
public void LanguageResolver_UsesUserThenSiteDefaultThenDutch()
{