PlotDirector/PlotLine.Tests/RibbonPresentationTests.cs
Nick Beckley e48889ac05 Complete desktop workspaces, context menus and plot health
Commit the pending application, help and browser regression work. Pin the patched PKCS dependency for the production release.
2026-10-31 09:27:04 +00:00

27 lines
2.6 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 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")) 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.");
}
}