< Summary

Information
Class: Chronicis.Client.Components.Articles.WikiLinkAutocompleteItem
Assembly: Chronicis.Client
File(s): /home/runner/work/chronicis/chronicis/src/Chronicis.Client/Components/Articles/WikiLinkAutocompleteItem.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 40
Coverable lines: 40
Total lines: 68
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 12
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor()100%210%
get_IsExternal()100%210%
get_IsCategory()100%210%
get_Title()100%210%
get_SecondaryText()100%210%
get_Source()100%210%
get_ArticleId()100%210%
get_ExternalId()100%210%
get_CategoryKey()100%210%
get_Icon()100%210%
get_MatchedAlias()100%210%
get_SourceBadge()0%620%
get_DisplayTitle()0%620%
FromInternal(...)100%210%
FromExternal(...)0%7280%

File(s)

/home/runner/work/chronicis/chronicis/src/Chronicis.Client/Components/Articles/WikiLinkAutocompleteItem.cs

#LineLine coverage
 1using Chronicis.Shared.DTOs;
 2
 3namespace Chronicis.Client.Components.Articles;
 4
 5public sealed class WikiLinkAutocompleteItem
 6{
 07    private WikiLinkAutocompleteItem()
 8    {
 09    }
 10
 011    public bool IsExternal { get; private init; }
 012    public bool IsCategory { get; private init; }
 013    public string Title { get; private init; } = string.Empty;
 014    public string? SecondaryText { get; private init; }
 015    public string? Source { get; private init; }
 016    public Guid? ArticleId { get; private init; }
 017    public string? ExternalId { get; private init; }
 018    public string? CategoryKey { get; private init; }
 019    public string? Icon { get; private init; }
 20
 21    /// <summary>
 22    /// If the suggestion matched via an alias, this contains the matched alias.
 23    /// Used for display: "MatchedAlias (Title)"
 24    /// </summary>
 025    public string? MatchedAlias { get; private init; }
 26
 027    public string SourceBadge => string.IsNullOrWhiteSpace(Source)
 028        ? string.Empty
 029        : Source.ToUpperInvariant();
 30
 31    /// <summary>
 32    /// Gets the display title. If matched via alias, shows "Alias (Title)".
 33    /// </summary>
 034    public string DisplayTitle => !string.IsNullOrWhiteSpace(MatchedAlias)
 035        ? $"{MatchedAlias} ({Title})"
 036        : Title;
 37
 38    public static WikiLinkAutocompleteItem FromInternal(LinkSuggestionDto suggestion)
 39    {
 040        return new WikiLinkAutocompleteItem
 041        {
 042            IsExternal = false,
 043            IsCategory = false,
 044            Title = suggestion.Title,
 045            SecondaryText = suggestion.DisplayPath,
 046            ArticleId = suggestion.ArticleId,
 047            MatchedAlias = suggestion.MatchedAlias
 048        };
 49    }
 50
 51    public static WikiLinkAutocompleteItem FromExternal(ExternalLinkSuggestionDto suggestion)
 52    {
 053        var isCategory = suggestion.Category == "_category";
 54
 055        return new WikiLinkAutocompleteItem
 056        {
 057            IsExternal = true,
 058            IsCategory = isCategory,
 059            Title = isCategory ? $"{suggestion.Icon} {suggestion.Title}" : suggestion.Title,
 060            SecondaryText = suggestion.Subtitle,
 061            Source = suggestion.Source,
 062            ExternalId = isCategory ? null : suggestion.Id,
 063            CategoryKey = isCategory ? suggestion.Id?.Replace("_category/", "") : null,
 064            Icon = suggestion.Icon,
 065            MatchedAlias = null // External links don't have aliases
 066        };
 67    }
 68}