Files
element-x-ios/UnitTests/Sources/MessageForwardingScreenViewModelTests.swift
T
Stefan Ceriu f040964d3f Allow the user to forward the same message to multiple rooms at once
This will send the item to the rooms in order they were chosen and only deep link
into the target room if single, otherwise it will just dismiss the forwarding screen
after sending.
2026-05-29 14:27:42 +03:00

73 lines
2.5 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
@testable import ElementX
import Testing
@MainActor
struct MessageForwardingScreenViewModelTests {
let forwardingItem = MessageForwardingItem(id: .event(uniqueID: .init("t1"), eventOrTransactionID: .eventID("t1")),
roomID: "1",
content: .init(noHandle: .init()))
var viewModel: MessageForwardingScreenViewModelProtocol!
var context: MessageForwardingScreenViewModelType.Context!
init() {
let clientProxy = ClientProxyMock(.init())
clientProxy.roomForIdentifierClosure = { .joined(JoinedRoomProxyMock(.init(id: $0))) }
viewModel = MessageForwardingScreenViewModel(forwardingItem: forwardingItem,
userSession: UserSessionMock(.init(clientProxy: clientProxy)),
roomSummaryProvider: RoomSummaryProviderMock(.init(state: .loaded(.mockRooms))),
userIndicatorController: UserIndicatorControllerMock())
context = viewModel.context
}
@Test
func initialState() {
#expect(context.viewState.rooms.first { $0.id == forwardingItem.roomID } == nil, "The source room ID shouldn't be shown")
}
@Test
mutating func roomSelection() {
context.send(viewAction: .selectRoom(roomID: "2"))
#expect(context.viewState.selectedRoomIDs == ["2"])
}
@Test
mutating func searching() async throws {
let deferred = deferFulfillment(context.$viewState) { state in
state.rooms.count == 1
}
context.searchQuery = "Second"
try await deferred.fulfill()
}
@Test
mutating func forwarding() async throws {
context.send(viewAction: .selectRoom(roomID: "2"))
#expect(context.viewState.selectedRoomIDs == ["2"])
let deferred = deferFulfillment(viewModel.actions) { action in
switch action {
case .sent(let roomIDs):
return roomIDs == ["2"]
default:
return false
}
}
context.send(viewAction: .send)
try await deferred.fulfill()
}
}