Hero: tekst-only regio alleen bij Hero:TextOnlyRegion (aan voor SLP, uit voor ASF: de ingebakken hero blijft)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-16 16:57:10 +01:00
co-authored by Claude Sonnet 5.5
parent d3525c1316
commit 0b003f5795
9 changed files with 61 additions and 18 deletions
@@ -6,7 +6,10 @@ using SlpModularCms.Modules.Hero.Services;
namespace SlpModularCms.Modules.Hero.Tests;
/// <summary>A hero without slides (SLP Software): the host writes the title, the lead and the buttons into the first HTML.</summary>
/// <summary>
/// A hero without slides (SLP Software): when the site asks for it (<c>Hero:TextOnlyRegion</c>) the host writes the
/// title, the lead and the buttons into the first HTML; otherwise (ASF) the baked page stays.
/// </summary>
public class HeroTextOnlyTests
{
private static PublicHeroDto TextOnly(string title = "Websites,\napps\n& meer.", string? tagline = null, string? lead = "Een lead.", params HeroButtonDto[] buttons)
@@ -17,7 +20,7 @@ public class HeroTextOnlyTests
{
var hero = TextOnly(buttons: [new HeroButtonDto("Bekijk pakketten", "#pakketten"), new HeroButtonDto("Plan een gesprek", "#contact")]);
var injection = HeroPictureRenderer.Render(hero);
var injection = HeroPictureRenderer.Render(hero, textOnlyRegion: true);
injection.Region.Should().Be(
"<h1 class=\"cms-hero-title\"><span class=\"cms-hero-title-lines\">Websites,<br>apps<br>&amp; meer.</span></h1>" +
@@ -27,10 +30,19 @@ public class HeroTextOnlyTests
injection.IsEmpty.Should().BeFalse();
}
[Fact]
public void WithoutTheSiteAskingForIt_AHeroWithoutSlides_LeavesTheBakedHero()
{
var hero = TextOnly(buttons: [new HeroButtonDto("Knop", "#x")]);
HeroPictureRenderer.Render(hero).IsEmpty.Should().BeTrue();
HeroPictureRenderer.Render(hero, textOnlyRegion: false).IsEmpty.Should().BeTrue();
}
[Fact]
public void WithoutALead_OrButtons_ThosePartsAreLeftOut_AndATaglineComesFirst()
{
var injection = HeroPictureRenderer.Render(TextOnly("Titel", "Label", null));
var injection = HeroPictureRenderer.Render(TextOnly("Titel", "Label", null), textOnlyRegion: true);
injection.Region.Should().Be("<h1 class=\"cms-hero-title\"><span class=\"cms-hero-tagline\">Label</span> <span class=\"cms-hero-title-lines\">Titel</span></h1>");
}
@@ -38,30 +50,41 @@ public class HeroTextOnlyTests
[Fact]
public void TheLead_KeepsItsLineBreaks_AndEverythingIsEncoded()
{
var injection = HeroPictureRenderer.Render(TextOnly("<b>x</b>", null, "a & b\nc \"d\"", new HeroButtonDto("<i>", "/p?a=1&b=2")));
var injection = HeroPictureRenderer.Render(TextOnly("<b>x</b>", null, "a & b\nc \"d\"", new HeroButtonDto("<i>", "/p?a=1&b=2")), textOnlyRegion: true);
injection.Region.Should().Contain("&lt;b&gt;x&lt;/b&gt;").And.Contain("a &amp; b<br>c &quot;d&quot;").And.Contain("href=\"/p?a=1&amp;b=2\">&lt;i&gt;</a>");
injection.Region.Should().NotContain("<b>").And.NotContain("<i>");
}
[Fact]
public void AHeroWithSlidesThatAreAllUnusable_StaysEmpty_AsForTheAsfSite()
public void AHeroWithSlidesThatAreAllUnusable_StaysEmpty_EvenWhenTheSiteAsksForText()
{
var hero = new PublicHeroDto("single", "Titel", null, null, [], [new PublicSlideDto("x", "", false, new PublicImageDto(1, 1, new FocusDto(0.5, 0.5, 1), "/m.webp", []))]);
HeroPictureRenderer.Render(hero).IsEmpty.Should().BeTrue();
HeroPictureRenderer.Render(hero, textOnlyRegion: true).IsEmpty.Should().BeTrue();
}
[Fact]
public async Task TheTransform_FillsTheTextRegion_AndLeavesThePreloadRegionAlone()
private const string Page = "<head><!--CMS:HERO-PRELOAD--><!--/CMS:HERO-PRELOAD--></head><body><!--CMS:HERO-HTML-->baked<!--/CMS:HERO-HTML--></body>";
private static HeroHtmlTransform Transform(bool textOnly)
{
var model = Substitute.For<IHeroPageModel>();
model.GetAsync(default).ReturnsForAnyArgs(TextOnly());
const string page = "<head><!--CMS:HERO-PRELOAD--><!--/CMS:HERO-PRELOAD--></head><body><!--CMS:HERO-HTML-->baked<!--/CMS:HERO-HTML--></body>";
return new HeroHtmlTransform(model, Options.Create(new HeroOptions { TextOnlyRegion = textOnly }));
}
var html = await new HeroHtmlTransform(model).ApplyAsync(page, new HtmlTransformContext("https://x"), default);
[Fact]
public async Task TheTransform_FillsTheTextRegion_WhenTheSiteAsksForIt_AndLeavesThePreloadRegionAlone()
{
var html = await Transform(textOnly: true).ApplyAsync(Page, new HtmlTransformContext("https://x"), default);
html.Should().Contain("<!--CMS:HERO-HTML--><h1 class=\"cms-hero-title\">").And.NotContain("baked");
html.Should().Contain("<!--CMS:HERO-PRELOAD--><!--/CMS:HERO-PRELOAD-->");
}
[Fact]
public async Task TheTransform_LeavesTheWholePageAlone_WhenTheSiteDoesNotAskForText()
{
(await Transform(textOnly: false).ApplyAsync(Page, new HtmlTransformContext("https://x"), default)).Should().Be(Page);
}
}