| 1 | using CascadeIDE.Features.WorkspaceNavigation.Application; |
| 2 | using CascadeIDE.Models; |
| 3 | using Xunit; |
| 4 | |
| 5 | namespace CascadeIDE.Tests; |
| 6 | |
| 7 | public sealed class CodeNavigationMapPresentationProjectionTests |
| 8 | { |
| 9 | [Theory] |
| 10 | [InlineData("list", true, false)] |
| 11 | [InlineData("graph", false, true)] |
| 12 | [InlineData("both", true, true)] |
| 13 | public void Presentation_list_graph_match_settings_normalize_view(string view, bool expectList, bool expectGraph) |
| 14 | { |
| 15 | Assert.Equal(expectList, CodeNavigationMapPresentationProjection.ShowCodeNavigationMapList(view)); |
| 16 | Assert.Equal(expectGraph, CodeNavigationMapPresentationProjection.ShowCodeNavigationMapGraph(view, CodeNavigationMapLevelKind.File)); |
| 17 | Assert.Equal(expectList, CodeNavigationMapSettings.ViewWantsList(view)); |
| 18 | Assert.Equal(expectGraph, CodeNavigationMapSettings.ViewWantsGraph(view)); |
| 19 | } |
| 20 | |
| 21 | [Theory] |
| 22 | [InlineData("list")] |
| 23 | [InlineData("graph")] |
| 24 | public void ControlFlow_always_shows_graph_on_pfd(string view) |
| 25 | { |
| 26 | Assert.True(CodeNavigationMapPresentationProjection.ShowCodeNavigationMapGraph(view, CodeNavigationMapLevelKind.ControlFlow)); |
| 27 | } |
| 28 | |
| 29 | [Fact] |
| 30 | public void GraphClickHint_false_for_list_even_if_graph_mode_would_apply() |
| 31 | { |
| 32 | var hint = CodeNavigationMapPresentationProjection.ShowCodeNavigationMapGraphClickHint( |
| 33 | showGraph: true, |
| 34 | CodeNavigationMapLevelKind.File, |
| 35 | presentationView: "list"); |
| 36 | Assert.False(hint); |
| 37 | } |
| 38 | |
| 39 | [Fact] |
| 40 | public void GraphClickHint_true_when_graph_visibility_file_level_non_list_view() |
| 41 | { |
| 42 | var hint = CodeNavigationMapPresentationProjection.ShowCodeNavigationMapGraphClickHint( |
| 43 | showGraph: true, |
| 44 | CodeNavigationMapLevelKind.File, |
| 45 | presentationView: "graph"); |
| 46 | Assert.True(hint); |
| 47 | } |
| 48 | |
| 49 | [Fact] |
| 50 | public void GraphClickHint_false_for_control_flow_level() |
| 51 | { |
| 52 | var hint = CodeNavigationMapPresentationProjection.ShowCodeNavigationMapGraphClickHint( |
| 53 | showGraph: true, |
| 54 | CodeNavigationMapLevelKind.ControlFlow, |
| 55 | presentationView: "both"); |
| 56 | Assert.False(hint); |
| 57 | } |
| 58 | |
| 59 | [Theory] |
| 60 | [InlineData(0, "")] |
| 61 | [InlineData(1, "1 связь")] |
| 62 | [InlineData(3, "3 связей")] |
| 63 | public void RelatedBadge(int count, string expected) |
| 64 | { |
| 65 | Assert.Equal(expected, CodeNavigationMapPresentationProjection.WorkspaceNavigationMapRelatedBadge(count)); |
| 66 | } |
| 67 | |
| 68 | [Theory] |
| 69 | [InlineData(1, null, true)] |
| 70 | [InlineData(0, 5, true)] |
| 71 | [InlineData(0, 1, false)] |
| 72 | [InlineData(0, null, false)] |
| 73 | public void HasRelated(int related, int? graphNodes, bool expect) |
| 74 | { |
| 75 | Assert.Equal( |
| 76 | expect, |
| 77 | CodeNavigationMapPresentationProjection.WorkspaceNavigationMapHasRelated(related, graphNodes)); |
| 78 | } |
| 79 | |
| 80 | [Fact] |
| 81 | public void SettingsSummaryLine_includes_trimmed_detail() |
| 82 | { |
| 83 | var s = CodeNavigationMapPresentationProjection.SettingsSummaryLine("both", "file", " normal ", "top_down", "auto"); |
| 84 | Assert.Contains("детализация: normal", s, StringComparison.Ordinal); |
| 85 | Assert.Contains("укладка: top_down", s, StringComparison.Ordinal); |
| 86 | Assert.Contains("CF ось: auto", s, StringComparison.Ordinal); |
| 87 | } |
| 88 | |
| 89 | [Theory] |
| 90 | [InlineData("list", "graph")] |
| 91 | [InlineData("graph", "both")] |
| 92 | [InlineData("both", "list")] |
| 93 | [InlineData("junk", "graph")] |
| 94 | public void NextPresentationViewAfter_cycles(string current, string next) => |
| 95 | Assert.Equal(next, CodeNavigationMapPresentationProjection.NextPresentationViewAfter(current)); |
| 96 | |
| 97 | [Theory] |
| 98 | [InlineData("file", CodeNavigationMapLevelKind.ControlFlow)] |
| 99 | [InlineData("FILE", CodeNavigationMapLevelKind.ControlFlow)] |
| 100 | [InlineData(CodeNavigationMapLevelKind.ControlFlow, CodeNavigationMapLevelKind.File)] |
| 101 | public void ToggledMapLevel_alternates(string current, string expected) => |
| 102 | Assert.Equal(expected, CodeNavigationMapPresentationProjection.ToggledMapLevel(current)); |
| 103 | |
| 104 | [Theory] |
| 105 | [InlineData(CodeNavigationMapDetailLevel.Glance, CodeNavigationMapDetailLevel.Normal, "normal")] |
| 106 | [InlineData(CodeNavigationMapDetailLevel.Normal, CodeNavigationMapDetailLevel.Inspect, "inspect")] |
| 107 | [InlineData(CodeNavigationMapDetailLevel.Inspect, CodeNavigationMapDetailLevel.Glance, "glance")] |
| 108 | public void NextDetailCycle_rotates( |
| 109 | CodeNavigationMapDetailLevel current, |
| 110 | CodeNavigationMapDetailLevel expectDetail, |
| 111 | string expectToml) |
| 112 | { |
| 113 | var (d, t) = CodeNavigationMapPresentationProjection.NextDetailCycle(current); |
| 114 | Assert.Equal(expectDetail, d); |
| 115 | Assert.Equal(expectToml, t); |
| 116 | } |
| 117 | } |
| 118 | |