< Summary

Information
Class: Pomodoro.Web.Components.ConsentModalBase
Assembly: Pomodoro.Web
File(s): /home/runner/work/Pomodoro/Pomodoro/src/Pomodoro.Web/Components/ConsentModal.razor.cs
Line coverage
100%
Covered lines: 73
Uncovered lines: 0
Coverable lines: 73
Total lines: 148
Line coverage: 100%
Branch coverage
100%
Covered branches: 18
Total branches: 18
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_IsVisible()100%11100%
get_CompletedSessionType()100%11100%
get_CountdownSeconds()100%11100%
get_Options()100%11100%
get_OnOptionSelected()100%11100%
OnParametersSet()100%44100%
GetIcon()100%44100%
GetTitle()100%44100%
GetMessage()100%44100%
GetProgressPercentage()100%22100%
HandleOptionSelect()100%11100%
get_RenderOptions()100%11100%

File(s)

/home/runner/work/Pomodoro/Pomodoro/src/Pomodoro.Web/Components/ConsentModal.razor.cs

#LineLine coverage
 1using Microsoft.AspNetCore.Components;
 2using Microsoft.AspNetCore.Components.Web;
 3using Pomodoro.Web.Models;
 4using Pomodoro.Web.Services;
 5
 6namespace Pomodoro.Web.Components;
 7
 8/// <summary>
 9/// Code-behind for ConsentModal component
 10/// Separates business logic from view
 11/// </summary>
 12public class ConsentModalBase : ComponentBase
 13{
 14    #region Parameters (Model)
 15
 16    [Parameter]
 69117    public bool IsVisible { get; set; }
 18
 19    [Parameter]
 41320    public SessionType CompletedSessionType { get; set; }
 21
 22    [Parameter]
 110523    public int CountdownSeconds { get; set; }
 24
 25    [Parameter]
 63926    public List<ConsentOption> Options { get; set; } = new();
 27
 28    [Parameter]
 32729    public EventCallback<SessionType> OnOptionSelected { get; set; }
 30
 31    #endregion
 32
 33    #region Constants
 34
 35    /// <summary>Maximum countdown seconds for the consent modal (used for progress bar calculation)</summary>
 36    private int _initialCountdownSeconds;
 37
 38    #endregion
 39
 40    #region Lifecycle Methods
 41
 42    protected override void OnParametersSet()
 34643    {
 44        // Track the initial countdown value for progress bar calculation
 45        // Only update if the countdown was reset (back to a higher value)
 34646        if (CountdownSeconds > _initialCountdownSeconds)
 2347        {
 2348            _initialCountdownSeconds = CountdownSeconds;
 2349        }
 50
 51        // If countdown is 0, reset for next time
 34652        if (CountdownSeconds <= 0)
 32353        {
 32354            _initialCountdownSeconds = 0;
 32355        }
 34656    }
 57
 58    #endregion
 59
 60    #region Business Logic Methods
 61
 62    /// <summary>
 63    /// Gets the icon for the completed session type
 64    /// </summary>
 65    protected string GetIcon()
 2366    {
 2367        return CompletedSessionType switch
 2368        {
 1669            SessionType.Pomodoro => Constants.SessionTypes.PomodoroEmoji,
 370            SessionType.ShortBreak => Constants.SessionTypes.ShortBreakEmoji,
 371            SessionType.LongBreak => Constants.SessionTypes.LongBreakEmoji,
 172            _ => Constants.SessionTypes.PomodoroEmoji
 2373        };
 2374    }
 75
 76    /// <summary>
 77    /// Gets the title for the completed session type
 78    /// </summary>
 79    protected string GetTitle()
 2380    {
 2381        return CompletedSessionType switch
 2382        {
 1683            SessionType.Pomodoro => Constants.Messages.PomodoroCompleteTitle,
 384            SessionType.ShortBreak => Constants.Messages.BreakCompleteTitle,
 385            SessionType.LongBreak => Constants.Messages.LongBreakCompleteTitle,
 186            _ => Constants.Messages.SessionCompleteTitle
 2387        };
 2388    }
 89
 90    /// <summary>
 91    /// Gets the message for the completed session type
 92    /// </summary>
 93    protected string GetMessage()
 2394    {
 2395        return CompletedSessionType switch
 2396        {
 1697            SessionType.Pomodoro => Constants.Messages.PomodoroCompleteMessage,
 398            SessionType.ShortBreak => Constants.Messages.BreakCompleteMessage,
 399            SessionType.LongBreak => Constants.Messages.BreakCompleteMessage,
 1100            _ => Constants.Messages.SessionCompleteMessage
 23101        };
 23102    }
 103
 104    /// <summary>
 105    /// Calculates the progress bar percentage
 106    /// </summary>
 107    protected double GetProgressPercentage()
 23108    {
 23109        if (_initialCountdownSeconds <= 0)
 2110            return 0;
 111
 21112        return ((double)CountdownSeconds / _initialCountdownSeconds) * Constants.UI.PercentageMultiplier;
 23113    }
 114
 115    /// <summary>
 116    /// Handles option selection
 117    /// </summary>
 118    protected async Task HandleOptionSelect(SessionType sessionType)
 1119    {
 1120        await OnOptionSelected.InvokeAsync(sessionType);
 1121    }
 122
 6123    protected RenderFragment RenderOptions => builder =>
 6124    {
 6125        int seq = 0;
 38126        foreach (var option in Options)
 10127        {
 10128            var cssClass = $"btn btn-option {(option.IsDefault ? "default" : "")}";
 10129            builder.OpenElement(seq++, "button");
 10130            builder.AddAttribute(seq++, "class", cssClass);
 11131            builder.AddAttribute(seq++, "onclick", EventCallback.Factory.Create<MouseEventArgs>(this, _ => HandleOptionS
 6132
 10133            builder.OpenElement(seq++, "span");
 10134            builder.AddAttribute(seq++, "class", "option-label");
 10135            builder.AddContent(seq++, option.Label);
 10136            builder.CloseElement();
 6137
 10138            builder.OpenElement(seq++, "span");
 10139            builder.AddAttribute(seq++, "class", "option-duration");
 10140            builder.AddContent(seq++, option.Duration);
 10141            builder.CloseElement();
 6142
 10143            builder.CloseElement();
 10144        }
 12145    };
 146
 147    #endregion
 148}