mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 21:33:26 +00:00
Add SpaceRoomCell & Space…ProxyProtocols and use them on the SpaceListScreen. (#4404)
This commit is contained in:
@@ -5,12 +5,16 @@
|
||||
// Please see LICENSE files in the repository root for full details.
|
||||
//
|
||||
|
||||
import Combine
|
||||
import XCTest
|
||||
|
||||
@testable import ElementX
|
||||
|
||||
@MainActor
|
||||
class SpaceListScreenViewModelTests: XCTestCase {
|
||||
var joinedSpacesSubject: CurrentValueSubject<[SpaceRoomProxyProtocol], Never>!
|
||||
var spaceServiceProxy: SpaceServiceProxyMock!
|
||||
|
||||
var viewModel: SpaceListScreenViewModelProtocol!
|
||||
|
||||
var context: SpaceListScreenViewModelType.Context {
|
||||
@@ -19,15 +23,52 @@ class SpaceListScreenViewModelTests: XCTestCase {
|
||||
|
||||
func testInitialState() {
|
||||
setupViewModel()
|
||||
XCTAssertTrue(context.viewState.rooms.isEmpty)
|
||||
XCTAssertEqual(context.viewState.joinedSpaces.count, 3)
|
||||
XCTAssertEqual(context.viewState.joinedRoomsCount, 0)
|
||||
}
|
||||
|
||||
func testJoinedSpacesSubscription() {
|
||||
setupViewModel()
|
||||
|
||||
joinedSpacesSubject.send([])
|
||||
XCTAssertEqual(context.viewState.joinedSpaces.count, 0)
|
||||
|
||||
joinedSpacesSubject.send([
|
||||
SpaceRoomProxyMock(.init(isSpace: true))
|
||||
])
|
||||
XCTAssertEqual(context.viewState.joinedSpaces.count, 1)
|
||||
}
|
||||
|
||||
func testSelectingSpace() async throws {
|
||||
setupViewModel()
|
||||
|
||||
let selectedSpace = joinedSpacesSubject.value[0]
|
||||
let deferred = deferFulfillment(viewModel.actionsPublisher) { _ in true }
|
||||
viewModel.context.send(viewAction: .spaceAction(.select(selectedSpace)))
|
||||
let action = try await deferred.fulfill()
|
||||
|
||||
switch action {
|
||||
case .selectSpace(let spaceRoomProxy) where spaceRoomProxy.id == selectedSpace.id:
|
||||
break
|
||||
default:
|
||||
XCTFail("The action should select the space.")
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Helpers
|
||||
|
||||
private func setupViewModel() {
|
||||
let clientProxy = ClientProxyMock(.init())
|
||||
let userSession = UserSessionMock(.init(clientProxy: clientProxy))
|
||||
viewModel = SpaceListScreenViewModel(userSession: userSession)
|
||||
|
||||
joinedSpacesSubject = .init([
|
||||
SpaceRoomProxyMock(.init(id: "space1", isSpace: true)),
|
||||
SpaceRoomProxyMock(.init(id: "space2", isSpace: true)),
|
||||
SpaceRoomProxyMock(.init(id: "space3", isSpace: true))
|
||||
])
|
||||
spaceServiceProxy = SpaceServiceProxyMock(.init())
|
||||
spaceServiceProxy.joinedSpacesPublisher = joinedSpacesSubject.asCurrentValuePublisher()
|
||||
|
||||
viewModel = SpaceListScreenViewModel(userSession: userSession, spaceServiceProxy: spaceServiceProxy)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user