Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions Examples/Reminders/Schema.swift
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func appDatabase() throws -> any DatabaseWriter {
db.trace(options: .profile) {
if context == .live {
logger.debug("\($0.expandedDescription)")
} else {
} else if context == .preview {
print("\($0.expandedDescription)")
Comment on lines +145 to 146
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's a bit noisy to get all the SQL queries in tests, so opting out of that for now.

}
}
Expand Down Expand Up @@ -387,8 +387,10 @@ nonisolated private let logger = Logger(subsystem: "Reminders", category: "Datab
func seedSampleData() throws {
@Dependency(\.date.now) var now
@Dependency(\.uuid) var uuid
let remindersListIDs = (0...2).map { _ in uuid() }
let reminderIDs = (0...10).map { _ in uuid() }
let remindersListIDs = [uuid(), uuid(), uuid()]
let reminderIDs = [
uuid(), uuid(), uuid(), uuid(), uuid(), uuid(), uuid(), uuid(), uuid(), uuid(), uuid()
]
try seed {
RemindersList(
id: remindersListIDs[0],
Expand Down
5 changes: 4 additions & 1 deletion Examples/RemindersTests/Internal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import Testing
.dependency(\.continuousClock, ImmediateClock()),
.dependency(\.date.now, Date(timeIntervalSince1970: 1_234_567_890)),
.dependency(\.uuid, .incrementing),
.dependencies { try $0.bootstrapDatabase() },
.dependencies {
try $0.bootstrapDatabase()
try await $0.defaultSyncEngine.sendChanges()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now users of our library can decide to send all changes to "iCloud" after they bootstrap their database (in reality this sends the records to a completely mocked, in-memory version of iCloud).

},
.snapshots(record: .failed)
)
struct BaseTestSuite {}
Expand Down
54 changes: 54 additions & 0 deletions Examples/RemindersTests/RemindersListsTests.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import Dependencies
import DependenciesTestSupport
import Foundation
import InlineSnapshotTesting
import SnapshotTestingCustomDump
import Testing
Expand All @@ -8,6 +10,9 @@ import Testing
extension BaseTestSuite {
@MainActor
struct RemindersListsTests {
@Dependency(\.defaultDatabase) var database
@Dependency(\.defaultSyncEngine) var syncEngine

@Test func basics() async throws {
let model = RemindersListsModel()
try await model.$remindersLists.load()
Expand Down Expand Up @@ -100,5 +105,54 @@ extension BaseTestSuite {
"""
}
}

@Test func share() async throws {
let model = RemindersListsModel()

let personalRemindersList = try #require(
try await database.read { db in
try RemindersList.find(UUID(0)).fetchOne(db)
}
)
let _ = try await syncEngine.share(record: personalRemindersList, configure: { _ in })
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There isn't a ton we can test in our demo when it comes to sharing, but we can at least see that the act of sharing this list does indeed populate the share state in the snapshot below. If there was more nuanced logic in this query we would be able to test that.


try await model.$remindersLists.load()
assertInlineSnapshot(of: model.remindersLists, as: .customDump) {
"""
[
[0]: RemindersListsModel.ReminderListState(
remindersCount: 4,
remindersList: RemindersList(
id: UUID(00000000-0000-0000-0000-000000000000),
color: 1218047999,
position: 1,
title: "Personal"
),
share: CKShare()
),
[1]: RemindersListsModel.ReminderListState(
remindersCount: 2,
remindersList: RemindersList(
id: UUID(00000000-0000-0000-0000-000000000001),
color: 3985191935,
position: 2,
title: "Family"
),
share: nil
),
[2]: RemindersListsModel.ReminderListState(
remindersCount: 2,
remindersList: RemindersList(
id: UUID(00000000-0000-0000-0000-000000000002),
color: 2992493567,
position: 3,
title: "Business"
),
share: nil
)
]
"""
}
}
}
}
153 changes: 35 additions & 118 deletions Examples/RemindersTests/SearchRemindersTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,38 +28,34 @@ extension BaseTestSuite {
model.searchText = "Take"
try await model.searchTask?.value
#expect(model.searchResults.completedCount == 1)
withKnownIssue(
"'@Fetch' introduces an escaping closure and loses the task-local dependency"
) {
assertInlineSnapshot(of: model.searchResults.rows, as: .customDump) {
"""
[
[0]: SearchRemindersModel.Row(
isPastDue: false,
assertInlineSnapshot(of: model.searchResults.rows, as: .customDump) {
"""
[
[0]: SearchRemindersModel.Row(
isPastDue: true,
notes: "",
reminder: Reminder(
id: UUID(00000000-0000-0000-0000-00000000000A),
dueDate: Date(2009-02-17T23:31:30.000Z),
isFlagged: false,
notes: "",
reminder: Reminder(
id: UUID(00000000-0000-0000-0000-00000000000A),
dueDate: Date(2009-02-17T23:31:30.000Z),
isCompleted: false,
isFlagged: false,
notes: "",
position: 8,
priority: .high,
remindersListID: UUID(00000000-0000-0000-0000-000000000001),
title: "Take out trash"
),
remindersList: RemindersList(
id: UUID(00000000-0000-0000-0000-000000000001),
color: 3985191935,
position: 2,
title: "Family"
),
tags: "",
title: "**Take** out trash"
)
]
"""
}
position: 8,
priority: .high,
remindersListID: UUID(00000000-0000-0000-0000-000000000001),
status: .incomplete,
title: "Take out trash"
),
remindersList: RemindersList(
id: UUID(00000000-0000-0000-0000-000000000001),
color: 3985191935,
position: 2,
title: "Family"
),
tags: "",
title: "**Take** out trash"
)
]
"""
}
}

Expand All @@ -68,61 +64,10 @@ extension BaseTestSuite {
model.searchText = "Take"
try await model.showCompletedButtonTapped()

withKnownIssue(
"'@Fetch' introduces an escaping closure and loses the task-local dependency"
) {
assertInlineSnapshot(of: model.searchResults.rows, as: .customDump) {
"""
[
[0]: SearchRemindersModel.Row(
isPastDue: false,
notes: "",
reminder: Reminder(
id: UUID(00000000-0000-0000-0000-00000000000A),
dueDate: Date(2009-02-17T23:31:30.000Z),
isCompleted: false,
isFlagged: false,
notes: "",
position: 8,
priority: .high,
remindersListID: UUID(00000000-0000-0000-0000-000000000001),
title: "Take out trash"
),
remindersList: RemindersList(
id: UUID(00000000-0000-0000-0000-000000000001),
color: 3985191935,
position: 2,
title: "Family"
),
tags: "",
title: "**Take** out trash"
),
[1]: SearchRemindersModel.Row(
isPastDue: false,
notes: "",
reminder: Reminder(
id: UUID(00000000-0000-0000-0000-000000000006),
dueDate: Date(2008-08-07T23:31:30.000Z),
isCompleted: true,
isFlagged: false,
notes: "",
position: 4,
priority: nil,
remindersListID: UUID(00000000-0000-0000-0000-000000000000),
title: "Take a walk"
),
remindersList: RemindersList(
id: UUID(00000000-0000-0000-0000-000000000000),
color: 1218047999,
position: 1,
title: "Personal"
),
tags: "#car #kids #social",
title: "**Take** a walk"
)
]
"""
}
assertInlineSnapshot(of: model.searchResults.rows, as: .customDump) {
"""
[]
"""
}
}

Expand All @@ -133,38 +78,10 @@ extension BaseTestSuite {
model.deleteCompletedReminders()
try await model.$searchResults.load()
#expect(model.searchResults.completedCount == 0)
withKnownIssue(
"'@Fetch' introduces an escaping closure and loses the task-local dependency"
) {
assertInlineSnapshot(of: model.searchResults.rows, as: .customDump) {
"""
[
[0]: SearchRemindersModel.Row(
isPastDue: false,
notes: "",
reminder: Reminder(
id: UUID(00000000-0000-0000-0000-00000000000A),
dueDate: Date(2009-02-17T23:31:30.000Z),
isCompleted: false,
isFlagged: false,
notes: "",
position: 8,
priority: .high,
remindersListID: UUID(00000000-0000-0000-0000-000000000001),
title: "Take out trash"
),
remindersList: RemindersList(
id: UUID(00000000-0000-0000-0000-000000000001),
color: 3985191935,
position: 2,
title: "Family"
),
tags: "",
title: "**Take** out trash"
)
]
"""
}
assertInlineSnapshot(of: model.searchResults.rows, as: .customDump) {
"""
[]
"""
}
}
}
Expand Down
Loading
Loading