< Summary

Information
Class: Chronicis.Client.Services.AutocompleteCommitDecision
Assembly: Chronicis.Client
File(s): /home/runner/work/chronicis/chronicis/src/Chronicis.Client/Services/AutocompleteCommitDecision.cs
Line coverage
100%
Covered lines: 17
Uncovered lines: 0
Coverable lines: 17
Total lines: 59
Line coverage: 100%
Branch coverage
100%
Covered branches: 16
Total branches: 16
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
.ctor(...)100%11100%
.ctor()100%11100%
Decide(...)100%1414100%
ExtractArticleName(...)100%22100%

File(s)

/home/runner/work/chronicis/chronicis/src/Chronicis.Client/Services/AutocompleteCommitDecision.cs

#LineLine coverage
 1namespace Chronicis.Client.Services;
 2
 3/// <summary>
 4/// Pure discriminated union returned by <see cref="AutocompleteCommitDecision.Decide"/>.
 5/// Hosts pattern-match on this to choose the correct commit path.
 6/// </summary>
 7public abstract record AutocompleteCommitDecision
 8{
 9    /// <summary>Select the existing suggestion at <see cref="Index"/>.</summary>
 410    public sealed record SelectExisting(int Index) : AutocompleteCommitDecision;
 11
 12    /// <summary>Create a new article with the resolved <see cref="Name"/>.</summary>
 713    public sealed record CreateNew(string Name) : AutocompleteCommitDecision;
 14
 15    /// <summary>No action — guard conditions were not met.</summary>
 1016    public sealed record DoNothing() : AutocompleteCommitDecision;
 17
 18    /// <summary>
 19    /// Determines what the host should do when Enter is pressed in the autocomplete.
 20    /// </summary>
 21    /// <param name="query">Current autocomplete query (internal remainder for external queries).</param>
 22    /// <param name="suggestionsCount">Number of suggestions currently visible.</param>
 23    /// <param name="selectedIndex">Currently highlighted suggestion index.</param>
 24    /// <param name="isExternalQuery">True when the query targets an external provider (e.g. srd/).</param>
 25    /// <param name="isMapQuery">True when the query targets the maps namespace.</param>
 26    public static AutocompleteCommitDecision Decide(
 27        string query,
 28        int suggestionsCount,
 29        int selectedIndex,
 30        bool isExternalQuery,
 31        bool isMapQuery)
 32    {
 1933        if (suggestionsCount > 0 && selectedIndex >= 0 && selectedIndex < suggestionsCount)
 334            return new SelectExisting(selectedIndex);
 35
 1636        if (isExternalQuery || isMapQuery)
 237            return new DoNothing();
 38
 1439        var trimmed = (query ?? string.Empty).Trim();
 1440        if (trimmed.Length < 3)
 641            return new DoNothing();
 42
 843        var name = ExtractArticleName(trimmed);
 844        return string.IsNullOrEmpty(name) ? new DoNothing() : new CreateNew(name);
 45    }
 46
 47    /// <summary>
 48    /// Extracts a display name from the query, taking the last path segment and
 49    /// capitalising the first letter — parity with ArticleDetailWikiLinkAutocomplete.GetArticleName.
 50    /// </summary>
 51    private static string ExtractArticleName(string query)
 52    {
 853        var segments = query.Split('/');
 854        var name = segments[^1].Trim();
 855        if (string.IsNullOrEmpty(name))
 156            return string.Empty;
 757        return char.ToUpper(name[0]) + name[1..];
 58    }
 59}