* Present members of a space * present the members modally from the space * Implemented a room members flow coordinator to make such flow more modular and reusable this is required since we will need to reuse this module also in the space settings, and later we could also replace it in the RoomFlowCoordinator. * the implementation to support at least the SpaceFlowCoordinator is done a follow UP should do the refactor. * remove modal usage from the flow, we want to always be a navigation flow * Improved and implemented the room navigation in the members flow coordinator * pr suggestions and refactored the start chat flow and the invite screen * updated copies for managing room members * Update ElementX/Sources/Screens/Spaces/SpaceScreen/SpaceScreenViewModel.swift Co-authored-by: Doug <6060466+pixlwave@users.noreply.github.com> --------- Co-authored-by: Doug <6060466+pixlwave@users.noreply.github.com>
93 lines
3.8 KiB
Swift
93 lines
3.8 KiB
Swift
//
|
|
// Copyright 2025 Element Creations Ltd.
|
|
// Copyright 2022-2025 New Vector Ltd.
|
|
//
|
|
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
|
// Please see LICENSE files in the repository root for full details.
|
|
//
|
|
|
|
import Combine
|
|
import XCTest
|
|
|
|
@testable import ElementX
|
|
|
|
@MainActor
|
|
class InviteUsersScreenViewModelTests: XCTestCase {
|
|
var viewModel: InviteUsersScreenViewModelProtocol!
|
|
var userDiscoveryService: UserDiscoveryServiceMock!
|
|
|
|
var context: InviteUsersScreenViewModel.Context {
|
|
viewModel.context
|
|
}
|
|
|
|
func testSelectUser() {
|
|
setupWithRoomType(roomType: .draft)
|
|
XCTAssertTrue(context.viewState.selectedUsers.isEmpty)
|
|
context.send(viewAction: .toggleUser(.mockAlice))
|
|
XCTAssertTrue(context.viewState.selectedUsers.count == 1)
|
|
XCTAssertEqual(context.viewState.selectedUsers.first?.userID, UserProfileProxy.mockAlice.userID)
|
|
}
|
|
|
|
func testReselectUser() {
|
|
setupWithRoomType(roomType: .draft)
|
|
XCTAssertTrue(context.viewState.selectedUsers.isEmpty)
|
|
context.send(viewAction: .toggleUser(.mockAlice))
|
|
XCTAssertEqual(context.viewState.selectedUsers.count, 1)
|
|
XCTAssertEqual(context.viewState.selectedUsers.first?.userID, UserProfileProxy.mockAlice.userID)
|
|
context.send(viewAction: .toggleUser(.mockAlice))
|
|
XCTAssertTrue(context.viewState.selectedUsers.isEmpty)
|
|
}
|
|
|
|
func testDeselectUser() {
|
|
setupWithRoomType(roomType: .draft)
|
|
XCTAssertTrue(context.viewState.selectedUsers.isEmpty)
|
|
context.send(viewAction: .toggleUser(.mockAlice))
|
|
XCTAssertEqual(context.viewState.selectedUsers.count, 1)
|
|
XCTAssertEqual(context.viewState.selectedUsers.first?.userID, UserProfileProxy.mockAlice.userID)
|
|
context.send(viewAction: .toggleUser(.mockAlice))
|
|
XCTAssertTrue(context.viewState.selectedUsers.isEmpty)
|
|
}
|
|
|
|
func testInviteButton() async throws {
|
|
let mockedMembers: [RoomMemberProxyMock] = [.mockAlice, .mockBob]
|
|
let roomProxy = JoinedRoomProxyMock(.init(name: "test", members: mockedMembers))
|
|
roomProxy.inviteUserIDReturnValue = .success(())
|
|
setupWithRoomType(roomType: .room(roomProxy: roomProxy))
|
|
|
|
let deferredState = deferFulfillment(viewModel.context.$viewState) { state in
|
|
state.isUserSelected(.mockAlice)
|
|
}
|
|
|
|
context.send(viewAction: .toggleUser(.mockAlice))
|
|
|
|
try await deferredState.fulfill()
|
|
|
|
let deferredAction = deferFulfillment(viewModel.actions) { action in
|
|
switch action {
|
|
case .dismiss:
|
|
return true
|
|
default:
|
|
return false
|
|
}
|
|
}
|
|
|
|
context.send(viewAction: .proceed)
|
|
|
|
try await deferredAction.fulfill()
|
|
XCTAssertEqual(roomProxy.inviteUserIDReceivedInvocations, [RoomMemberProxyMock.mockAlice.userID])
|
|
}
|
|
|
|
private func setupWithRoomType(roomType: InviteUsersScreenRoomType) {
|
|
userDiscoveryService = UserDiscoveryServiceMock()
|
|
userDiscoveryService.searchProfilesWithReturnValue = .success([])
|
|
let viewModel = InviteUsersScreenViewModel(userSession: UserSessionMock(.init()),
|
|
selectedUsers: nil,
|
|
roomType: roomType,
|
|
userDiscoveryService: userDiscoveryService,
|
|
userIndicatorController: UserIndicatorControllerMock(),
|
|
appSettings: ServiceLocator.shared.settings)
|
|
viewModel.state.usersSection = .init(type: .suggestions, users: [.mockAlice, .mockBob, .mockCharlie])
|
|
self.viewModel = viewModel
|
|
}
|
|
}
|