Added the "showCompleted" property to the initializer for the TodoFetchDescriptor+Inits extension in. the app target.
This commit is contained in:
@@ -20,7 +20,10 @@ struct TodoFetchDescriptorTests {
|
||||
let context = container.mainContext
|
||||
|
||||
// WHEN
|
||||
let descriptor = FetchDescriptor<Todo>(group: .today)
|
||||
let descriptor = FetchDescriptor<Todo>(
|
||||
group: .today,
|
||||
showCompleted: .random()
|
||||
)
|
||||
let results = try context.fetch(descriptor)
|
||||
|
||||
// THEN
|
||||
@@ -28,7 +31,7 @@ struct TodoFetchDescriptorTests {
|
||||
}
|
||||
|
||||
@Test(
|
||||
"initializes with group when filled tasks",
|
||||
"initializes with group and show completed disabled when filled tasks",
|
||||
arguments: TodoGroup.allCases
|
||||
)
|
||||
@MainActor
|
||||
@@ -40,7 +43,10 @@ struct TodoFetchDescriptorTests {
|
||||
insert(into: context)
|
||||
|
||||
// WHEN
|
||||
let descriptor = FetchDescriptor<Todo>(group: group)
|
||||
let descriptor = FetchDescriptor<Todo>(
|
||||
group: group,
|
||||
showCompleted: false
|
||||
)
|
||||
let results = try context.fetch(descriptor)
|
||||
|
||||
// THEN
|
||||
@@ -61,6 +67,50 @@ struct TodoFetchDescriptorTests {
|
||||
#expect(results[1].title == "Upcoming task #2")
|
||||
}
|
||||
}
|
||||
|
||||
@Test(
|
||||
"initializes with group and show completed enabled when filled tasks",
|
||||
arguments: TodoGroup.allCases
|
||||
)
|
||||
@MainActor
|
||||
func initializationWithShowCompleted(for group: TodoGroup) throws {
|
||||
// GIVEN
|
||||
let container = try modelContainer
|
||||
let context = container.mainContext
|
||||
|
||||
insert(into: context)
|
||||
|
||||
// WHEN
|
||||
let descriptor = FetchDescriptor<Todo>(
|
||||
group: group,
|
||||
showCompleted: true
|
||||
)
|
||||
let results = try context.fetch(descriptor)
|
||||
|
||||
// THEN
|
||||
if group == .overdue || group == .upcoming {
|
||||
#expect(results.count == 3)
|
||||
} else {
|
||||
#expect(results.count == 2)
|
||||
}
|
||||
|
||||
switch group {
|
||||
case .completed:
|
||||
#expect(results[0].title == "Completed task #2")
|
||||
#expect(results[1].title == "Completed task #1")
|
||||
case .overdue:
|
||||
#expect(results[0].title == "Completed task #1")
|
||||
#expect(results[1].title == "Overdue task #2")
|
||||
#expect(results[2].title == "Overdue task #1")
|
||||
case .today:
|
||||
#expect(results[0].title == "Today task #1")
|
||||
#expect(results[1].title == "Today task #2")
|
||||
case .upcoming:
|
||||
#expect(results[0].title == "Upcoming task #1")
|
||||
#expect(results[1].title == "Upcoming task #2")
|
||||
#expect(results[2].title == "Completed task #2")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user