| | | 1 | | using Pomodoro.Web.Components.History; |
| | | 2 | | |
| | | 3 | | namespace Pomodoro.Web.Services.Formatters; |
| | | 4 | | |
| | | 5 | | /// <summary> |
| | | 6 | | /// Service for formatting StatCard component data. |
| | | 7 | | /// Extracts formatting logic from component to enable testable code with coverage tracking. |
| | | 8 | | /// </summary> |
| | | 9 | | public class StatCardFormatter |
| | | 10 | | { |
| | | 11 | | /// <summary> |
| | | 12 | | /// Gets the formatted value for display. |
| | | 13 | | /// Returns "0" if value is empty or null. |
| | | 14 | | /// </summary> |
| | | 15 | | /// <param name="value">The value to format</param> |
| | | 16 | | /// <returns>Formatted value string</returns> |
| | | 17 | | public string GetFormattedValue(string? value) |
| | 8 | 18 | | { |
| | 8 | 19 | | return string.IsNullOrWhiteSpace(value) ? "0" : value; |
| | 8 | 20 | | } |
| | | 21 | | |
| | | 22 | | /// <summary> |
| | | 23 | | /// Gets the formatted label for display. |
| | | 24 | | /// Returns "N/A" if label is empty or null. |
| | | 25 | | /// </summary> |
| | | 26 | | /// <param name="label">The label to format</param> |
| | | 27 | | /// <returns>Formatted label string</returns> |
| | | 28 | | public string GetFormattedLabel(string? label) |
| | 7 | 29 | | { |
| | 7 | 30 | | return string.IsNullOrWhiteSpace(label) ? "N/A" : label; |
| | 7 | 31 | | } |
| | | 32 | | |
| | | 33 | | /// <summary> |
| | | 34 | | /// Gets the formatted icon for display. |
| | | 35 | | /// Returns default icon "📊" if icon is empty or null. |
| | | 36 | | /// </summary> |
| | | 37 | | /// <param name="icon">The icon to format</param> |
| | | 38 | | /// <returns>Formatted icon string</returns> |
| | | 39 | | public string GetFormattedIcon(string? icon) |
| | 7 | 40 | | { |
| | 7 | 41 | | return string.IsNullOrWhiteSpace(icon) ? "📊" : icon; |
| | 7 | 42 | | } |
| | | 43 | | |
| | | 44 | | /// <summary> |
| | | 45 | | /// Checks if the stat card has all required data. |
| | | 46 | | /// </summary> |
| | | 47 | | /// <param name="icon">The icon value</param> |
| | | 48 | | /// <param name="value">The value</param> |
| | | 49 | | /// <param name="label">The label</param> |
| | | 50 | | /// <returns>True if all required data is present</returns> |
| | | 51 | | public bool HasRequiredData(string? icon, string? value, string? label) |
| | 12 | 52 | | { |
| | 12 | 53 | | return !string.IsNullOrWhiteSpace(icon) && !string.IsNullOrWhiteSpace(value) && !string.IsNullOrWhiteSpace(label |
| | 12 | 54 | | } |
| | | 55 | | } |