| 1 | using AgentForge.Abstractions; |
| 2 | using AgentForge.Plugin.Grouping.Core; |
| 3 | |
| 4 | namespace AgentForge.Tests; |
| 5 | |
| 6 | public sealed class ForgeCatalogAxisCatalogTests |
| 7 | { |
| 8 | [Fact] |
| 9 | public void Catalog_lists_axes_in_order() |
| 10 | { |
| 11 | var catalog = new ForgeGroupingAxisCatalog<IForgeCatalogGroupingAxis, ForgeCatalogGroupingRepoRow>( |
| 12 | [ |
| 13 | new TestAxis("group", "Group", order: 60), |
| 14 | new TestAxis("visibility", "Visibility", order: 10), |
| 15 | new TestAxis("drive_mode", "Drive mode", order: 20), |
| 16 | ], |
| 17 | "repository"); |
| 18 | |
| 19 | Assert.Equal(["visibility", "drive_mode", "group"], catalog.Axes.Select(axis => axis.Id).ToList()); |
| 20 | } |
| 21 | |
| 22 | [Fact] |
| 23 | public void Catalog_rejects_duplicate_axis_id() |
| 24 | { |
| 25 | Assert.Throws<InvalidOperationException>(() => new ForgeGroupingAxisCatalog<IForgeCatalogGroupingAxis, ForgeCatalogGroupingRepoRow>( |
| 26 | [ |
| 27 | new TestAxis("visibility", "Visibility", order: 10), |
| 28 | new TestAxis("visibility", "Visibility copy", order: 11), |
| 29 | ], |
| 30 | "repository")); |
| 31 | } |
| 32 | |
| 33 | [Fact] |
| 34 | public void ParseStack_skips_unknown_axes() |
| 35 | { |
| 36 | var catalog = new ForgeGroupingAxisCatalog<IForgeCatalogGroupingAxis, ForgeCatalogGroupingRepoRow>( |
| 37 | [new TestAxis("visibility", "Visibility", order: 10)], |
| 38 | "repository"); |
| 39 | |
| 40 | var stack = catalog.ParseStack("visibility,not-real,drive_mode"); |
| 41 | |
| 42 | Assert.Equal(["visibility"], stack); |
| 43 | } |
| 44 | |
| 45 | private sealed class TestAxis(string id, string label, int order) : IForgeCatalogGroupingAxis |
| 46 | { |
| 47 | public string Id => id; |
| 48 | |
| 49 | public string Label => label; |
| 50 | |
| 51 | public int Order => order; |
| 52 | |
| 53 | public string GetKey(ForgeCatalogGroupingRepoRow row, DateTimeOffset utcNow) => id; |
| 54 | |
| 55 | public IReadOnlyList<ForgeGroupingSection> SectionsFor( |
| 56 | IReadOnlyList<ForgeCatalogGroupingRepoRow> rows, |
| 57 | DateTimeOffset utcNow) => [new("only", "Only")]; |
| 58 | } |
| 59 | } |
| 60 | |