| 1 | using CascadeIDE.Contracts.Experimental; |
| 2 | using CascadeIDE.Contracts.Experimental.Capabilities; |
| 3 | using CascadeIDE.Features.UiChrome; |
| 4 | using CascadeIDE.Services.Capabilities; |
| 5 | using Xunit; |
| 6 | |
| 7 | namespace CascadeIDE.Tests; |
| 8 | |
| 9 | public sealed class CapabilityAttentionConsistencyTests : IDisposable |
| 10 | { |
| 11 | public CapabilityAttentionConsistencyTests() => |
| 12 | AttentionZonePanelRuntime.ResetToCodeDefaults(); |
| 13 | |
| 14 | public void Dispose() => |
| 15 | AttentionZonePanelRuntime.ResetToCodeDefaults(); |
| 16 | |
| 17 | [Fact] |
| 18 | public void Both_set_and_matching_returns_no_issue() |
| 19 | { |
| 20 | var d = new UiSurfaceCapabilityDescriptor |
| 21 | { |
| 22 | Id = "ui.test.solution", |
| 23 | OwnerModuleId = "test", |
| 24 | DisplayName = "Solution", |
| 25 | PrimaryAttentionZoneId = AttentionZoneCanonicalIds.Pfd, |
| 26 | HostAttentionPanelId = AttentionPanelCanonicalIds.SolutionExplorer |
| 27 | }; |
| 28 | Assert.Null(CapabilityAttentionConsistency.TryGetUiSurfaceIssue(d)); |
| 29 | } |
| 30 | |
| 31 | [Fact] |
| 32 | public void Zone_mismatch_returns_issue() |
| 33 | { |
| 34 | var d = new UiSurfaceCapabilityDescriptor |
| 35 | { |
| 36 | Id = "ui.bad", |
| 37 | OwnerModuleId = "test", |
| 38 | PrimaryAttentionZoneId = AttentionZoneCanonicalIds.Mfd, |
| 39 | HostAttentionPanelId = AttentionPanelCanonicalIds.SolutionExplorer |
| 40 | }; |
| 41 | var issue = CapabilityAttentionConsistency.TryGetUiSurfaceIssue(d); |
| 42 | Assert.NotNull(issue); |
| 43 | Assert.Contains("does not match", issue, StringComparison.Ordinal); |
| 44 | Assert.Contains("pfd", issue, StringComparison.OrdinalIgnoreCase); |
| 45 | } |
| 46 | |
| 47 | [Fact] |
| 48 | public void Unknown_panel_returns_issue() |
| 49 | { |
| 50 | var d = new UiSurfaceCapabilityDescriptor |
| 51 | { |
| 52 | Id = "ui.unknown", |
| 53 | OwnerModuleId = "test", |
| 54 | PrimaryAttentionZoneId = AttentionZoneCanonicalIds.Pfd, |
| 55 | HostAttentionPanelId = "nonexistent_panel" |
| 56 | }; |
| 57 | var issue = CapabilityAttentionConsistency.TryGetUiSurfaceIssue(d); |
| 58 | Assert.NotNull(issue); |
| 59 | Assert.Contains("not in AttentionZonePanelRuntime", issue, StringComparison.Ordinal); |
| 60 | } |
| 61 | |
| 62 | [Fact] |
| 63 | public void Only_zone_or_only_panel_skips_cross_check() |
| 64 | { |
| 65 | var zoneOnly = new UiSurfaceCapabilityDescriptor |
| 66 | { |
| 67 | Id = "a", |
| 68 | OwnerModuleId = "m", |
| 69 | PrimaryAttentionZoneId = AttentionZoneCanonicalIds.Mfd |
| 70 | }; |
| 71 | Assert.Null(CapabilityAttentionConsistency.TryGetUiSurfaceIssue(zoneOnly)); |
| 72 | |
| 73 | var panelOnly = new UiSurfaceCapabilityDescriptor |
| 74 | { |
| 75 | Id = "b", |
| 76 | OwnerModuleId = "m", |
| 77 | HostAttentionPanelId = AttentionPanelCanonicalIds.Editor |
| 78 | }; |
| 79 | Assert.Null(CapabilityAttentionConsistency.TryGetUiSurfaceIssue(panelOnly)); |
| 80 | } |
| 81 | } |
| 82 | |