| 1 | using System.Text.Json; |
| 2 | using CascadeIDE.Cockpit.Graph; |
| 3 | using CascadeIDE.Features.WorkspaceNavigation.Application; |
| 4 | using CascadeIDE.Models; |
| 5 | using Xunit; |
| 6 | |
| 7 | namespace CascadeIDE.Tests; |
| 8 | |
| 9 | public sealed class WorkspaceNavigationMapContextAndViewportTests |
| 10 | { |
| 11 | [Fact] |
| 12 | public void Viewport_rejects_nan_and_below_threshold() |
| 13 | { |
| 14 | Assert.False(CodeNavigationMapViewportPolicy.ShouldApplyMeasuredWidth(double.NaN, 100d, out _)); |
| 15 | Assert.False(CodeNavigationMapViewportPolicy.ShouldApplyMeasuredWidth(39d, 100d, out _)); |
| 16 | } |
| 17 | |
| 18 | [Fact] |
| 19 | public void Viewport_clamps_and_skips_near_current() |
| 20 | { |
| 21 | Assert.True(CodeNavigationMapViewportPolicy.ShouldApplyMeasuredWidth(500d, 100d, out var clamped)); |
| 22 | Assert.Equal(500d, clamped); |
| 23 | |
| 24 | Assert.False(CodeNavigationMapViewportPolicy.ShouldApplyMeasuredWidth(100d, 100d, out _)); |
| 25 | Assert.False(CodeNavigationMapViewportPolicy.ShouldApplyMeasuredWidth(100d, 102d, out _)); |
| 26 | } |
| 27 | |
| 28 | [Fact] |
| 29 | public void Viewport_coerces_small_reported_values_to_minimum() |
| 30 | { |
| 31 | Assert.True(CodeNavigationMapViewportPolicy.ShouldApplyMeasuredWidth(41d, 10d, out var clamped)); |
| 32 | Assert.Equal(CodeNavigationMapViewportPolicy.MinClampedWidth, clamped); |
| 33 | } |
| 34 | |
| 35 | [Fact] |
| 36 | public void JsonBuilder_control_flow_without_file_returns_error_no_file() |
| 37 | { |
| 38 | var json = WorkspaceNavigationMapContextJsonBuilder.Build( |
| 39 | CodeNavigationMapLevelKind.ControlFlow, |
| 40 | wantGraph: false, |
| 41 | currentPath: null, |
| 42 | editorText: null, |
| 43 | cursorLine: null, |
| 44 | cursorColumn: null, |
| 45 | [], |
| 46 | solutionPath: null, |
| 47 | navSettings: null); |
| 48 | |
| 49 | using var doc = JsonDocument.Parse(json); |
| 50 | Assert.Equal("no_file", doc.RootElement.GetProperty("error").GetString()); |
| 51 | } |
| 52 | |
| 53 | [Fact] |
| 54 | public void IGraphDataSource_matches_static_builder_for_control_flow_no_file() |
| 55 | { |
| 56 | IGraphDataSource source = new WorkspaceNavigationMapContextJsonDataSource(); |
| 57 | var req = new GraphNavigationJsonRequest( |
| 58 | CodeNavigationMapLevelKind.ControlFlow, |
| 59 | WantGraph: false, |
| 60 | CurrentPath: null, |
| 61 | EditorText: null, |
| 62 | CursorLine: null, |
| 63 | CursorColumn: null, |
| 64 | RawFilePathsFromSolution: [], |
| 65 | SolutionPath: null, |
| 66 | NavSettings: null); |
| 67 | var fromInterface = source.BuildNavigationJson(req); |
| 68 | var fromStatic = WorkspaceNavigationMapContextJsonBuilder.Build( |
| 69 | CodeNavigationMapLevelKind.ControlFlow, |
| 70 | wantGraph: false, |
| 71 | currentPath: null, |
| 72 | editorText: null, |
| 73 | cursorLine: null, |
| 74 | cursorColumn: null, |
| 75 | [], |
| 76 | solutionPath: null, |
| 77 | navSettings: null); |
| 78 | Assert.Equal(fromStatic, fromInterface); |
| 79 | } |
| 80 | } |
| 81 | |