Task edition improvements (#9)

This PR contains the work done to improve upon the editing experience on the **Task list item and the **New task** views.

Reviewed-on: rock-n-code/todos-app#9
Co-authored-by: Javier Cicchelli <javier@rock-n-code.com>
Co-committed-by: Javier Cicchelli <javier@rock-n-code.com>
This commit was merged in pull request #9.
This commit is contained in:
2026-02-12 01:21:19 +00:00
committed by javier
parent bbd7ec264b
commit 52376695a4
11 changed files with 355 additions and 47 deletions
@@ -0,0 +1,49 @@
@testable import class Todos.Todo
@testable import protocol Todos.TodoRepository
/// A mock implementation of the TodoRepository protocol for unit testing.
///
/// This mock repository provides a simple in-memory storage mechanism for testing
/// without requiring a full SwiftData ModelContext setup. It tracks inserted and
/// deleted todos, allowing tests to verify repository operations.
final class MockTodoRepository {
// MARK: Properties
/// Array of todo tasks managed by this mock repository.
///
/// This property tracks all todos in the repository, maintaining state across
/// insert and delete operations. It serves as the in-memory storage for the mock,
/// allowing tests to verify repository behavior without requiring SwiftData.
private(set) var todos: [Todo]
// MARK: Initializers
/// Creates a new mock repository with an optional initial set of todo tasks.
///
/// This initializer allows tests to set up a repository with pre-existing todos
/// or start with an empty repository. The default parameter value provides
/// convenient initialization for most test cases.
///
/// - Parameter todos: An array of todo tasks to initialize the repository with. Defaults to an empty array.
init(todos: [Todo] = []) {
self.todos = todos
}
}
// MARK: - TodoRepository
extension MockTodoRepository: TodoRepository {
// MARK: Functions
func delete(_ todo: Todo) {
todos.removeAll { $0.id == todo.id }
}
func insert(_ todo: Todo) {
todos.append(todo)
}
}