| 1 | using CascadeIDE.Cockpit.Cds; |
| 2 | using CascadeIDE.Cockpit.Composition.HostSurface; |
| 3 | using CascadeIDE.Features.Shell.Application; |
| 4 | using CascadeIDE.Features.UiChrome; |
| 5 | using CascadeIDE.Models; |
| 6 | using Xunit; |
| 7 | |
| 8 | namespace CascadeIDE.Tests; |
| 9 | |
| 10 | public sealed class MainWindowPresentationSurfaceProjectionTests |
| 11 | { |
| 12 | private sealed class TestInstrumentMountResolver : IInstrumentMountPolicyResolver |
| 13 | { |
| 14 | public Func<DisplaySettings, string, string, string, string>? Invoke { get; set; } |
| 15 | |
| 16 | public string Resolve(DisplaySettings displaySettings, string surfaceId, string slotId, string instrumentId) => |
| 17 | Invoke?.Invoke(displaySettings, surfaceId, slotId, instrumentId) |
| 18 | ?? $"{surfaceId}|{slotId}|{instrumentId}"; |
| 19 | } |
| 20 | [Fact] |
| 21 | public void ResolveWindowTitle_matches_catalog_then_family_fallback() |
| 22 | { |
| 23 | foreach (var mode in new[] { "Flight", "Editor", "Debug", "" }) |
| 24 | { |
| 25 | var normalized = UiModeCatalog.NormalizeUiMode(string.IsNullOrEmpty(mode) ? null : mode); |
| 26 | var fromCatalog = UiModeCatalog.GetWindowTitleOverride(normalized); |
| 27 | string expected = fromCatalog |
| 28 | ?? UiModeFamilyResolver.FromNormalizedMode(normalized) switch |
| 29 | { |
| 30 | UiModeFamily.Power => "CascadeIDE — Power Mode [Autonomous Agent Cockpit]", |
| 31 | UiModeFamily.AgentChat => "CascadeIDE — Agent Chat", |
| 32 | UiModeFamily.Debug => "CascadeIDE — Debug", |
| 33 | UiModeFamily.Editor => "CascadeIDE — Editor", |
| 34 | _ => "CascadeIDE", |
| 35 | }; |
| 36 | Assert.Equal(expected, MainWindowPresentationSurfaceProjection.ResolveWindowTitle(normalized)); |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | [Fact] |
| 41 | public void IsMfdContourContentVisible_requires_any_checked_layer() |
| 42 | { |
| 43 | Assert.False(MainWindowPresentationSurfaceProjection.IsMfdContourContentVisible( |
| 44 | problemsPanelVisible: false, |
| 45 | isTerminalVisible: false, |
| 46 | isBuildOutputVisible: false, |
| 47 | instrumentationTabs: false, |
| 48 | isGitPanelVisible: false)); |
| 49 | Assert.True(MainWindowPresentationSurfaceProjection.IsMfdContourContentVisible( |
| 50 | problemsPanelVisible: true, |
| 51 | isTerminalVisible: false, |
| 52 | isBuildOutputVisible: false, |
| 53 | instrumentationTabs: false, |
| 54 | isGitPanelVisible: false)); |
| 55 | } |
| 56 | |
| 57 | [Fact] |
| 58 | public void MountPolicySurfaceId_docked_grid_stable() |
| 59 | { |
| 60 | Assert.Equal( |
| 61 | "main_window_docked_grid", |
| 62 | MainWindowPresentationSurfaceProjection.MountPolicySurfaceId(AttentionLayoutSurfaceKind.MainWindowDockedGrid)); |
| 63 | } |
| 64 | |
| 65 | [Fact] |
| 66 | public void IsAgentSummary_visible_only_when_differs_from_placeholder() |
| 67 | { |
| 68 | var p = MainWindowPresentationSurfaceProjection.DefaultRiskSummaryPlaceholder; |
| 69 | Assert.False(MainWindowPresentationSurfaceProjection.IsAgentSummaryVisibleComparedToPlaceholder(null, p)); |
| 70 | Assert.False(MainWindowPresentationSurfaceProjection.IsAgentSummaryVisibleComparedToPlaceholder(" ", p)); |
| 71 | Assert.False(MainWindowPresentationSurfaceProjection.IsAgentSummaryVisibleComparedToPlaceholder(p, p)); |
| 72 | Assert.True(MainWindowPresentationSurfaceProjection.IsAgentSummaryVisibleComparedToPlaceholder("risk text", p)); |
| 73 | } |
| 74 | |
| 75 | [Fact] |
| 76 | public void IsMainGridSplitColumnVisible_positive_width_only() |
| 77 | { |
| 78 | Assert.False(MainWindowPresentationSurfaceProjection.IsMainGridSplitColumnVisible(0)); |
| 79 | Assert.True(MainWindowPresentationSurfaceProjection.IsMainGridSplitColumnVisible(1)); |
| 80 | } |
| 81 | |
| 82 | [Fact] |
| 83 | public void IdeHealth_skia_mount_flags_combine_useSkia_and_column_or_host() |
| 84 | { |
| 85 | Assert.False(MainWindowPresentationSurfaceProjection.IsIdeHealthSkiaMountVisibleInDockedColumn( |
| 86 | useSkiaInstrumentMount: false, |
| 87 | columnVisible: true)); |
| 88 | Assert.False(MainWindowPresentationSurfaceProjection.IsIdeHealthSkiaMountVisibleInDockedColumn( |
| 89 | useSkiaInstrumentMount: true, |
| 90 | columnVisible: false)); |
| 91 | Assert.True(MainWindowPresentationSurfaceProjection.IsIdeHealthSkiaMountVisibleInDockedColumn( |
| 92 | useSkiaInstrumentMount: true, |
| 93 | columnVisible: true)); |
| 94 | |
| 95 | Assert.False(MainWindowPresentationSurfaceProjection.IsIdeHealthSkiaMountVisibleForHostWindow( |
| 96 | useSkiaInstrumentMount: true, |
| 97 | hostShellOpen: false)); |
| 98 | Assert.True(MainWindowPresentationSurfaceProjection.IsIdeHealthSkiaMountVisibleForHostWindow( |
| 99 | useSkiaInstrumentMount: true, |
| 100 | hostShellOpen: true)); |
| 101 | } |
| 102 | |
| 103 | [Fact] |
| 104 | public void ResolveInstrumentMountStyleForSlot_uses_MountPolicySurfaceId() |
| 105 | { |
| 106 | var resolver = new TestInstrumentMountResolver(); |
| 107 | DisplaySettings? capturedDisplay = null; |
| 108 | string? capturedSurface = null; |
| 109 | string? capturedSlot = null; |
| 110 | string? capturedInstrument = null; |
| 111 | resolver.Invoke = (d, surf, slot, instr) => |
| 112 | { |
| 113 | capturedDisplay = d; |
| 114 | capturedSurface = surf; |
| 115 | capturedSlot = slot; |
| 116 | capturedInstrument = instr; |
| 117 | return "ok"; |
| 118 | }; |
| 119 | |
| 120 | var display = new DisplaySettings(); |
| 121 | var style = MainWindowPresentationSurfaceProjection.ResolveInstrumentMountStyleForSlot( |
| 122 | resolver, |
| 123 | display, |
| 124 | AttentionLayoutSurfaceKind.MainWindowPlusMfdHostTopLevel, |
| 125 | "mfd", |
| 126 | "inst-1"); |
| 127 | |
| 128 | Assert.Equal("ok", style); |
| 129 | Assert.Same(display, capturedDisplay); |
| 130 | Assert.Equal( |
| 131 | MainWindowPresentationSurfaceProjection.MountPolicySurfaceId( |
| 132 | AttentionLayoutSurfaceKind.MainWindowPlusMfdHostTopLevel), |
| 133 | capturedSurface); |
| 134 | Assert.Equal("mfd", capturedSlot); |
| 135 | Assert.Equal("inst-1", capturedInstrument); |
| 136 | } |
| 137 | |
| 138 | [Fact] |
| 139 | public void ResolveExpandedMfdWidthPixels_Flight_uses_agent_chat_width() |
| 140 | { |
| 141 | var w = MainWindowPresentationSurfaceProjection.ResolveExpandedMfdWidthPixels( |
| 142 | "Flight", |
| 143 | MfdShellPage.Terminal, |
| 144 | PrimaryWorkSurfaceKind.Editor); |
| 145 | Assert.Equal(UiWorkspaceLayoutRuntimeMetrics.MfdRegionExpandedAgentChatWidthPixels, w); |
| 146 | } |
| 147 | |
| 148 | [Fact] |
| 149 | public void ResolveExpandedMfdWidthPixels_Chat_page_at_least_agent_chat_width() |
| 150 | { |
| 151 | var w = MainWindowPresentationSurfaceProjection.ResolveExpandedMfdWidthPixels( |
| 152 | "Editor", |
| 153 | MfdShellPage.Chat, |
| 154 | PrimaryWorkSurfaceKind.Editor); |
| 155 | Assert.Equal(UiWorkspaceLayoutRuntimeMetrics.MfdRegionExpandedAgentChatWidthPixels, w); |
| 156 | } |
| 157 | |
| 158 | [Fact] |
| 159 | public void ResolveExpandedMfdWidthPixels_non_chat_uses_mode_default() |
| 160 | { |
| 161 | var w = MainWindowPresentationSurfaceProjection.ResolveExpandedMfdWidthPixels( |
| 162 | "Editor", |
| 163 | MfdShellPage.Terminal, |
| 164 | PrimaryWorkSurfaceKind.Editor); |
| 165 | Assert.Equal(UiWorkspaceLayoutRuntimeMetrics.MfdRegionExpandedDefaultWidthPixels, w); |
| 166 | } |
| 167 | } |
| 168 | |