PlotDirector/PlotLine.Tests/RibbonPresentationTests.cs

30 lines
3.1 KiB
C#

using PlotLine.Services;
internal static class RibbonPresentationTests
{
public static void SemanticMetadata()
{
if (RibbonPresentation.Operation("Books", "Create") != RibbonPresentation.Operation("books", "create")) throw new Exception("Operation identity must be stable across route casing.");
var exports = new[] { RibbonPresentation.IconFor("Exports.StoryBible"), RibbonPresentation.IconFor("exports.storybible", "markdown"), RibbonPresentation.IconFor("exports.storybible", "text"), RibbonPresentation.IconFor("exports.narrativetimeline"), RibbonPresentation.IconFor("exports.researchpack") };
if (exports.Distinct().Count() != exports.Length || exports.Any(key => key == "bible")) throw new Exception("Export operations need distinct semantic icon metadata, not the Story Bible navigation icon.");
foreach (var key in exports.Append("settings").Append("validate").Append("help")) _ = ApplicationRibbon.Icon(key!);
if (RibbonPresentation.IconFor("timeline.settings") == RibbonPresentation.IconFor("warnings.validateproject")) throw new Exception("Settings and validation are different operations.");
if (RibbonPresentation.IconFor("books.create") is not null) throw new Exception("Preserve the established Add Book icon association.");
var storyStructure = ApplicationRibbon.Categories.Single(category => category.Key == "story").Groups.Single(group => group.Label == "Story structure");
if (!storyStructure.Commands.Select(command => command.ToolbarKey).SequenceEqual(new[] { "timeline", "plotlines", "threads", "calendar", "point" }))
throw new Exception("Story navigation must follow the author workflow: Timeline, Plot Lines, Threads, Calendar, At This Point.");
var root = new DirectoryInfo(AppContext.BaseDirectory);
while (root is not null && !Directory.Exists(Path.Combine(root.FullName, "PlotLine", "Views"))) root = root.Parent;
if (root is null) throw new Exception("Ribbon source coverage requires the repository.");
foreach (var command in ApplicationRibbon.Categories.SelectMany(category => category.Groups).SelectMany(group => group.Commands))
{
var action = command.Controller is "Books" or "Chapters" && command.Action == "Create" ? "Edit"
: command.Controller == "Onboarding" && command.Action == "StoryIntelligenceBookReviewCentre" ? "StoryIntelligenceReviewCentre" : command.Action;
var view = Path.Combine(root.FullName, "PlotLine", "Views", command.Controller, action + ".cshtml");
if (!File.Exists(view)) continue; // Downloads and controller redirects have no page furniture.
var markup = File.ReadAllText(view);
if (!markup.Contains("data-pwa-") && !markup.Contains("_StoryCalendarSurface") && !markup.Contains("_Writer3Header")) throw new Exception($"Navigation destination has no contextual classification: {command.Controller}/{action}");
}
if (RibbonPresentation.Icons.Select(icon => icon.Key).Distinct().Count() != RibbonPresentation.Icons.Count()) throw new Exception("Icon catalog keys must be unique.");
}
}