Add iOS platform service boundaries

This commit is contained in:
Mikhail Kilin
2026-05-20 15:48:33 +03:00
parent 593b19ba8e
commit 8bea159569
4 changed files with 242 additions and 1 deletions

View File

@@ -8,6 +8,7 @@ struct TeleTuiIOSSmokeTests {
try await chatListLoadsDeterministicFakeDataAndFilters()
try await chatDetailLoadsAndSendsMessage()
try await messageActionsCoverEditReplyForwardReactDeleteSearchAndCopy()
try await platformServicesCoverNotificationsMediaVoiceClipboardAndAccounts()
try await profileLoadsFromSelectedChat()
appStorageUsesApplicationSupportStyleAccountPaths()
print("TeleTuiIOS smoke tests passed")
@@ -100,6 +101,46 @@ struct TeleTuiIOSSmokeTests {
precondition(!viewModel.messages.contains { $0.id == 1 })
}
@MainActor
private static func platformServicesCoverNotificationsMediaVoiceClipboardAndAccounts() async throws {
let root = URL(fileURLWithPath: "/tmp/TeleTuiIOS")
let paths = AppStoragePaths(root: root)
let cache = MediaCache(root: paths.mediaCachePath(for: "work"))
precondition(cache.photoPath(fileId: 10).path == "/tmp/TeleTuiIOS/Accounts/work/Media/photos/10.jpg")
precondition(cache.voicePath(fileId: 20).path == "/tmp/TeleTuiIOS/Accounts/work/Media/voices/20.ogg")
let policy = NotificationPolicy()
let chat = ChatSummary(id: 1, title: "Chat", lastMessage: "hello", isMuted: false)
let muted = ChatSummary(id: 2, title: "Muted", lastMessage: "hello", isMuted: true)
let incomingMention = Message(id: 1, chatId: 1, senderName: "Alice", text: "@me hello", isOutgoing: false)
let incomingPlain = Message(id: 2, chatId: 1, senderName: "Alice", text: "hello", isOutgoing: false)
precondition(policy.shouldNotify(chat: chat, message: incomingMention, mentionOnly: true))
precondition(!policy.shouldNotify(chat: chat, message: incomingPlain, mentionOnly: true))
precondition(!policy.shouldNotify(chat: muted, message: incomingMention, mentionOnly: false))
let clipboard = InMemoryClipboardWriter()
await clipboard.write(text: "copied")
let copiedText = await clipboard.currentText()
precondition(copiedText == "copied")
let player = RecordingVoicePlayer()
let mediaViewModel = MediaViewModel(cache: cache, voicePlayer: player)
let voiceURL = cache.voicePath(fileId: 20)
await mediaViewModel.playVoice(url: voiceURL)
precondition(mediaViewModel.isVoicePlaying)
let loadedURL = await player.currentLoadedURL()
precondition(loadedURL == voiceURL)
await mediaViewModel.pauseVoice()
precondition(!mediaViewModel.isVoicePlaying)
let personal = Account(id: "personal", displayName: "Personal", databasePath: paths.databasePath(for: "personal"))
let work = Account(id: "work", displayName: "Work", databasePath: paths.databasePath(for: "work"))
let switcher = AccountSwitcherViewModel(accounts: [personal, work], activeAccount: personal)
switcher.switchToAccount(id: "work")
precondition(switcher.activeAccount.id == "work")
precondition(switcher.activeAccount.databasePath.path.hasSuffix("/Accounts/work/tdlib"))
}
@MainActor
private static func profileLoadsFromSelectedChat() async throws {
let bridge = FakeSessionBridge(auth: .ready)