< Summary

Information
Class: Pomodoro.Web.Services.Formatters.ActivityItemFormatter
Assembly: Pomodoro.Web
File(s): /home/runner/work/Pomodoro/Pomodoro/src/Pomodoro.Web/Services/Formatters/ActivityItemFormatter.cs
Line coverage
100%
Covered lines: 22
Uncovered lines: 0
Coverable lines: 22
Total lines: 74
Line coverage: 100%
Branch coverage
100%
Covered branches: 14
Total branches: 14
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
IsValidActivity(...)100%22100%
GetFormattedTime(...)100%22100%
GetFormattedDuration(...)100%22100%
GetSessionTypeDisplay(...)100%22100%
HasTask(...)100%22100%
GetTaskName(...)100%44100%

File(s)

/home/runner/work/Pomodoro/Pomodoro/src/Pomodoro.Web/Services/Formatters/ActivityItemFormatter.cs

#LineLine coverage
 1using Pomodoro.Web.Models;
 2
 3namespace Pomodoro.Web.Services.Formatters;
 4
 5/// <summary>
 6/// Service for formatting ActivityItem component data.
 7/// Extracts formatting logic from component to enable testable code with coverage tracking.
 8/// </summary>
 9public class ActivityItemFormatter
 10{
 11    /// <summary>
 12    /// Checks if the activity is valid.
 13    /// </summary>
 14    /// <param name="activity">The activity to check</param>
 15    /// <returns>True if activity is not null and has a valid ID</returns>
 16    public bool IsValidActivity(ActivityRecord? activity)
 617    {
 618        return activity != null && activity.Id != Guid.Empty;
 619    }
 20
 21    /// <summary>
 22    /// Gets the formatted time for display.
 23    /// </summary>
 24    /// <param name="activity">The activity to format</param>
 25    /// <returns>Formatted time string (HH:mm) or "N/A" if null</returns>
 26    public string GetFormattedTime(ActivityRecord? activity)
 527    {
 628        if (activity == null) return "N/A";
 429        return activity.CompletedAt.ToString("HH:mm");
 530    }
 31
 32    /// <summary>
 33    /// Gets the formatted duration for display.
 34    /// </summary>
 35    /// <param name="activity">The activity to format</param>
 36    /// <returns>Formatted duration string (e.g., "25m") or "0m" if null</returns>
 37    public string GetFormattedDuration(ActivityRecord? activity)
 538    {
 639        if (activity == null) return "0m";
 440        return $"{activity.DurationMinutes}m";
 541    }
 42
 43    /// <summary>
 44    /// Gets the session type display name.
 45    /// </summary>
 46    /// <param name="activity">The activity to format</param>
 47    /// <returns>Session type name or "Unknown" if null</returns>
 48    public string GetSessionTypeDisplay(ActivityRecord? activity)
 549    {
 650        if (activity == null) return "Unknown";
 451        return activity.Type.ToString();
 552    }
 53
 54    /// <summary>
 55    /// Checks if the activity has an associated task.
 56    /// </summary>
 57    /// <param name="activity">The activity to check</param>
 58    /// <returns>True if activity has a task name</returns>
 59    public bool HasTask(ActivityRecord? activity)
 760    {
 761        return activity != null && !string.IsNullOrWhiteSpace(activity.TaskName);
 762    }
 63
 64    /// <summary>
 65    /// Gets the task name for display.
 66    /// </summary>
 67    /// <param name="activity">The activity to format</param>
 68    /// <returns>Task name or "No task" if null or empty</returns>
 69    public string GetTaskName(ActivityRecord? activity)
 770    {
 871        if (activity == null) return "No task";
 672        return string.IsNullOrWhiteSpace(activity.TaskName) ? "No task" : activity.TaskName;
 773    }
 74}