mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-16 23:52:40 -06:00
88 lines
4.0 KiB
Swift
88 lines
4.0 KiB
Swift
import Contacts
|
|
import EventKit
|
|
import Foundation
|
|
import Photos
|
|
import Testing
|
|
@testable import OpenClaw
|
|
|
|
struct DevicePermissionsTests {
|
|
@Test func `contacts statuses map to shared grants`() {
|
|
#expect(DevicePermissionStatusMap.contacts(.authorized) == .granted)
|
|
#expect(DevicePermissionStatusMap.contacts(.limited) == .limited)
|
|
#expect(DevicePermissionStatusMap.contacts(.notDetermined) == .notRequested)
|
|
#expect(DevicePermissionStatusMap.contacts(.denied) == .denied)
|
|
#expect(DevicePermissionStatusMap.contacts(.restricted) == .denied)
|
|
}
|
|
|
|
@Test func `photos statuses map to shared grants`() {
|
|
#expect(DevicePermissionStatusMap.photos(.authorized) == .granted)
|
|
#expect(DevicePermissionStatusMap.photos(.limited) == .limited)
|
|
#expect(DevicePermissionStatusMap.photos(.notDetermined) == .notRequested)
|
|
#expect(DevicePermissionStatusMap.photos(.denied) == .denied)
|
|
}
|
|
|
|
@Test func `event kit write-only is limited for read but granted for add`() {
|
|
#expect(DevicePermissionStatusMap.eventKitRead(.writeOnly) == .limited)
|
|
#expect(DevicePermissionStatusMap.eventKitWrite(.writeOnly) == .granted)
|
|
#expect(DevicePermissionStatusMap.eventKitRead(.fullAccess) == .granted)
|
|
#expect(DevicePermissionStatusMap.eventKitWrite(.fullAccess) == .granted)
|
|
#expect(DevicePermissionStatusMap.eventKitRead(.notDetermined) == .notRequested)
|
|
#expect(DevicePermissionStatusMap.eventKitRead(.denied) == .denied)
|
|
}
|
|
|
|
@Test func `first-run onboarding moves directly from intro to pairing`() {
|
|
#expect(OnboardingStep.intro.previous == nil)
|
|
#expect(OnboardingStep.welcome.previous == .intro)
|
|
#expect(!OnboardingStep.welcome.canGoBack)
|
|
#expect(OnboardingStep.welcome.manualProgressTitle.isEmpty)
|
|
}
|
|
|
|
@Test func `onboarding has no aggregate system permission prompt`() throws {
|
|
let onboardingDirectory = Self.sourceRoot()
|
|
.appending(path: "Onboarding", directoryHint: .isDirectory)
|
|
let wizard = try String(
|
|
contentsOf: onboardingDirectory.appending(path: "OnboardingWizardView.swift"),
|
|
encoding: .utf8)
|
|
|
|
#expect(!FileManager.default.fileExists(
|
|
atPath: onboardingDirectory.appending(path: "OnboardingPermissionsStep.swift").path))
|
|
#expect(!wizard.contains("OnboardingPermissionsStep"))
|
|
#expect(!wizard.contains("navigate(to: .permissions)"))
|
|
}
|
|
|
|
@Test func `settings first request says Continue and immediately requests permission`() throws {
|
|
let settings = try String(
|
|
contentsOf: Self.sourceRoot()
|
|
.appending(path: "Settings", directoryHint: .isDirectory)
|
|
.appending(path: "PrivacyAccessSectionView.swift"),
|
|
encoding: .utf8)
|
|
let actionTitles = try #require(Self.extract(
|
|
settings,
|
|
from: " private func standardActionTitle(",
|
|
to: " /// `limitedRequests`"))
|
|
let action = try #require(Self.extract(
|
|
settings,
|
|
from: " private func standardAction(",
|
|
to: " private func requestContacts()"))
|
|
|
|
#expect(actionTitles.contains("case .notRequested:\n LocalizedStringResource(\"Continue\")"))
|
|
#expect(!actionTitles.contains("LocalizedStringResource(\"Allow\")"))
|
|
#expect(action.contains("await request()"))
|
|
#expect(action.contains("case .notRequested:\n return run"))
|
|
}
|
|
|
|
private static func sourceRoot() -> URL {
|
|
URL(fileURLWithPath: #filePath)
|
|
.deletingLastPathComponent()
|
|
.deletingLastPathComponent()
|
|
.appending(path: "Sources", directoryHint: .isDirectory)
|
|
}
|
|
|
|
private static func extract(_ source: String, from start: String, to end: String) -> String? {
|
|
guard let startRange = source.range(of: start),
|
|
let endRange = source.range(of: end, range: startRange.upperBound..<source.endIndex)
|
|
else { return nil }
|
|
return String(source[startRange.lowerBound..<endRange.lowerBound])
|
|
}
|
|
}
|