-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestSupport.swift
More file actions
215 lines (172 loc) · 5.83 KB
/
Copy pathTestSupport.swift
File metadata and controls
215 lines (172 loc) · 5.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
//
// TestSupport.swift
// DevLogPresentationTests
//
// Created by opfic on 4/6/26.
//
import Testing
import Foundation
import Combine
import DevLogCore
import DevLogDomain
@testable import DevLogPresentation
@MainActor
func waitUntil(
timeout: Duration = .seconds(1),
pollInterval: Duration = .milliseconds(20),
_ condition: @escaping () -> Bool
) async {
let continuousClock = ContinuousClock()
let deadline = continuousClock.now + timeout
while !condition() && continuousClock.now < deadline {
try? await Task.sleep(for: pollInterval)
}
}
final class FetchPushNotificationsUseCaseSpy: FetchPushNotificationsUseCase {
var pushNotificationPage: PushNotificationPage
private(set) var executeCallCount = 0
init(pushNotificationPage: PushNotificationPage) {
self.pushNotificationPage = pushNotificationPage
}
func execute(
_ query: PushNotificationQuery,
cursor: PushNotificationCursor?
) async throws -> PushNotificationPage {
executeCallCount += 1
return pushNotificationPage
}
func observe(
_ query: PushNotificationQuery,
limit: Int
) throws -> AnyPublisher<PushNotificationPage, Error> {
Empty().eraseToAnyPublisher()
}
}
final class SignInUseCaseSpy: SignInUseCase {
var error: Error?
var shouldSuspend = false
private(set) var calledProviders: [AuthProvider] = []
private(set) var successfulProviders = [AuthProvider]()
private var continuation: CheckedContinuation<Void, Never>?
private var shouldResume = false
func execute(_ provider: AuthProvider) async throws {
calledProviders.append(provider)
if shouldSuspend {
await withCheckedContinuation { continuation in
if shouldResume {
shouldResume = false
continuation.resume()
} else {
self.continuation = continuation
}
}
}
if let error {
throw error
}
successfulProviders.append(provider)
}
func resume() {
guard let continuation else {
shouldResume = true
return
}
self.continuation = nil
continuation.resume()
}
}
final class DeletePushNotificationUseCaseSpy: DeletePushNotificationUseCase {
private(set) var calledNotificationIds: [String] = []
func execute(_ notificationID: String) async throws {
calledNotificationIds.append(notificationID)
}
}
final class UndoDeletePushNotificationUseCaseSpy: UndoDeletePushNotificationUseCase {
private(set) var calledNotificationIds: [String] = []
func execute(_ notificationID: String) async throws {
calledNotificationIds.append(notificationID)
}
}
final class TogglePushNotificationReadUseCaseSpy: TogglePushNotificationReadUseCase {
private(set) var calledTodoIds: [String] = []
func execute(_ todoId: String) async throws {
calledTodoIds.append(todoId)
}
}
final class FetchPushNotificationQueryUseCaseSpy: FetchPushNotificationQueryUseCase {
var pushNotificationQuery = PushNotificationQuery.default
func execute() -> PushNotificationQuery {
pushNotificationQuery
}
}
final class UpdatePushNotificationQueryUseCaseSpy: UpdatePushNotificationQueryUseCase {
private(set) var queries: [PushNotificationQuery] = []
func execute(_ query: PushNotificationQuery) {
queries.append(query)
}
}
final class FetchTodoCategoryPreferencesUseCaseSpy: FetchTodoCategoryPreferencesUseCase {
var todoCategoryPreferences: [TodoCategoryPreference] = []
func execute() async throws -> [TodoCategoryPreference] {
todoCategoryPreferences
}
}
final class UpdateTodoCategoryPreferencesUseCaseSpy: UpdateTodoCategoryPreferencesUseCase {
private(set) var updates: [[TodoCategoryPreference]] = []
func execute(_ preferences: [TodoCategoryPreference]) async throws {
updates.append(preferences)
}
}
final class AddWebPageUseCaseSpy: AddWebPageUseCase {
private(set) var calledUrlStrings: [String] = []
func execute(_ urlString: String) async throws {
calledUrlStrings.append(urlString)
}
}
final class DeleteWebPageUseCaseSpy: DeleteWebPageUseCase {
private(set) var calledUrlStrings: [String] = []
func execute(_ urlString: String) async throws {
calledUrlStrings.append(urlString)
}
}
final class UndoDeleteWebPageUseCaseSpy: UndoDeleteWebPageUseCase {
private(set) var calledUrlStrings: [String] = []
func execute(_ urlString: String) async throws {
calledUrlStrings.append(urlString)
}
}
final class UpsertTodoUseCaseSpy: UpsertTodoUseCase {
private(set) var todos: [Todo] = []
private(set) var todoDrafts: [TodoDraft] = []
func execute(_ todo: Todo) async throws {
todos.append(todo)
}
func execute(_ todoDraft: TodoDraft) async throws {
todoDrafts.append(todoDraft)
}
}
final class FetchTodosUseCaseSpy: FetchTodosUseCase {
var todoPage = TodoPage(items: [], nextCursor: nil)
private(set) var queries: [TodoQuery] = []
func execute(_ query: TodoQuery, cursor: TodoCursor?) async throws -> TodoPage {
queries.append(query)
return todoPage
}
}
final class FetchWebPagesUseCaseSpy: FetchWebPagesUseCase {
var webPages: [WebPage]
private(set) var calledQueries: [String] = []
init(webPages: [WebPage]) {
self.webPages = webPages
}
func execute(_ query: String) async throws -> [WebPage] {
calledQueries.append(query)
return webPages
}
}
final class ObserveNetworkConnectivityUseCaseSpy: ObserveNetworkConnectivityUseCase {
let currentValueSubject = CurrentValueSubject<Bool, Never>(true)
func observe() -> AnyPublisher<Bool, Never> {
currentValueSubject.eraseToAnyPublisher()
}
}