mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-10-31 08:15:24 +00:00
c0f167ccf7
* Add HealthChat API and extended profile services Expose OpenID tokens and homeserver credentials from the client proxy, and add fork-only services for the HealthChat member directory backend (api.healthchat.ch) plus a service that reads MSC4133 extended profile fields directly from the homeserver. Groundwork for the members tab and the profile screens. Claude-Session: https://claude.ai/code/session_013qdTbAWsZj2quQzEkagXaS * Show extended profile details on the profile screens Add a UserProfileScreenHook that lets the fork inject an extra Form section below the header of the user profile and room member details screens. The HealthChat implementation loads the MSC4133 extended profile fields and renders them with tappable phone/email/website links, hiding the section entirely for profiles without any fields. Strings live in a new fork-only HealthChat.strings table (de/en/fr, generated as HealthChatL10n via SwiftGen) since Untranslated.strings pins the English bundle. Claude-Session: https://claude.ai/code/session_013qdTbAWsZj2quQzEkagXaS * Add a member directory tab Add a HomeTabsHook that lets the fork append an extra tab to the home tab bar, and a HealthChat members flow behind it: a directory of all approved members from the HealthChat API with server-side search, pending-approval and error states, chat shortcuts and pushed member profiles. Chats and calls are handed back to the session flow via the hook's actions publisher. Claude-Session: https://claude.ai/code/session_013qdTbAWsZj2quQzEkagXaS
146 lines
6.2 KiB
Swift
146 lines
6.2 KiB
Swift
//
|
|
// Copyright 2026 Element Creations Ltd.
|
|
//
|
|
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
|
// Please see LICENSE files in the repository root for full details.
|
|
//
|
|
|
|
@testable import ElementX
|
|
import Foundation
|
|
import Testing
|
|
|
|
final class HealthChatMemberDirectoryScreenViewModelTests {
|
|
private let apiService = HealthChatAPIServiceMock()
|
|
private let clientProxy = ClientProxyMock(.init())
|
|
|
|
@Test
|
|
func loadsMembersOnStart() async throws {
|
|
apiService.membersSearchQueryReturnValue = try .success(makeResponse(userIDs: ["@alice:healthchat.ch"]))
|
|
|
|
let viewModel = makeViewModel()
|
|
|
|
let deferred = deferFulfillment(viewModel.context.observe(\.viewState.content)) { content in
|
|
guard case .members(let members) = content else { return false }
|
|
return members.map(\.userID) == ["@alice:healthchat.ch"]
|
|
}
|
|
try await deferred.fulfill()
|
|
}
|
|
|
|
@Test
|
|
func showsPendingApprovalMessage() async throws {
|
|
apiService.membersSearchQueryReturnValue = .success(.init(users: [],
|
|
isApproved: false,
|
|
pendingMessage: "Ihr Konto wird geprüft"))
|
|
|
|
let viewModel = makeViewModel()
|
|
|
|
let deferred = deferFulfillment(viewModel.context.observe(\.viewState.content)) { content in
|
|
content == .pendingApproval(message: "Ihr Konto wird geprüft")
|
|
}
|
|
try await deferred.fulfill()
|
|
}
|
|
|
|
@Test
|
|
func showsFailureAndRecoversOnRetry() async throws {
|
|
apiService.membersSearchQueryReturnValue = .failure(.networkFailure)
|
|
|
|
let viewModel = makeViewModel()
|
|
|
|
let deferredFailure = deferFulfillment(viewModel.context.observe(\.viewState.content)) { $0 == .failure }
|
|
try await deferredFailure.fulfill()
|
|
|
|
apiService.membersSearchQueryReturnValue = try .success(makeResponse(userIDs: ["@alice:healthchat.ch"]))
|
|
|
|
let deferredMembers = deferFulfillment(viewModel.context.observe(\.viewState.content)) { content in
|
|
guard case .members = content else { return false }
|
|
return true
|
|
}
|
|
viewModel.context.send(viewAction: .retry)
|
|
try await deferredMembers.fulfill()
|
|
}
|
|
|
|
@Test
|
|
func searchQueryTriggersServerSearch() async throws {
|
|
let allMembers = try makeResponse(userIDs: ["@alice:healthchat.ch"])
|
|
let searchResults = try makeResponse(userIDs: ["@zoe:healthchat.ch"])
|
|
apiService.membersSearchQueryClosure = { searchQuery in
|
|
searchQuery == "Zürich" ? .success(searchResults) : .success(allMembers)
|
|
}
|
|
|
|
let viewModel = makeViewModel()
|
|
|
|
let deferred = deferFulfillment(viewModel.context.observe(\.viewState.content)) { content in
|
|
guard case .members(let members) = content else { return false }
|
|
return members.map(\.userID) == ["@zoe:healthchat.ch"]
|
|
}
|
|
viewModel.context.searchQuery = "Zürich"
|
|
try await deferred.fulfill()
|
|
|
|
#expect(apiService.membersSearchQueryReceivedInvocations.last == "Zürich")
|
|
}
|
|
|
|
@Test
|
|
func startChatWithExistingDMPresentsRoom() async throws {
|
|
apiService.membersSearchQueryReturnValue = try .success(makeResponse(userIDs: ["@alice:healthchat.ch"]))
|
|
clientProxy.directRoomForUserIDReturnValue = .success("existingRoom")
|
|
|
|
let viewModel = makeViewModel()
|
|
|
|
let deferred = deferFulfillment(viewModel.actionsPublisher) { action in
|
|
guard case .presentRoom(let roomID) = action else { return false }
|
|
return roomID == "existingRoom"
|
|
}
|
|
try viewModel.context.send(viewAction: .startChat(makeMember(userID: "@alice:healthchat.ch")))
|
|
try await deferred.fulfill()
|
|
}
|
|
|
|
@Test
|
|
func startChatWithoutDMCreatesOne() async throws {
|
|
apiService.membersSearchQueryReturnValue = try .success(makeResponse(userIDs: ["@alice:healthchat.ch"]))
|
|
clientProxy.directRoomForUserIDReturnValue = .success(nil)
|
|
clientProxy.createDirectRoomWithExpectedRoomNameReturnValue = .success("newRoom")
|
|
|
|
let viewModel = makeViewModel()
|
|
|
|
let deferred = deferFulfillment(viewModel.actionsPublisher) { action in
|
|
guard case .presentRoom(let roomID) = action else { return false }
|
|
return roomID == "newRoom"
|
|
}
|
|
try viewModel.context.send(viewAction: .startChat(makeMember(userID: "@alice:healthchat.ch")))
|
|
try await deferred.fulfill()
|
|
|
|
#expect(clientProxy.createDirectRoomWithExpectedRoomNameReceivedArguments?.userID == "@alice:healthchat.ch")
|
|
}
|
|
|
|
@Test
|
|
func selectMemberEmitsAction() async throws {
|
|
apiService.membersSearchQueryReturnValue = try .success(makeResponse(userIDs: ["@alice:healthchat.ch"]))
|
|
|
|
let viewModel = makeViewModel()
|
|
|
|
let deferred = deferFulfillment(viewModel.actionsPublisher) { action in
|
|
guard case .selectMember(let userID) = action else { return false }
|
|
return userID == "@alice:healthchat.ch"
|
|
}
|
|
try viewModel.context.send(viewAction: .selectMember(makeMember(userID: "@alice:healthchat.ch")))
|
|
try await deferred.fulfill()
|
|
}
|
|
|
|
// MARK: - Helpers
|
|
|
|
private func makeViewModel() -> HealthChatMemberDirectoryScreenViewModel {
|
|
HealthChatMemberDirectoryScreenViewModel(apiService: apiService,
|
|
clientProxy: clientProxy,
|
|
mediaProvider: MediaProviderMock(.init()),
|
|
userIndicatorController: UserIndicatorControllerMock())
|
|
}
|
|
|
|
private func makeResponse(userIDs: [String]) throws -> HealthChatMembersResponse {
|
|
try .init(users: userIDs.map(makeMember(userID:)), isApproved: true, pendingMessage: nil)
|
|
}
|
|
|
|
private func makeMember(userID: String) throws -> HealthChatMember {
|
|
try JSONDecoder().decode(HealthChatMember.self, from: Data(#"{ "userId": "\#(userID)" }"#.utf8))
|
|
}
|
|
}
|