Files
openclaw/apps/macos/Tests/OpenClawIPCTests/DashboardNotificationsBridgeTests.swift
Peter Steinberger 42133d0c3c feat(mac): show native notification permission in dashboard Notifications settings (#110646)
* feat(mac): show native notification permission in dashboard Notifications settings

The Mac app's embedded Control UI showed the web-push section as
Unsupported/Not subscribed even though the app delivers notifications
natively. The dashboard now installs an openclawNotifications WebKit
bridge (status / request-permission / send-test) and the Notifications
settings page renders native permission state with Enable, Open System
Settings, and Send test actions when hosted in the Mac app. Browsers
keep the existing web-push UI. The notifications section renderer moved
out of the oversized config view module.

* fix(ui): break config view import cycle and satisfy lint/deadcode/i18n gates

Move the notifications section props to a leaf contract (no view.ts
type import), unexport the status-event constant, use bracket access
for the injected dunder global, default-case the status switch, and
refresh the native i18n inventory line offset.
2026-07-18 14:13:06 +01:00

33 lines
1.6 KiB
Swift

import Testing
import UserNotifications
@testable import OpenClaw
@MainActor
struct DashboardNotificationsBridgeTests {
@Test func `parses notification requests`() {
#expect(DashboardWindowController.notificationsRequest(from: ["type": "status"]) == .status)
#expect(DashboardWindowController.notificationsRequest(
from: ["type": "request-permission"]) == .requestPermission)
#expect(DashboardWindowController.notificationsRequest(
from: ["type": "send-test"]) == .sendTest)
}
@Test func `rejects invalid notification requests`() {
#expect(DashboardWindowController.notificationsRequest(from: ["type": "unknown"]) == nil)
#expect(DashboardWindowController.notificationsRequest(from: "status") == nil)
}
@Test func `maps notification permission labels`() throws {
#expect(DashboardWindowController.notificationsPermissionLabel(for: .authorized) == "granted")
#expect(DashboardWindowController.notificationsPermissionLabel(for: .provisional) == "granted")
// Ephemeral (unavailable by name on macOS, raw value 4) cannot occur here
// and maps to notDetermined with the rest of the default branch.
let ephemeral = try #require(UNAuthorizationStatus(rawValue: 4))
#expect(DashboardWindowController.notificationsPermissionLabel(
for: ephemeral) == "notDetermined")
#expect(DashboardWindowController.notificationsPermissionLabel(for: .denied) == "denied")
#expect(DashboardWindowController.notificationsPermissionLabel(
for: .notDetermined) == "notDetermined")
}
}