< Summary

Information
Class: Pomodoro.Web.Services.LayoutPresenterService
Assembly: Pomodoro.Web
File(s): /home/runner/work/Pomodoro/Pomodoro/src/Pomodoro.Web/Services/LayoutPresenterService.cs
Line coverage
100%
Covered lines: 56
Uncovered lines: 0
Coverable lines: 56
Total lines: 131
Line coverage: 100%
Branch coverage
100%
Covered branches: 10
Total branches: 10
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%
GetNavMenuCssClass()100%22100%
ToggleNavMenu()100%11100%
GetNavMenuCollapsedState()100%11100%
SetNavMenuCollapsedState(...)100%11100%
GetCurrentYear()100%11100%
ShouldHighlightNavLink(...)100%88100%
GetNavigationLinks()100%11100%

File(s)

/home/runner/work/Pomodoro/Pomodoro/src/Pomodoro.Web/Services/LayoutPresenterService.cs

#LineLine coverage
 1using Microsoft.AspNetCore.Components;
 2using Microsoft.AspNetCore.Components.Routing;
 3
 4namespace Pomodoro.Web.Services
 5{
 6    /// <summary>
 7    /// Service for managing layout-related presentation logic
 8    /// </summary>
 9    public class LayoutPresenterService
 10    {
 25411        private bool _collapseNavMenu = true;
 12
 13        /// <summary>
 14        /// Gets the CSS class for the navigation menu based on its collapsed state
 15        /// </summary>
 16        /// <returns>CSS class name or null if not collapsed</returns>
 17        public virtual string? GetNavMenuCssClass()
 618        {
 619            return _collapseNavMenu ? "collapse" : null;
 620        }
 21
 22        /// <summary>
 23        /// Toggles the navigation menu's collapsed state
 24        /// </summary>
 25        /// <returns>New collapsed state</returns>
 26        public virtual bool ToggleNavMenu()
 727        {
 728            _collapseNavMenu = !_collapseNavMenu;
 729            return _collapseNavMenu;
 730        }
 31
 32        /// <summary>
 33        /// Gets the current collapsed state of the navigation menu
 34        /// </summary>
 35        /// <returns>True if collapsed, false if expanded</returns>
 36        public bool GetNavMenuCollapsedState()
 1137        {
 1138            return _collapseNavMenu;
 1139        }
 40
 41        /// <summary>
 42        /// Sets the navigation menu's collapsed state
 43        /// </summary>
 44        /// <param name="collapsed">True to collapse, false to expand</param>
 45        public void SetNavMenuCollapsedState(bool collapsed)
 1346        {
 1347            _collapseNavMenu = collapsed;
 1348        }
 49
 50        /// <summary>
 51        /// Gets the current year for footer copyright display
 52        /// </summary>
 53        /// <returns>Current UTC year</returns>
 54        public virtual int GetCurrentYear()
 3555        {
 3556            return DateTime.UtcNow.Year;
 3557        }
 58
 59        /// <summary>
 60        /// Determines if a navigation link should be highlighted based on the current URI
 61        /// </summary>
 62        /// <param name="href">The href of the navigation link</param>
 63        /// <param name="currentUri">The current page URI</param>
 64        /// <param name="match">The NavLinkMatch behavior</param>
 65        /// <returns>True if the link should be highlighted</returns>
 66        public bool ShouldHighlightNavLink(string href, Uri currentUri, NavLinkMatch match = NavLinkMatch.Prefix)
 1567        {
 1568            if (string.IsNullOrEmpty(href))
 369                return false;
 70
 1271            if (match == NavLinkMatch.All)
 472            {
 473                return currentUri.AbsolutePath == href ||
 474                       (currentUri.AbsolutePath == "/" && href == "");
 75            }
 76
 877            return currentUri.AbsolutePath.StartsWith(href, StringComparison.OrdinalIgnoreCase);
 1578        }
 79
 80        /// <summary>
 81        /// Gets navigation link data for the application
 82        /// </summary>
 83        /// <returns>Collection of navigation link information</returns>
 84        public virtual IEnumerable<NavLinkData> GetNavigationLinks()
 4085        {
 4086            yield return new NavLinkData
 4087            {
 4088                Href = Constants.Routing.HomeRoute,
 4089                Icon = Constants.Layout.TimerNavIcon,
 4090                Title = Constants.Layout.TimerNavLinkTitle,
 4091                Match = NavLinkMatch.All
 4092            };
 93
 4094            yield return new NavLinkData
 4095            {
 4096                Href = Constants.Routing.HistoryRoute,
 4097                Icon = Constants.Layout.HistoryNavIcon,
 4098                Title = Constants.Layout.HistoryNavLinkTitle,
 4099                Match = NavLinkMatch.Prefix
 40100            };
 101
 40102            yield return new NavLinkData
 40103            {
 40104                Href = Constants.Routing.SettingsRoute,
 40105                Icon = Constants.Layout.SettingsNavIcon,
 40106                Title = Constants.Layout.SettingsNavLinkTitle,
 40107                Match = NavLinkMatch.Prefix
 40108            };
 109
 40110            yield return new NavLinkData
 40111            {
 40112                Href = Constants.Routing.AboutRoute,
 40113                Icon = Constants.Layout.AboutNavIcon,
 40114                Title = Constants.Layout.AboutNavLinkTitle,
 40115                Match = NavLinkMatch.Prefix
 40116            };
 40117        }
 118
 119    }
 120
 121    /// <summary>
 122    /// Data model for navigation links
 123    /// </summary>
 124    public class NavLinkData
 125    {
 126        public string Href { get; set; } = string.Empty;
 127        public string Icon { get; set; } = string.Empty;
 128        public string Title { get; set; } = string.Empty;
 129        public NavLinkMatch Match { get; set; } = NavLinkMatch.Prefix;
 130    }
 131}