Add SpaceRoomCell & Space…ProxyProtocols and use them on the SpaceListScreen. (#4404)

This commit is contained in:
Doug
2025-08-13 12:06:29 +01:00
committed by GitHub
parent 192f4765c3
commit 3dc6d73899
32 changed files with 781 additions and 39 deletions
@@ -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)
}
}