Implemented the view refresh after data updates for the TaskGroupListView view in the app target.
This commit is contained in:
@@ -31,58 +31,49 @@ struct TaskGroupListViewModelTests {
|
||||
|
||||
// MARK: Functions tests
|
||||
|
||||
@MainActor
|
||||
@Test(
|
||||
"count returns zero when empty data",
|
||||
arguments: TodoGroup.allCases
|
||||
)
|
||||
func countWhenEmptyData(for group: TodoGroup) throws {
|
||||
// GIVEN
|
||||
let container = try ModelContainer(
|
||||
for: Todo.self,
|
||||
configurations: .init(isStoredInMemoryOnly: true)
|
||||
)
|
||||
let tasks: [Todo] = []
|
||||
let viewModel = TaskGroupListView.ViewModel()
|
||||
|
||||
// WHEN
|
||||
let count = viewModel.count(for: group, in: container.mainContext)
|
||||
let count = viewModel.count(tasks, for: group)
|
||||
|
||||
// THEN
|
||||
#expect(count == 0)
|
||||
}
|
||||
|
||||
@MainActor
|
||||
@Test(
|
||||
"count returns correct count when filled data",
|
||||
arguments: TodoGroup.allCases
|
||||
)
|
||||
func countWhenFilledData(for group: TodoGroup) throws {
|
||||
// GIVEN
|
||||
let container = try ModelContainer(
|
||||
for: Todo.self,
|
||||
configurations: .init(isStoredInMemoryOnly: true)
|
||||
)
|
||||
let context = container.mainContext
|
||||
|
||||
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
|
||||
|
||||
context.insert(Todo(title: "Today task #1", due: today))
|
||||
context.insert(Todo(title: "Today task #2", due: today))
|
||||
context.insert(Todo(title: "Tomorrow task #1", due: tomorrow))
|
||||
context.insert(Todo(title: "Next week task #1", due: nextWeek))
|
||||
context.insert(Todo(title: "Yesterday task #1", due: yesterday))
|
||||
context.insert(Todo(title: "Last week task #1", due: lastWeek))
|
||||
context.insert(Todo(title: "Completed task #1", due: tomorrow, completed: today))
|
||||
context.insert(Todo(title: "Completed task #2", due: yesterday, completed: today))
|
||||
let tasks = [
|
||||
Todo(title: "Today task #1", due: today),
|
||||
Todo(title: "Today task #2", due: today),
|
||||
Todo(title: "Tomorrow task #1", due: tomorrow),
|
||||
Todo(title: "Next week task #1", due: nextWeek),
|
||||
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)
|
||||
]
|
||||
|
||||
let viewModel = TaskGroupListView.ViewModel()
|
||||
|
||||
// WHEN
|
||||
let count = viewModel.count(for: group, in: context)
|
||||
let count = viewModel.count(tasks, for: group)
|
||||
|
||||
// THEN
|
||||
#expect(count == 2)
|
||||
|
||||
Reference in New Issue
Block a user