diff --git a/Sources/XCTSpeziNotifications/XCUIApplication+AuthorizationAlert.swift b/Sources/XCTSpeziNotifications/XCUIApplication+AuthorizationAlert.swift index d5263a6..f08f002 100644 --- a/Sources/XCTSpeziNotifications/XCUIApplication+AuthorizationAlert.swift +++ b/Sources/XCTSpeziNotifications/XCUIApplication+AuthorizationAlert.swift @@ -21,14 +21,25 @@ extension XCUIApplication { /// Confirm the notification authorization dialog. /// - Parameter action: The action to confirm the alert with. @available(tvOS, unavailable) + @available(macOS, unavailable) + @available(watchOS, unavailable) public func confirmNotificationAuthorization(action: NotificationAuthorizationAction = .allow) { - let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard") - let predicate = NSPredicate(format: "label CONTAINS 'Would Like to Send You Notifications'") + +#if os(iOS) + let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard") let alert = springboard.alerts.element(matching: predicate) XCTAssert(alert.waitForExistence(timeout: 5.0)) - print(springboard.alerts.element(matching: predicate).debugDescription) XCTAssert(alert.buttons[action.rawValue].exists) alert.buttons[action.rawValue].tap() +#elseif os(visionOS) + let notifications = XCUIApplication(bundleIdentifier: "com.apple.RealityNotifications") + print(notifications.debugDescription) // TODO: remove + XCTAssert(notifications.scrollViews.staticTexts.element(matching: predicate).waitForExistence(timeout: 5.0)) + XCTAssert(notifications.buttons[action.rawValue].exists) + notifications.buttons[action.rawValue].tap() +#else + preconditionFailure("Unsupported platform") +#endif } } diff --git a/Tests/UITests/TestApp/ControlsView.swift b/Tests/UITests/TestApp/ControlsView.swift index ce0c8e1..4e161e7 100644 --- a/Tests/UITests/TestApp/ControlsView.swift +++ b/Tests/UITests/TestApp/ControlsView.swift @@ -124,6 +124,7 @@ struct ControlsView: View { extension UNNotificationContent { static func content(type: String, interruption: UNNotificationInterruptionLevel = .active) -> UNNotificationContent { let content = UNMutableNotificationContent() +#if !os(tvOS) content.title = "\(type) Notification" content.subtitle = "Test Notification" content.body = "This is a \(type.lowercased()) notification" @@ -132,6 +133,7 @@ extension UNNotificationContent { content.threadIdentifier = "SpeziNotifications" content.interruptionLevel = interruption content.sound = .default +#endif return content }