List tasks feature (#4)
This PR contains the work done to implement the **List Tasks** feature, and to integrate it into the main content view of the app. Reviewed-on: rock-n-code/todos-app#4 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 #4.
This commit is contained in:
@@ -124,10 +124,7 @@ struct NewTaskViewModelTests {
|
||||
@MainActor
|
||||
func saveWithAllProperties() throws {
|
||||
// GIVEN
|
||||
let container = try ModelContainer(
|
||||
for: Todo.self,
|
||||
configurations: .init(isStoredInMemoryOnly: true)
|
||||
)
|
||||
let container = try modelContainer
|
||||
let context = container.mainContext
|
||||
let viewModel = NewTaskView.ViewModel()
|
||||
|
||||
@@ -153,10 +150,7 @@ struct NewTaskViewModelTests {
|
||||
@MainActor
|
||||
func saveWithEmptyNote() throws {
|
||||
// GIVEN
|
||||
let container = try ModelContainer(
|
||||
for: Todo.self,
|
||||
configurations: .init(isStoredInMemoryOnly: true)
|
||||
)
|
||||
let container = try modelContainer
|
||||
let context = container.mainContext
|
||||
let viewModel = NewTaskView.ViewModel()
|
||||
|
||||
@@ -182,10 +176,7 @@ struct NewTaskViewModelTests {
|
||||
@MainActor
|
||||
func saveWithWhitespaceNote() throws {
|
||||
// GIVEN
|
||||
let container = try ModelContainer(
|
||||
for: Todo.self,
|
||||
configurations: .init(isStoredInMemoryOnly: true)
|
||||
)
|
||||
let container = try modelContainer
|
||||
let context = container.mainContext
|
||||
let viewModel = NewTaskView.ViewModel()
|
||||
|
||||
@@ -211,10 +202,7 @@ struct NewTaskViewModelTests {
|
||||
@MainActor
|
||||
func saveMultipleTodos() throws {
|
||||
// GIVEN
|
||||
let container = try ModelContainer(
|
||||
for: Todo.self,
|
||||
configurations: .init(isStoredInMemoryOnly: true)
|
||||
)
|
||||
let container = try modelContainer
|
||||
let context = container.mainContext
|
||||
let viewModelFirst = NewTaskView.ViewModel()
|
||||
let viewModelSecond = NewTaskView.ViewModel()
|
||||
@@ -237,3 +225,20 @@ struct NewTaskViewModelTests {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: - Helpers
|
||||
|
||||
private extension NewTaskViewModelTests {
|
||||
|
||||
// MARK: Computed
|
||||
|
||||
var modelContainer: ModelContainer {
|
||||
get throws {
|
||||
try ModelContainer(
|
||||
for: Todo.self,
|
||||
configurations: .init(isStoredInMemoryOnly: true)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -37,11 +37,10 @@ struct TaskGroupListViewModelTests {
|
||||
)
|
||||
func countWhenEmptyData(for group: TodoGroup) throws {
|
||||
// GIVEN
|
||||
let tasks: [Todo] = []
|
||||
let viewModel = TaskGroupListView.ViewModel()
|
||||
|
||||
// WHEN
|
||||
let count = viewModel.count(tasks, for: group)
|
||||
let count = viewModel.count(emptyTasks, for: group)
|
||||
|
||||
// THEN
|
||||
#expect(count == 0)
|
||||
@@ -53,13 +52,33 @@ struct TaskGroupListViewModelTests {
|
||||
)
|
||||
func countWhenFilledData(for group: TodoGroup) throws {
|
||||
// GIVEN
|
||||
let viewModel = TaskGroupListView.ViewModel()
|
||||
|
||||
// WHEN
|
||||
let count = viewModel.count(sampleTasks, for: group)
|
||||
|
||||
// THEN
|
||||
#expect(count == 2)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: - Helpers
|
||||
|
||||
private extension TaskGroupListViewModelTests {
|
||||
|
||||
// MARK: Computed
|
||||
|
||||
var emptyTasks: [Todo] { [] }
|
||||
|
||||
var sampleTasks: [Todo] {
|
||||
let today: Date = .now
|
||||
let tomorrow = calendar.date(byAdding: .day, value: 1, to: today) ?? today
|
||||
let yesterday = calendar.date(byAdding: .day, value: -1, to: today) ?? today
|
||||
let nextWeek = calendar.date(byAdding: .day, value: 7, to: today) ?? today
|
||||
let lastWeek = calendar.date(byAdding: .day, value: -7, to: today) ?? today
|
||||
|
||||
let tasks = [
|
||||
return [
|
||||
Todo(title: "Today task #1", due: today),
|
||||
Todo(title: "Today task #2", due: today),
|
||||
Todo(title: "Tomorrow task #1", due: tomorrow),
|
||||
@@ -67,16 +86,8 @@ struct TaskGroupListViewModelTests {
|
||||
Todo(title: "Yesterday task #1", due: yesterday),
|
||||
Todo(title: "Last week task #1", due: lastWeek),
|
||||
Todo(title: "Completed task #1", due: tomorrow, completed: today),
|
||||
Todo(title: "Completed task #2", due: yesterday, completed: today)
|
||||
Todo(title: "Completed task #2", due: yesterday, completed: today),
|
||||
]
|
||||
|
||||
let viewModel = TaskGroupListView.ViewModel()
|
||||
|
||||
// WHEN
|
||||
let count = viewModel.count(tasks, for: group)
|
||||
|
||||
// THEN
|
||||
#expect(count == 2)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import Foundation
|
||||
import SwiftData
|
||||
import Testing
|
||||
|
||||
@testable import Todos
|
||||
|
||||
@Suite("TaskList view model tests")
|
||||
struct TaskListViewModelTests {
|
||||
|
||||
// MARK: Computed tests
|
||||
|
||||
@Test(
|
||||
"navigationTitle returns correct title for each and every group",
|
||||
arguments: TodoGroup.allCases
|
||||
)
|
||||
func navigationTitle(for group: TodoGroup) {
|
||||
// GIVEN
|
||||
let viewModel = TaskListView.ViewModel(group: group)
|
||||
|
||||
// WHEN
|
||||
let title = viewModel.navigationTitle
|
||||
|
||||
// THEN
|
||||
#expect(title == group.title)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user