diff --git a/App/Sources/Enumerations/TodoGroup.swift b/App/Sources/Enumerations/TodoGroup.swift index ccf3ac2..cb0b8ea 100644 --- a/App/Sources/Enumerations/TodoGroup.swift +++ b/App/Sources/Enumerations/TodoGroup.swift @@ -5,6 +5,16 @@ import SwiftUI /// /// This enumeration provides a semantic grouping mechanism for organizing and filtering todo tasks throughout the application. /// Each case represents a distinct category that helps users manage their tasks based on temporal relevance and completion state. +/// +/// ## Features +/// - Provides localized titles and icons for each group +/// - Supports filtering of completed tasks within temporal groups +/// - Enables color-coded visual categorization +/// +/// ## Groups +/// Groups are categorized into two types: +/// - **Temporal groups** (`.today`, `.upcoming`, `.overdue`): Time-based categorization that can optionally include completed tasks +/// - **Status group** (`.completed`): Contains all completed tasks regardless of due date enum TodoGroup { /// Tasks that have been marked as done, regardless of due date. case completed @@ -20,6 +30,17 @@ enum TodoGroup { extension TodoGroup { + /// Indicates whether this group supports toggling the visibility of completed tasks. + /// + /// This property determines if a show/hide completed tasks action should be available for the group. + /// + /// - Returns: `true` for temporal groups (`.today`, `.upcoming`, `.overdue`) that can optionally + /// show or hide completed tasks. Returns `false` for the `.completed` group since it exclusively + /// displays completed tasks. + var canShowCompleted: Bool { + self != .completed + } + /// The color associated with the task group. var color: Color { switch self { @@ -40,7 +61,7 @@ extension TodoGroup { } } - /// The display title for the task group. + /// The localized display title for the task group. var title: LocalizedStringKey { switch self { case .completed: "enumeration.todo-group.title.completed" @@ -57,6 +78,13 @@ extension TodoGroup { extension TodoGroup: CaseIterable { + /// All todo group cases in their display order. + /// + /// The cases are ordered by priority and temporal relevance: + /// 1. `.today` - Most immediate tasks + /// 2. `.upcoming` - Future tasks + /// 3. `.overdue` - Past due tasks requiring attention + /// 4. `.completed` - Finished tasks static var allCases: [TodoGroup] { [.today, .upcoming, .overdue, .completed] } } @@ -65,6 +93,9 @@ extension TodoGroup: CaseIterable { extension TodoGroup: Identifiable { + /// The unique identifier for the group. + /// + /// Uses the case itself as the identifier, enabling use in SwiftUI's `ForEach` and other collection views. var id: Self { self } } diff --git a/UnitTests/Tests/Enumerations/TodoGroupTests.swift b/UnitTests/Tests/Enumerations/TodoGroupTests.swift index e58058e..22116ee 100644 --- a/UnitTests/Tests/Enumerations/TodoGroupTests.swift +++ b/UnitTests/Tests/Enumerations/TodoGroupTests.swift @@ -9,6 +9,25 @@ struct TodoGroupTests { // MARK: Computed tests + @Test( + "canShowCompleted returns correct values", + arguments: zip( + TodoGroup.allCases, + [true, true, true, false] + ) + ) + func canShowCompleted( + for group: TodoGroup, + expects expectation: Bool + ) { + // GIVEN + // WHEN + let canShowCompleted = group.canShowCompleted + + // THEN + #expect(canShowCompleted == expectation) + } + @Test( "group color match expected values", arguments: zip(