Improved some tests cases for the NewTaskViewModelTests and the TaskGroupListViewModelTests tests in the unit tests target.
This commit is contained in:
@@ -124,10 +124,7 @@ struct NewTaskViewModelTests {
|
|||||||
@MainActor
|
@MainActor
|
||||||
func saveWithAllProperties() throws {
|
func saveWithAllProperties() throws {
|
||||||
// GIVEN
|
// GIVEN
|
||||||
let container = try ModelContainer(
|
let container = try modelContainer
|
||||||
for: Todo.self,
|
|
||||||
configurations: .init(isStoredInMemoryOnly: true)
|
|
||||||
)
|
|
||||||
let context = container.mainContext
|
let context = container.mainContext
|
||||||
let viewModel = NewTaskView.ViewModel()
|
let viewModel = NewTaskView.ViewModel()
|
||||||
|
|
||||||
@@ -153,10 +150,7 @@ struct NewTaskViewModelTests {
|
|||||||
@MainActor
|
@MainActor
|
||||||
func saveWithEmptyNote() throws {
|
func saveWithEmptyNote() throws {
|
||||||
// GIVEN
|
// GIVEN
|
||||||
let container = try ModelContainer(
|
let container = try modelContainer
|
||||||
for: Todo.self,
|
|
||||||
configurations: .init(isStoredInMemoryOnly: true)
|
|
||||||
)
|
|
||||||
let context = container.mainContext
|
let context = container.mainContext
|
||||||
let viewModel = NewTaskView.ViewModel()
|
let viewModel = NewTaskView.ViewModel()
|
||||||
|
|
||||||
@@ -182,10 +176,7 @@ struct NewTaskViewModelTests {
|
|||||||
@MainActor
|
@MainActor
|
||||||
func saveWithWhitespaceNote() throws {
|
func saveWithWhitespaceNote() throws {
|
||||||
// GIVEN
|
// GIVEN
|
||||||
let container = try ModelContainer(
|
let container = try modelContainer
|
||||||
for: Todo.self,
|
|
||||||
configurations: .init(isStoredInMemoryOnly: true)
|
|
||||||
)
|
|
||||||
let context = container.mainContext
|
let context = container.mainContext
|
||||||
let viewModel = NewTaskView.ViewModel()
|
let viewModel = NewTaskView.ViewModel()
|
||||||
|
|
||||||
@@ -211,10 +202,7 @@ struct NewTaskViewModelTests {
|
|||||||
@MainActor
|
@MainActor
|
||||||
func saveMultipleTodos() throws {
|
func saveMultipleTodos() throws {
|
||||||
// GIVEN
|
// GIVEN
|
||||||
let container = try ModelContainer(
|
let container = try modelContainer
|
||||||
for: Todo.self,
|
|
||||||
configurations: .init(isStoredInMemoryOnly: true)
|
|
||||||
)
|
|
||||||
let context = container.mainContext
|
let context = container.mainContext
|
||||||
let viewModelFirst = NewTaskView.ViewModel()
|
let viewModelFirst = NewTaskView.ViewModel()
|
||||||
let viewModelSecond = 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 {
|
func countWhenEmptyData(for group: TodoGroup) throws {
|
||||||
// GIVEN
|
// GIVEN
|
||||||
let tasks: [Todo] = []
|
|
||||||
let viewModel = TaskGroupListView.ViewModel()
|
let viewModel = TaskGroupListView.ViewModel()
|
||||||
|
|
||||||
// WHEN
|
// WHEN
|
||||||
let count = viewModel.count(tasks, for: group)
|
let count = viewModel.count(emptyTasks, for: group)
|
||||||
|
|
||||||
// THEN
|
// THEN
|
||||||
#expect(count == 0)
|
#expect(count == 0)
|
||||||
@@ -53,13 +52,33 @@ struct TaskGroupListViewModelTests {
|
|||||||
)
|
)
|
||||||
func countWhenFilledData(for group: TodoGroup) throws {
|
func countWhenFilledData(for group: TodoGroup) throws {
|
||||||
// GIVEN
|
// 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 today: Date = .now
|
||||||
let tomorrow = calendar.date(byAdding: .day, value: 1, to: today) ?? today
|
let tomorrow = calendar.date(byAdding: .day, value: 1, to: today) ?? today
|
||||||
let yesterday = 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 nextWeek = calendar.date(byAdding: .day, value: 7, to: today) ?? today
|
||||||
let lastWeek = 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 #1", due: today),
|
||||||
Todo(title: "Today task #2", due: today),
|
Todo(title: "Today task #2", due: today),
|
||||||
Todo(title: "Tomorrow task #1", due: tomorrow),
|
Todo(title: "Tomorrow task #1", due: tomorrow),
|
||||||
@@ -67,16 +86,8 @@ struct TaskGroupListViewModelTests {
|
|||||||
Todo(title: "Yesterday task #1", due: yesterday),
|
Todo(title: "Yesterday task #1", due: yesterday),
|
||||||
Todo(title: "Last week task #1", due: lastWeek),
|
Todo(title: "Last week task #1", due: lastWeek),
|
||||||
Todo(title: "Completed task #1", due: tomorrow, completed: today),
|
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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user