| 1 | using CascadeIDE.Features.Chat; |
| 2 | using CascadeIDE.Models.Intercom; |
| 3 | using CascadeIDE.Services; |
| 4 | using CascadeIDE.Services.Intercom; |
| 5 | using Xunit; |
| 6 | |
| 7 | namespace CascadeIDE.Tests; |
| 8 | |
| 9 | public sealed class IntercomAnchorSlashTests |
| 10 | { |
| 11 | [Theory] |
| 12 | [InlineData("abcd1234", "abcd1234")] |
| 13 | [InlineData("a:AbCd1234", "abcd1234")] |
| 14 | public void TryNormalizeAnchorId_AcceptsForms(string raw, string expected) |
| 15 | { |
| 16 | Assert.True(IntercomAnchorSlash.TryNormalizeAnchorId(raw, out var id, out var error), error); |
| 17 | Assert.Equal(expected, id); |
| 18 | } |
| 19 | |
| 20 | [Fact] |
| 21 | public void TryNormalizeAnchorId_AcceptsWireMarker() |
| 22 | { |
| 23 | var raw = IntercomAttachmentMarkers.FormatMarker("ef001122"); |
| 24 | Assert.True(IntercomAnchorSlash.TryNormalizeAnchorId(raw, out var id, out var error), error); |
| 25 | Assert.Equal("ef001122", id); |
| 26 | } |
| 27 | |
| 28 | [Fact] |
| 29 | public void ResolveInput_IntercomMessageAnchorsList() |
| 30 | { |
| 31 | ChatSlashCatalogTestSupport.AssertResolves("/intercom message anchors list", "/intercom message anchors list"); |
| 32 | Assert.True( |
| 33 | ChatSlashCommandCatalog.TryResolveInput("/intercom message anchors list", out var d, out _)); |
| 34 | Assert.True(IntentSlashCatalog.TryGetRoute(d.SlashPath, out var route)); |
| 35 | Assert.Equal("message_anchors_list", route.IntercomHandlerId); |
| 36 | } |
| 37 | |
| 38 | [Fact] |
| 39 | public void ResolveInput_AnchorPeek() |
| 40 | { |
| 41 | ChatSlashCatalogTestSupport.AssertResolves("/anchor peek abcd1234", "/anchor peek", "abcd1234"); |
| 42 | Assert.True( |
| 43 | ChatSlashCommandCatalog.TryResolveInput("/anchor peek abcd1234", out var d, out _)); |
| 44 | Assert.True(IntentSlashCatalog.TryGetRoute(d.SlashPath, out var route)); |
| 45 | Assert.Equal("anchor_peek", route.IntercomHandlerId); |
| 46 | } |
| 47 | |
| 48 | [Fact] |
| 49 | public void PreviewBuilder_AnchorPeek() |
| 50 | { |
| 51 | Assert.True(SlashCommandPreviewEvaluator.TryEvaluateSummary("/anchor peek abcd1234", out var summary)); |
| 52 | Assert.Contains("Peek", summary); |
| 53 | } |
| 54 | |
| 55 | [Fact] |
| 56 | public void ResolveInput_IntercomAnchorPeek() |
| 57 | { |
| 58 | ChatSlashCatalogTestSupport.AssertResolves( |
| 59 | "/intercom anchor peek abcd1234", |
| 60 | "/intercom anchor peek", |
| 61 | "abcd1234"); |
| 62 | Assert.Equal( |
| 63 | "abcd1234", |
| 64 | IntercomAnchorSlash.ExtractPeekIdTail("/intercom anchor peek", "abcd1234")); |
| 65 | } |
| 66 | |
| 67 | [Fact] |
| 68 | public void TryResolvePeekOrdinal_resolves_index_in_selected_message() |
| 69 | { |
| 70 | var anchors = new[] |
| 71 | { |
| 72 | new AttachmentAnchor { Id = "abcd1234", DisplayLabel = "A" }, |
| 73 | new AttachmentAnchor { Id = "ef005678", DisplayLabel = "B" }, |
| 74 | }; |
| 75 | |
| 76 | Assert.True(IntercomAnchorSlash.TryResolvePeekOrdinal("2", anchors, out var anchor, out var ordinal)); |
| 77 | Assert.Equal(2, ordinal); |
| 78 | Assert.Equal("ef005678", anchor.Id); |
| 79 | } |
| 80 | |
| 81 | [Fact] |
| 82 | public void Autocomplete_hex_entry_still_suppressed_for_static_segments() |
| 83 | { |
| 84 | var suggestions = ChatSlashAutocomplete.GetSuggestions("/anchor peek abcd"); |
| 85 | Assert.Empty(suggestions); |
| 86 | } |
| 87 | |
| 88 | [Fact] |
| 89 | public void AnchorPeek_Ordinal_in_preview() |
| 90 | { |
| 91 | var preview = SlashCommandPreviewEvaluator.Evaluate("/anchor peek 1"); |
| 92 | Assert.Equal(SlashCommandPreviewKind.Incomplete, preview.Kind); |
| 93 | } |
| 94 | } |
| 95 | |