From 2cdcb9d868afa1bbc958957bddb6d43aaae98e3c Mon Sep 17 00:00:00 2001 From: Sluijsens Date: Mon, 9 Nov 2026 13:21:58 +0100 Subject: [PATCH] Mail: donker logo voor dark mode (Email:LogoDarkUrl) en lichte plaat achter het logo - Optionele Email:LogoDarkUrl, zelfde validatie als LogoUrl; leeg = geen swap - Twee img-klassen; dark-blok verbergt het lichte logo (incl. mso-hide) en toont het donkere - Lichte afgeronde plaat (bgcolor + vlak verloop) achter het logo als vangnet voor clients die media queries negeren of inverteren - ASF: LogoDarkUrl = /admin/brand-logo-on-dark.png (publiek bereikbaar gecontroleerd); SLP leeg (geen on-dark logo) Co-Authored-By: Claude Sonnet 5.5 --- .../HostConfigurationTests.cs | 1 + .../appsettings.json | 1 + .../Email/EmailRulesAndRendererTests.cs | 42 +++++++++++++++++++ .../Email/MailSoftFailureTests.cs | 2 + src/SlpModularCms.Core/Email/EmailOptions.cs | 6 +++ .../Email/EmailOptionsValidator.cs | 2 + .../Email/IdentityMailService.cs | 3 +- .../Email/MailTemplateRenderer.cs | 21 +++++++++- src/SlpModularCms.Core/Email/MailTypes.cs | 3 +- 9 files changed, 78 insertions(+), 3 deletions(-) diff --git a/src/SlpModularCms.Api.AndreaSlopFotografie.Tests/HostConfigurationTests.cs b/src/SlpModularCms.Api.AndreaSlopFotografie.Tests/HostConfigurationTests.cs index cfc1588..de0ea90 100644 --- a/src/SlpModularCms.Api.AndreaSlopFotografie.Tests/HostConfigurationTests.cs +++ b/src/SlpModularCms.Api.AndreaSlopFotografie.Tests/HostConfigurationTests.cs @@ -85,5 +85,6 @@ public class HostConfigurationTests config["Email:Smtp:Password"].Should().BeNullOrEmpty(); config["Email:FromAddress"].Should().NotBeNullOrEmpty(); config["Email:LogoUrl"].Should().Be("/admin/brand-logo-on-light.png"); + config["Email:LogoDarkUrl"].Should().Be("/admin/brand-logo-on-dark.png"); } } diff --git a/src/SlpModularCms.Api.AndreaSlopFotografie/appsettings.json b/src/SlpModularCms.Api.AndreaSlopFotografie/appsettings.json index 6343757..9840e68 100644 --- a/src/SlpModularCms.Api.AndreaSlopFotografie/appsettings.json +++ b/src/SlpModularCms.Api.AndreaSlopFotografie/appsettings.json @@ -58,6 +58,7 @@ "FromName": "Andrea Slop Fotografie", "AllowedFromAddresses": [], "LogoUrl": "/admin/brand-logo-on-light.png", + "LogoDarkUrl": "/admin/brand-logo-on-dark.png", "BrandColor": "#5f6a58", "Smtp": { "Host": "", diff --git a/src/SlpModularCms.Core.Tests/Email/EmailRulesAndRendererTests.cs b/src/SlpModularCms.Core.Tests/Email/EmailRulesAndRendererTests.cs index 813f5be..d8c27b2 100644 --- a/src/SlpModularCms.Core.Tests/Email/EmailRulesAndRendererTests.cs +++ b/src/SlpModularCms.Core.Tests/Email/EmailRulesAndRendererTests.cs @@ -227,6 +227,48 @@ public class MailTemplateRendererTests html.Should().Contain($".mail-accent{{color:{dark} !important;"); } + private const string DarkLogo = "https://t.nl/admin/brand-logo-on-dark.png"; + + [Fact] + public void WithADarkLogo_BothImagesAreThere_AndDarkModeSwapsThem() + { + var html = _renderer.Render(MailKind.Invitation, "nl", Model() with { LogoDarkUrl = DarkLogo }).Html; + + html.Should().Contain("class=\"mail-logo-light\" src=\"https://t.nl/admin/brand-logo-on-light.png\"") + .And.Contain($"class=\"mail-logo-dark\" src=\"{DarkLogo}\""); + // the dark logo is hidden by default (with the Outlook safety net) ... + html.Should().MatchRegex("class=\"mail-logo-dark\"[^>]*display:none;[^>]*mso-hide:all"); + // ... and the dark block swaps them and drops the plate + html.Should().Contain(".mail-logo-light{display:none !important").And.Contain(".mail-logo-dark{display:block !important") + .And.Contain(".mail-plate{background:transparent !important"); + } + + [Fact] + public void WithoutADarkLogo_ThereIsNoSwap_AndTheLightLogoKeepsItsLightPlate() + { + var html = _renderer.Render(MailKind.Invitation, "nl", Model()).Html; + + html.Should().NotContain("mail-logo-dark").And.NotContain(".mail-logo-light{").And.NotContain(".mail-plate{"); + // the plate survives clients that invert backgrounds or ignore the media query + html.Should().Contain("class=\"mail-plate\" bgcolor=\"#f3f4f6\"").And.Contain("background-image:linear-gradient(#f3f4f6,#f3f4f6)"); + } + + [Fact] + public void ADarkLogoWithoutALightLogo_IsIgnored_AndTheSiteNameIsShown() + { + var html = _renderer.Render(MailKind.Invitation, "nl", Model() with { LogoUrl = null, LogoDarkUrl = DarkLogo }).Html; + + html.Should().NotContain("brand-logo-on-dark").And.NotContain("mail-logo-dark"); + } + + [Fact] + public void ADarkLogoUrl_IsHtmlEncoded_NotInterpreted() + { + var html = _renderer.Render(MailKind.Invitation, "nl", Model() with { LogoDarkUrl = "https://t.nl/x.png\">" }).Html; + + html.Should().NotContain("