Files
letro-ios/UnitTests/Sources/DeclineAndBlockScreenViewModelTests.swift
Mauro 7fcc550a59 Report room and decline & block screens tweaks (#4044)
* report rom and decline and block screens tweaks

- Use the copies: "Leave room" and "Report room" everywhere, also in DMs
- Report reason in report room is now mandatory.
- Report reason in decline and block is now mandatory if the report action is set to on.
- Generic alert for failure of main API in both report room and decline and block has been added

* report room and decline and block screen previews
2025-04-22 10:44:20 +01:00

78 lines
2.9 KiB
Swift

//
// Copyright 2022-2024 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 XCTest
@testable import ElementX
@MainActor
class DeclineAndBlockScreenViewModelTests: XCTestCase {
var viewModel: DeclineAndBlockScreenViewModelProtocol!
var clientProxy: ClientProxyMock!
var context: DeclineAndBlockScreenViewModelType.Context {
viewModel.context
}
override func setUp() {
clientProxy = ClientProxyMock(.init())
viewModel = DeclineAndBlockScreenViewModel(userID: "@alice:matrix.org",
roomID: "!room:matrix.org",
clientProxy: clientProxy,
userIndicatorController: UserIndicatorControllerMock())
}
func testInitialState() {
XCTAssertFalse(context.viewState.isDeclineDisabled)
XCTAssertFalse(context.shouldReport)
XCTAssertTrue(context.shouldBlockUser)
}
func testDeclineDisabled() {
context.shouldBlockUser = false
XCTAssertTrue(context.viewState.isDeclineDisabled)
XCTAssertFalse(context.shouldReport)
XCTAssertFalse(context.shouldBlockUser)
context.shouldReport = true
// Should report set to `true` always requires a non empty reason
XCTAssertTrue(context.viewState.isDeclineDisabled)
context.reportReason = "Test reason"
XCTAssertFalse(context.viewState.isDeclineDisabled)
}
func testDeclineBlockAndReport() async throws {
let reason = "Test reason"
clientProxy.roomForIdentifierClosure = { id in
XCTAssertEqual(id, "!room:matrix.org")
let roomProxyMock = InvitedRoomProxyMock(.init(id: id))
roomProxyMock.rejectInvitationReturnValue = .success(())
return .invited(InvitedRoomProxyMock(.init(id: id)))
}
clientProxy.reportRoomForIdentifierReasonClosure = { id, reasonValue in
XCTAssertEqual(id, "!room:matrix.org")
XCTAssertEqual(reasonValue, reason)
return .success(())
}
clientProxy.ignoreUserClosure = { userId in
XCTAssertEqual(userId, "@alice:matrix.org")
return .success(())
}
context.shouldReport = true
context.reportReason = reason
let deferredAction = deferFulfillment(viewModel.actionsPublisher) { action in
action == .dismiss(hasDeclined: true)
}
context.send(viewAction: .decline)
try await deferredAction.fulfill()
XCTAssertTrue(clientProxy.roomForIdentifierCalled)
XCTAssertTrue(clientProxy.reportRoomForIdentifierReasonCalled)
XCTAssertTrue(clientProxy.ignoreUserCalled)
}
}