Task deletion feature (#7)
This PR contains the work done to add support for todo tasks deletion on the *Task list* view. Reviewed-on: rock-n-code/todos-app#7 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 #7.
This commit is contained in:
@@ -91,6 +91,45 @@ struct TaskListViewModelTests {
|
||||
|
||||
// MARK: Method tests
|
||||
|
||||
@Test("deleteTasks removes a single task from model context")
|
||||
func deleteTasksSingle() throws {
|
||||
// GIVEN
|
||||
let container = try ModelContainer(
|
||||
for: Todo.self,
|
||||
configurations: .init(isStoredInMemoryOnly: true)
|
||||
)
|
||||
let context = ModelContext(container)
|
||||
|
||||
let viewModel = TaskListView.ViewModel(group: .today)
|
||||
let todosToInsert: [Todo] = [
|
||||
.init(title: "Task 1", due: .now, order: 0),
|
||||
.init(title: "Task 2", due: .now, order: 1),
|
||||
.init(title: "Task 3", due: .now, order: 2),
|
||||
]
|
||||
let countInitial = todosToInsert.count
|
||||
|
||||
for todo in todosToInsert {
|
||||
context.insert(todo)
|
||||
}
|
||||
|
||||
// WHEN
|
||||
viewModel.deleteTasks(
|
||||
todosToInsert,
|
||||
at: IndexSet(integer: 1),
|
||||
from: context
|
||||
)
|
||||
|
||||
// THEN
|
||||
let descriptor = FetchDescriptor<Todo>()
|
||||
let todos = try context.fetch(descriptor)
|
||||
|
||||
#expect(countInitial == 3)
|
||||
#expect(todos.count == 2)
|
||||
#expect(todos.contains(where: { $0.title == "Task 1" }))
|
||||
#expect(todos.contains(where: { $0.title == "Task 3" }))
|
||||
#expect(!todos.contains(where: { $0.title == "Task 2" }))
|
||||
}
|
||||
|
||||
@Test("reorderTasks updates order property when moving task forward")
|
||||
func reorderTasksMovingForward() {
|
||||
// GIVEN
|
||||
|
||||
Reference in New Issue
Block a user