2023-06-21 12:10:14 +03:00
|
|
|
//
|
2024-09-06 16:34:30 +03:00
|
|
|
// Copyright 2022-2024 New Vector Ltd.
|
2023-06-21 12:10:14 +03:00
|
|
|
//
|
2025-01-06 11:27:37 +01:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
|
|
|
// Please see LICENSE files in the repository root for full details.
|
2023-06-21 12:10:14 +03:00
|
|
|
//
|
|
|
|
|
|
|
|
import Combine
|
|
|
|
import XCTest
|
|
|
|
|
|
|
|
@testable import ElementX
|
|
|
|
|
|
|
|
@MainActor
|
|
|
|
class MessageForwardingScreenViewModelTests: XCTestCase {
|
2025-02-04 09:50:46 +00:00
|
|
|
let forwardingItem = MessageForwardingItem(id: .event(uniqueID: .init("t1"), eventOrTransactionID: .eventID("t1")),
|
2024-05-07 15:04:11 +01:00
|
|
|
roomID: "1",
|
|
|
|
content: .init(noPointer: .init()))
|
2023-06-21 12:10:14 +03:00
|
|
|
var viewModel: MessageForwardingScreenViewModelProtocol!
|
|
|
|
var context: MessageForwardingScreenViewModelType.Context!
|
|
|
|
var cancellables = Set<AnyCancellable>()
|
|
|
|
|
|
|
|
override func setUpWithError() throws {
|
2023-09-14 12:53:33 +03:00
|
|
|
cancellables.removeAll()
|
2024-05-07 15:04:11 +01:00
|
|
|
|
|
|
|
let clientProxy = ClientProxyMock(.init())
|
2024-08-20 16:13:27 +03:00
|
|
|
clientProxy.roomForIdentifierClosure = { .joined(JoinedRoomProxyMock(.init(id: $0))) }
|
2024-05-07 15:04:11 +01:00
|
|
|
|
|
|
|
viewModel = MessageForwardingScreenViewModel(forwardingItem: forwardingItem,
|
|
|
|
clientProxy: clientProxy,
|
|
|
|
roomSummaryProvider: RoomSummaryProviderMock(.init(state: .loaded(.mockRooms))),
|
|
|
|
userIndicatorController: UserIndicatorControllerMock(),
|
2024-10-02 17:41:08 +01:00
|
|
|
mediaProvider: MediaProviderMock(configuration: .init()))
|
2023-06-21 12:10:14 +03:00
|
|
|
context = viewModel.context
|
|
|
|
}
|
|
|
|
|
|
|
|
func testInitialState() {
|
2024-12-06 16:58:14 +02:00
|
|
|
XCTAssertNil(context.viewState.rooms.first { $0.id == forwardingItem.roomID }, "The source room ID shouldn't be shown")
|
2023-06-21 12:10:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func testRoomSelection() {
|
|
|
|
context.send(viewAction: .selectRoom(roomID: "2"))
|
|
|
|
XCTAssertEqual(context.viewState.selectedRoomID, "2")
|
|
|
|
}
|
|
|
|
|
2023-10-09 14:59:31 +03:00
|
|
|
func testSearching() async throws {
|
|
|
|
let defered = deferFulfillment(context.$viewState) { state in
|
|
|
|
state.rooms.count == 1
|
|
|
|
}
|
|
|
|
|
2023-06-21 12:10:14 +03:00
|
|
|
context.searchQuery = "Second"
|
2023-10-09 14:59:31 +03:00
|
|
|
|
|
|
|
try await defered.fulfill()
|
2023-06-21 12:10:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func testForwarding() {
|
|
|
|
context.send(viewAction: .selectRoom(roomID: "2"))
|
|
|
|
XCTAssertEqual(context.viewState.selectedRoomID, "2")
|
|
|
|
|
|
|
|
let expectation = expectation(description: "Wait for confirmation")
|
|
|
|
|
|
|
|
viewModel.actions
|
|
|
|
.sink { action in
|
|
|
|
switch action {
|
2024-05-07 15:04:11 +01:00
|
|
|
case .sent(let roomID):
|
2023-06-21 12:10:14 +03:00
|
|
|
XCTAssertEqual(roomID, "2")
|
|
|
|
expectation.fulfill()
|
|
|
|
default:
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.store(in: &cancellables)
|
|
|
|
|
|
|
|
context.send(viewAction: .send)
|
|
|
|
|
|
|
|
waitForExpectations(timeout: 5.0)
|
|
|
|
}
|
|
|
|
}
|