70 lines
2.1 KiB
C#
70 lines
2.1 KiB
C#
using Elternbeirat.Contracts;
|
|
using Elternbeirat.Web.Features.Layout;
|
|
|
|
namespace Elternbeirat.Web.Tests;
|
|
|
|
/// <summary>
|
|
/// Unit tests for the navigation builder. Pure logic, no PocketBase needed.
|
|
/// </summary>
|
|
public class NavBuilderTests
|
|
{
|
|
// Id is required on the record but irrelevant to navigation, so a fixed
|
|
// placeholder keeps these cases focused on slug/location/order/title.
|
|
private static Page Page(string slug, string location, double order, string title) =>
|
|
new() { Id = "test", Slug = slug, Location = location, Order = order, Title = title };
|
|
|
|
[Fact]
|
|
public void Header_keeps_only_header_pages_ordered_by_order()
|
|
{
|
|
var pages = new[]
|
|
{
|
|
Page("board", "header", 2, "Vorstandsteam"),
|
|
Page("home", "header", 1, "Start"),
|
|
Page("imprint", "footer", 1, "Impressum"),
|
|
};
|
|
|
|
var header = NavBuilder.Header(pages);
|
|
|
|
header.Select(link => link.Title).ShouldBe(["Start", "Vorstandsteam"]);
|
|
}
|
|
|
|
[Fact]
|
|
public void Footer_keeps_only_footer_pages_ordered_by_order()
|
|
{
|
|
var pages = new[]
|
|
{
|
|
Page("privacy", "footer", 2, "Datenschutz"),
|
|
Page("imprint", "footer", 1, "Impressum"),
|
|
Page("home", "header", 1, "Start"),
|
|
};
|
|
|
|
var footer = NavBuilder.Footer(pages);
|
|
|
|
footer.Select(link => link.Title).ShouldBe(["Impressum", "Datenschutz"]);
|
|
}
|
|
|
|
[Fact]
|
|
public void No_pages_give_empty_menus()
|
|
{
|
|
// PocketBase down or nothing published yet: both menus are empty lists, not
|
|
// null, so the layout can simply skip a column instead of crashing.
|
|
NavBuilder.Header([]).ShouldBeEmpty();
|
|
NavBuilder.Footer([]).ShouldBeEmpty();
|
|
}
|
|
|
|
[Fact]
|
|
public void Home_page_maps_to_root_every_other_slug_to_its_path()
|
|
{
|
|
var pages = new[]
|
|
{
|
|
Page("home", "header", 1, "Start"),
|
|
Page("board", "header", 2, "Vorstandsteam"),
|
|
};
|
|
|
|
var header = NavBuilder.Header(pages);
|
|
|
|
header[0].Href.ShouldBe("/");
|
|
header[1].Href.ShouldBe("/board");
|
|
}
|
|
}
|