2024-02-28 13:21:54 +02:00
|
|
|
//
|
2024-09-06 16:34:30 +03:00
|
|
|
// Copyright 2022-2024 New Vector Ltd.
|
2024-02-28 13:21:54 +02: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.
|
2024-02-28 13:21:54 +02:00
|
|
|
//
|
|
|
|
|
|
|
|
import Combine
|
|
|
|
import XCTest
|
|
|
|
|
|
|
|
@testable import ElementX
|
|
|
|
|
|
|
|
@MainActor
|
|
|
|
class BlockedUsersScreenViewModelTests: XCTestCase {
|
2024-05-31 13:37:59 +01:00
|
|
|
func testInitialState() async throws {
|
2024-02-27 16:22:47 +02:00
|
|
|
let clientProxy = ClientProxyMock(.init(userID: RoomMemberProxyMock.mockMe.userID))
|
2024-02-28 13:21:54 +02:00
|
|
|
|
2024-05-31 13:37:59 +01:00
|
|
|
let viewModel = BlockedUsersScreenViewModel(hideProfiles: true,
|
|
|
|
clientProxy: clientProxy,
|
2024-10-02 17:41:08 +01:00
|
|
|
mediaProvider: MediaProviderMock(configuration: .init()),
|
2024-02-28 13:21:54 +02:00
|
|
|
userIndicatorController: ServiceLocator.shared.userIndicatorController)
|
|
|
|
|
2024-12-06 16:58:14 +02:00
|
|
|
let deferred = deferFailure(viewModel.context.$viewState, timeout: 1) { $0.blockedUsers.contains { $0.displayName != nil } }
|
2024-05-31 13:37:59 +01:00
|
|
|
try await deferred.fulfill()
|
|
|
|
|
|
|
|
XCTAssertFalse(viewModel.context.viewState.blockedUsers.isEmpty)
|
|
|
|
XCTAssertFalse(clientProxy.profileForCalled)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testProfiles() async throws {
|
|
|
|
let clientProxy = ClientProxyMock(.init(userID: RoomMemberProxyMock.mockMe.userID))
|
|
|
|
|
|
|
|
let viewModel = BlockedUsersScreenViewModel(hideProfiles: false,
|
|
|
|
clientProxy: clientProxy,
|
2024-10-02 17:41:08 +01:00
|
|
|
mediaProvider: MediaProviderMock(configuration: .init()),
|
2024-05-31 13:37:59 +01:00
|
|
|
userIndicatorController: ServiceLocator.shared.userIndicatorController)
|
|
|
|
|
2024-12-06 16:58:14 +02:00
|
|
|
let deferred = deferFulfillment(viewModel.context.$viewState) { $0.blockedUsers.contains { $0.displayName != nil } }
|
2024-05-31 13:37:59 +01:00
|
|
|
try await deferred.fulfill()
|
|
|
|
|
2024-02-28 13:21:54 +02:00
|
|
|
XCTAssertFalse(viewModel.context.viewState.blockedUsers.isEmpty)
|
2024-05-31 13:37:59 +01:00
|
|
|
XCTAssertTrue(clientProxy.profileForCalled)
|
2024-02-28 13:21:54 +02:00
|
|
|
}
|
|
|
|
}
|