diff --git a/Sources/Spezi/Capabilities/Notifications/RegisterRemoteNotificationsAction.swift b/Sources/Spezi/Capabilities/Notifications/RegisterRemoteNotificationsAction.swift index 7670c62..6e67a6d 100644 --- a/Sources/Spezi/Capabilities/Notifications/RegisterRemoteNotificationsAction.swift +++ b/Sources/Spezi/Capabilities/Notifications/RegisterRemoteNotificationsAction.swift @@ -103,6 +103,12 @@ public struct RegisterRemoteNotificationsAction: Sendable { try await registration.access.waitCheckingCancellation() +#if targetEnvironment(simulator) + async let _ = withTimeout(of: .seconds(10)) { @MainActor in + spezi.storage[RemoteNotificationContinuation.self]?.resume(with: .failure(TimeoutError())) + } +#endif + return try await withCheckedThrowingContinuation { continuation in assert(registration.continuation == nil, "continuation wasn't nil") registration.continuation = continuation diff --git a/Tests/UITests/TestApp/RemoteNotifications/RemoteNotificationsTestView.swift b/Tests/UITests/TestApp/RemoteNotifications/RemoteNotificationsTestView.swift index 2c69e51..40b269b 100644 --- a/Tests/UITests/TestApp/RemoteNotifications/RemoteNotificationsTestView.swift +++ b/Tests/UITests/TestApp/RemoteNotifications/RemoteNotificationsTestView.swift @@ -27,6 +27,10 @@ struct RemoteNotificationsTestView: View { if let token { Text(token.description) .foregroundStyle(.green) + } else if let error = error as? LocalizedError, + let description = error.errorDescription ?? error.failureReason { + Text(verbatim: description) + .foregroundStyle(.red) } else if error != nil { Text(verbatim: "failed") .foregroundStyle(.red) diff --git a/Tests/UITests/TestAppUITests/RemoteNotificationsTests.swift b/Tests/UITests/TestAppUITests/RemoteNotificationsTests.swift index 4d8beb8..1d046df 100644 --- a/Tests/UITests/TestAppUITests/RemoteNotificationsTests.swift +++ b/Tests/UITests/TestAppUITests/RemoteNotificationsTests.swift @@ -10,6 +10,11 @@ import XCTest final class RemoteNotificationsTests: XCTestCase { + @MainActor + override func setUp() async throws { + continueAfterFailure = false + } + @MainActor func testRegistrationOnSimulator() throws { let app = XCUIApplication() @@ -26,7 +31,11 @@ final class RemoteNotificationsTests: XCTestCase { XCTAssertTrue(app.buttons["Unregister"].exists) app.buttons["Register"].tap() - XCTAssertTrue(app.staticTexts["Token, 80 bytes"].waitForExistence(timeout: 1.0)) + + if !app.staticTexts["Token, 80 bytes"].waitForExistence(timeout: 1.0) { + XCTAssertFalse(app.staticTexts["Token, failed"].exists) + XCTAssertTrue(app.staticTexts["Token, Timeout"].waitForExistence(timeout: 15)) + } app.buttons["Unregister"].tap() XCTAssertTrue(app.staticTexts["Token, none"].waitForExistence(timeout: 1.0))