Hero: tekst-only regio voor een hero zonder slides (SLP), e2e-test op de echte ASF-build, bijgewerkte aannames en contract
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
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): the host writes the title, the lead and the buttons into the first HTML.</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);
|
||||
|
||||
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 WithoutALead_OrButtons_ThosePartsAreLeftOut_AndATaglineComesFirst()
|
||||
{
|
||||
var injection = HeroPictureRenderer.Render(TextOnly("Titel", "Label", null));
|
||||
|
||||
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")));
|
||||
|
||||
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_AsForTheAsfSite()
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task TheTransform_FillsTheTextRegion_AndLeavesThePreloadRegionAlone()
|
||||
{
|
||||
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>";
|
||||
|
||||
var html = await new HeroHtmlTransform(model).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-->");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user