Skip to content

Commit

Permalink
Support notification alert on visionOS
Browse files Browse the repository at this point in the history
  • Loading branch information
Supereg committed Sep 30, 2024
1 parent dced38b commit cf47812
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check failure on line 37 in Sources/XCTSpeziNotifications/XCUIApplication+AuthorizationAlert.swift

View workflow job for this annotation

GitHub Actions / Build and Test / SwiftLint / SwiftLint / SwiftLint

Todo Violation: TODOs should be resolved (remove) (todo)
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
}
}
2 changes: 2 additions & 0 deletions Tests/UITests/TestApp/ControlsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -132,6 +133,7 @@ extension UNNotificationContent {
content.threadIdentifier = "SpeziNotifications"
content.interruptionLevel = interruption
content.sound = .default
#endif

return content
}
Expand Down

0 comments on commit cf47812

Please sign in to comment.