| 1 | using System.Text.Json; |
| 2 | using CascadeIDE.Contracts.Experimental; |
| 3 | using CascadeIDE.Contracts.Experimental.Capabilities; |
| 4 | using CascadeIDE.Features.UiChrome; |
| 5 | using Xunit; |
| 6 | |
| 7 | namespace CascadeIDE.Tests; |
| 8 | |
| 9 | public sealed class AttentionZoneCanonicalIdsTests |
| 10 | { |
| 11 | [Fact] |
| 12 | public void AttentionZoneIds_strings_match_contracts_single_source() |
| 13 | { |
| 14 | Assert.Equal(AttentionZoneCanonicalIds.Forward, AttentionZoneIds.Forward); |
| 15 | Assert.Equal(AttentionZoneCanonicalIds.Pfd, AttentionZoneIds.Pfd); |
| 16 | Assert.Equal(AttentionZoneCanonicalIds.Mfd, AttentionZoneIds.Mfd); |
| 17 | Assert.Equal(AttentionZoneCanonicalIds.Eicas, AttentionZoneIds.Eicas); |
| 18 | Assert.Equal(AttentionZoneCanonicalIds.Hud, AttentionZoneIds.Hud); |
| 19 | Assert.Equal(AttentionZoneIds.All.Length, AttentionZoneCanonicalIds.All.Length); |
| 20 | } |
| 21 | |
| 22 | [Theory] |
| 23 | [InlineData("forward", true)] |
| 24 | [InlineData("pfd", true)] |
| 25 | [InlineData("mfd", true)] |
| 26 | [InlineData("eicas", true)] |
| 27 | [InlineData("hud", true)] |
| 28 | [InlineData("Forward", false)] |
| 29 | [InlineData("PFD", false)] |
| 30 | [InlineData("", false)] |
| 31 | [InlineData(null, false)] |
| 32 | public void IsKnownCanonicalId_is_strict(string? id, bool expected) => |
| 33 | Assert.Equal(expected, AttentionZoneCanonicalIds.IsKnownCanonicalId(id)); |
| 34 | |
| 35 | [Fact] |
| 36 | public void Command_descriptor_JSON_round_trips_PrimaryAttentionZoneId() |
| 37 | { |
| 38 | var d = new CommandCapabilityDescriptor |
| 39 | { |
| 40 | Id = "test.cmd", |
| 41 | OwnerModuleId = "test.module", |
| 42 | Title = "T", |
| 43 | PrimaryAttentionZoneId = AttentionZoneCanonicalIds.Mfd |
| 44 | }; |
| 45 | var json = JsonSerializer.Serialize(d); |
| 46 | var back = JsonSerializer.Deserialize<CommandCapabilityDescriptor>(json); |
| 47 | Assert.NotNull(back); |
| 48 | Assert.Equal(AttentionZoneCanonicalIds.Mfd, back.PrimaryAttentionZoneId); |
| 49 | } |
| 50 | |
| 51 | [Fact] |
| 52 | public void Ui_surface_descriptor_JSON_round_trips_zone_and_panel() |
| 53 | { |
| 54 | var d = new UiSurfaceCapabilityDescriptor |
| 55 | { |
| 56 | Id = "ui.x", |
| 57 | OwnerModuleId = "m", |
| 58 | DisplayName = "X", |
| 59 | PrimaryAttentionZoneId = AttentionZoneCanonicalIds.Pfd, |
| 60 | HostAttentionPanelId = AttentionPanelCanonicalIds.SolutionExplorer |
| 61 | }; |
| 62 | var json = JsonSerializer.Serialize(d); |
| 63 | var back = JsonSerializer.Deserialize<UiSurfaceCapabilityDescriptor>(json); |
| 64 | Assert.NotNull(back); |
| 65 | Assert.Equal(AttentionZoneCanonicalIds.Pfd, back.PrimaryAttentionZoneId); |
| 66 | Assert.Equal(AttentionPanelCanonicalIds.SolutionExplorer, back.HostAttentionPanelId); |
| 67 | } |
| 68 | } |
| 69 | |