diff --git a/Application/Presentation/NotificationTab/Tests/PushNotification/PushNotificationListTestSpies.swift b/Application/Presentation/NotificationTab/Tests/PushNotification/PushNotificationListTestSpies.swift new file mode 100644 index 00000000..40ad683b --- /dev/null +++ b/Application/Presentation/NotificationTab/Tests/PushNotification/PushNotificationListTestSpies.swift @@ -0,0 +1,52 @@ +// +// PushNotificationListTestSpies.swift +// NotificationTabTests +// +// Created by opfic on 7/6/26. +// + +import Domain + +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]() + var error: Error? + + func execute(_ todoId: String) async throws { + calledTodoIds.append(todoId) + if let error { + throw error + } + } +} + +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) + } +} diff --git a/Application/Presentation/PresentationShared/Tests/Support/TestSupport.swift b/Application/Presentation/PresentationShared/Tests/Support/TestSupport.swift index 64c56022..71530f20 100644 --- a/Application/Presentation/PresentationShared/Tests/Support/TestSupport.swift +++ b/Application/Presentation/PresentationShared/Tests/Support/TestSupport.swift @@ -7,10 +7,6 @@ import Testing import Foundation -import Combine -import Core -import Domain -@testable import PresentationShared @MainActor func waitUntil( @@ -25,254 +21,3 @@ func waitUntil( 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 { - Empty().eraseToAnyPublisher() - } -} - -final class SignInUseCaseSpy: SignInUseCase { - var error: Error? - var signedIn = true - var shouldSuspend = false - private(set) var calledProviders: [AuthProvider] = [] - private(set) var successfulProviders = [AuthProvider]() - private var continuation: CheckedContinuation? - private var shouldResume = false - - func execute(_ provider: AuthProvider) async throws -> Bool { - calledProviders.append(provider) - - if shouldSuspend { - await withCheckedContinuation { continuation in - if shouldResume { - shouldResume = false - continuation.resume() - } else { - self.continuation = continuation - } - } - } - - if let error { - throw error - } - - if signedIn { - successfulProviders.append(provider) - } - - return signedIn - } - - 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] = [] - var error: Error? - - func execute(_ todoId: String) async throws { - calledTodoIds.append(todoId) - if let error { - throw error - } - } -} - -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 { - var error: Error? - private(set) var calledUrlStrings: [String] = [] - - func execute(_ urlString: String) async throws { - calledUrlStrings.append(urlString) - if let error { - throw error - } - } -} - -final class DeleteWebPageUseCaseSpy: DeleteWebPageUseCase { - private(set) var calls: [(id: String, urlString: String)] = [] - - func execute(id: String, urlString: String) async throws { - calls.append((id, urlString)) - } -} - -final class UndoDeleteWebPageUseCaseSpy: UndoDeleteWebPageUseCase { - private(set) var calledIDs: [String] = [] - - func execute(_ id: String) async throws { - calledIDs.append(id) - } -} - -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 FetchUserDataUseCaseSpy: FetchUserDataUseCase { - var profile: UserProfile - - init(profile: UserProfile) { - self.profile = profile - } - - func execute() async throws -> UserProfile { - profile - } -} - -final class FetchProfileImageDataUseCaseSpy: FetchProfileImageDataUseCase { - var data: Data - private(set) var calledURLs: [URL] = [] - - init(data: Data) { - self.data = data - } - - func execute(from url: URL) async throws -> Data { - calledURLs.append(url) - return data - } -} - -final class UpsertStatusMessageUseCaseSpy: UpsertStatusMessageUseCase { - private(set) var messages: [String] = [] - - func execute(_ message: String) async throws { - messages.append(message) - } -} - -final class FetchHeatmapActivityTypesUseCaseSpy: FetchHeatmapActivityTypesUseCase { - var activityTypes: [String] = [] - - func execute() -> [String] { - activityTypes - } -} - -final class UpdateHeatmapActivityTypesUseCaseSpy: UpdateHeatmapActivityTypesUseCase { - private(set) var activityTypes: [[String]] = [] - - func execute(_ activityTypes: [String]) { - self.activityTypes.append(activityTypes) - } -} - -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(true) - - func observe() -> AnyPublisher { - currentValueSubject.eraseToAnyPublisher() - } -}