SLP-composite: 'SLP Software: '; ASF leeg (golden files ongewijzigd). Tests en contract bijgewerkt. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
132 lines
6.2 KiB
C#
132 lines
6.2 KiB
C#
using FluentAssertions;
|
|
using NSubstitute;
|
|
using SlpModularCms.Core.Hosting.Website;
|
|
using SlpModularCms.Modules.Hero.Models;
|
|
using SlpModularCms.Modules.Hero.Services;
|
|
|
|
namespace SlpModularCms.Modules.Hero.Tests;
|
|
|
|
/// <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)
|
|
=> new("single", title, tagline, lead, buttons, []);
|
|
|
|
[Fact]
|
|
public void ADisplayedHeroWithoutSlides_IsATextOnlyRegion_WithNothingToPreload()
|
|
{
|
|
var hero = TextOnly(buttons: [new HeroButtonDto("Bekijk pakketten", "#pakketten"), new HeroButtonDto("Plan een gesprek", "#contact")]);
|
|
|
|
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>& meer.</span></h1>" +
|
|
"<p class=\"cms-hero-lead\">Een lead.</p>" +
|
|
"<p class=\"cms-hero-buttons\"><a class=\"cms-hero-button\" href=\"#pakketten\">Bekijk pakketten</a><a class=\"cms-hero-button\" href=\"#contact\">Plan een gesprek</a></p>");
|
|
injection.Preload.Should().BeEmpty();
|
|
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), 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>");
|
|
}
|
|
|
|
[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")), textOnlyRegion: true);
|
|
|
|
injection.Region.Should().Contain("<b>x</b>").And.Contain("a & b<br>c "d"").And.Contain("href=\"/p?a=1&b=2\"><i></a>");
|
|
injection.Region.Should().NotContain("<b>").And.NotContain("<i>");
|
|
}
|
|
|
|
[Fact]
|
|
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, textOnlyRegion: true).IsEmpty.Should().BeTrue();
|
|
}
|
|
|
|
[Fact]
|
|
public void ThePrefix_IsTheFirstHiddenPartOfTheH1_AndIsEncoded()
|
|
{
|
|
var injection = HeroPictureRenderer.Render(TextOnly("Titel", "Label", null), textOnlyRegion: true, titlePrefix: "SLP & Co: ");
|
|
|
|
injection.Region.Should().Be("<h1 class=\"cms-hero-title\"><span class=\"cms-hero-title-prefix\">SLP & Co: </span><span class=\"cms-hero-tagline\">Label</span> <span class=\"cms-hero-title-lines\">Titel</span></h1>");
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("")]
|
|
[InlineData(" ")]
|
|
public void AnEmptyPrefix_ChangesNothing(string prefix)
|
|
{
|
|
var hero = TextOnly();
|
|
|
|
HeroPictureRenderer.Render(hero, textOnlyRegion: true, titlePrefix: prefix).Region
|
|
.Should().Be(HeroPictureRenderer.Render(hero, textOnlyRegion: true).Region).And.NotContain("title-prefix");
|
|
}
|
|
|
|
[Fact]
|
|
public void APictureHero_NeverGetsThePrefix()
|
|
{
|
|
var variant = new HeroVariantDto("wide", 640, 427, "image/webp", "/media/hero/0123456789abcdef/wide-640.webp");
|
|
var image = new PublicImageDto(1600, 1067, new FocusDto(0.5, 0.5, 1), "/media/hero/0123456789abcdef/wide-640.webp", [variant]);
|
|
var hero = new PublicHeroDto("single", "Titel", null, null, [], [new PublicSlideDto("alt", "", false, image)]);
|
|
|
|
HeroPictureRenderer.Render(hero, textOnlyRegion: true, titlePrefix: "SLP: ").Region.Should().NotContain("title-prefix");
|
|
}
|
|
|
|
[Fact]
|
|
public async Task TheTransform_PassesTheConfiguredPrefix()
|
|
{
|
|
var model = Substitute.For<IHeroPageModel>();
|
|
model.GetAsync(default).ReturnsForAnyArgs(TextOnly());
|
|
var transform = new HeroHtmlTransform(model, Options.Create(new HeroOptions { TextOnlyRegion = true, TitlePrefix = "SLP Software: " }));
|
|
|
|
var html = await transform.ApplyAsync(Page, new HtmlTransformContext("https://x"), default);
|
|
|
|
html.Should().Contain("<h1 class=\"cms-hero-title\"><span class=\"cms-hero-title-prefix\">SLP Software: </span><span class=\"cms-hero-title-lines\">");
|
|
}
|
|
|
|
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());
|
|
return new HeroHtmlTransform(model, Options.Create(new HeroOptions { TextOnlyRegion = textOnly }));
|
|
}
|
|
|
|
[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);
|
|
}
|
|
}
|