68 lines
2.1 KiB
C#
68 lines
2.1 KiB
C#
using Elternbeirat.Web.Features.Home;
|
|
|
|
namespace Elternbeirat.Web.Tests;
|
|
|
|
/// <summary>
|
|
/// Unit tests for taking the home page's body apart into heading, intro and
|
|
/// buttons. Pure logic, no PocketBase needed.
|
|
/// </summary>
|
|
public class HomeIntroTests
|
|
{
|
|
[Fact]
|
|
public void Body_splits_into_title_intro_and_buttons()
|
|
{
|
|
var intro = HomeIntro.Parse(
|
|
"# Willkommen\n\nSchön, dass Sie da sind.\n\n[Kommende Termine](/events)\n[Kontakt aufnehmen](/contact)");
|
|
|
|
intro.Title.ShouldBe("Willkommen");
|
|
intro.IntroHtml.ShouldBe("<p>Schön, dass Sie da sind.</p>\n");
|
|
intro.Links.ShouldBe(
|
|
[
|
|
new HomeLink("/events", "Kommende Termine"),
|
|
new HomeLink("/contact", "Kontakt aufnehmen"),
|
|
]);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(null)]
|
|
[InlineData("")]
|
|
[InlineData(" ")]
|
|
public void Empty_body_gives_the_fallback(string? markdown) =>
|
|
HomeIntro.Parse(markdown).ShouldBe(HomeIntro.Fallback);
|
|
|
|
[Fact]
|
|
public void Body_without_heading_keeps_the_fallback_title_and_all_text()
|
|
{
|
|
var intro = HomeIntro.Parse("Nur ein Absatz.");
|
|
|
|
intro.Title.ShouldBe(HomeIntro.FallbackTitle);
|
|
intro.IntroHtml.ShouldContain("Nur ein Absatz.");
|
|
intro.Links.ShouldBeEmpty();
|
|
}
|
|
|
|
[Fact]
|
|
public void Last_paragraph_with_other_text_stays_intro()
|
|
{
|
|
// "oder" would get lost in a button row, so the paragraph stays text.
|
|
var intro = HomeIntro.Parse("# Hallo\n\n[Termine](/events) oder [Kontakt](/contact)");
|
|
|
|
intro.Links.ShouldBeEmpty();
|
|
intro.IntroHtml.ShouldContain("href=\"/events\"");
|
|
}
|
|
|
|
[Fact]
|
|
public void Link_paragraph_that_is_not_last_stays_intro()
|
|
{
|
|
var intro = HomeIntro.Parse("# Hallo\n\n[Termine](/events)\n\nSchlusssatz.");
|
|
|
|
intro.Links.ShouldBeEmpty();
|
|
intro.IntroHtml.ShouldContain("Schlusssatz.");
|
|
}
|
|
|
|
[Fact]
|
|
public void Heading_markup_is_reduced_to_its_text()
|
|
{
|
|
HomeIntro.Parse("# Willkommen beim **Elternbeirat**").Title.ShouldBe("Willkommen beim Elternbeirat");
|
|
}
|
|
}
|