mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
Replace individual RoomProxy properties with a stored RoomInfo. (#3445)
* Store RoomInfo updates in JoinedRoomProxy and read from them directly. * Remove all RoomProxy properties that were reading from the RoomInfo.
This commit is contained in:
@@ -24,15 +24,16 @@ class RoomScreenViewModelTests: XCTestCase {
|
||||
}
|
||||
|
||||
func testPinnedEventsBanner() async throws {
|
||||
var configuration = JoinedRoomProxyMockConfiguration()
|
||||
let timelineSubject = PassthroughSubject<TimelineProxyProtocol, Never>()
|
||||
let updateSubject = PassthroughSubject<JoinedRoomProxyAction, Never>()
|
||||
let roomProxyMock = JoinedRoomProxyMock(.init())
|
||||
let infoSubject = CurrentValueSubject<RoomInfoProxy, Never>(.init(roomInfo: RoomInfo(configuration)))
|
||||
let roomProxyMock = JoinedRoomProxyMock(configuration)
|
||||
// setup a way to inject the mock of the pinned events timeline
|
||||
roomProxyMock.pinnedEventsTimelineClosure = {
|
||||
await timelineSubject.values.first()
|
||||
}
|
||||
// setup the room proxy actions publisher
|
||||
roomProxyMock.underlyingActionsPublisher = updateSubject.eraseToAnyPublisher()
|
||||
roomProxyMock.underlyingInfoPublisher = infoSubject.asCurrentValuePublisher()
|
||||
let viewModel = RoomScreenViewModel(clientProxy: ClientProxyMock(),
|
||||
roomProxy: roomProxyMock,
|
||||
initialSelectedPinnedEventID: nil,
|
||||
@@ -56,8 +57,8 @@ class RoomScreenViewModelTests: XCTestCase {
|
||||
deferred = deferFulfillment(viewModel.context.$viewState) { viewState in
|
||||
viewState.pinnedEventsBannerState.count == 2
|
||||
}
|
||||
roomProxyMock.underlyingPinnedEventIDs = ["test1", "test2"]
|
||||
updateSubject.send(.roomInfoUpdate)
|
||||
configuration.pinnedEventIDs = ["test1", "test2"]
|
||||
infoSubject.send(.init(roomInfo: RoomInfo(configuration)))
|
||||
try await deferred.fulfill()
|
||||
XCTAssertTrue(viewModel.context.viewState.pinnedEventsBannerState.isLoading)
|
||||
XCTAssertTrue(viewModel.context.viewState.shouldShowPinnedEventsBanner)
|
||||
@@ -157,11 +158,12 @@ class RoomScreenViewModelTests: XCTestCase {
|
||||
}
|
||||
|
||||
func testRoomInfoUpdate() async throws {
|
||||
let updateSubject = PassthroughSubject<JoinedRoomProxyAction, Never>()
|
||||
let roomProxyMock = JoinedRoomProxyMock(.init(id: "TestID", name: "StartingName", avatarURL: nil, hasOngoingCall: false))
|
||||
var configuration = JoinedRoomProxyMockConfiguration(id: "TestID", name: "StartingName", avatarURL: nil, hasOngoingCall: false)
|
||||
let infoSubject = CurrentValueSubject<RoomInfoProxy, Never>(.init(roomInfo: RoomInfo(configuration)))
|
||||
let roomProxyMock = JoinedRoomProxyMock(configuration)
|
||||
// setup the room proxy actions publisher
|
||||
roomProxyMock.canUserJoinCallUserIDReturnValue = .success(false)
|
||||
roomProxyMock.underlyingActionsPublisher = updateSubject.eraseToAnyPublisher()
|
||||
roomProxyMock.underlyingInfoPublisher = infoSubject.asCurrentValuePublisher()
|
||||
let viewModel = RoomScreenViewModel(clientProxy: ClientProxyMock(),
|
||||
roomProxy: roomProxyMock,
|
||||
initialSelectedPinnedEventID: nil,
|
||||
@@ -181,9 +183,9 @@ class RoomScreenViewModelTests: XCTestCase {
|
||||
}
|
||||
try await deferred.fulfill()
|
||||
|
||||
roomProxyMock.name = "NewName"
|
||||
roomProxyMock.avatar = .room(id: "TestID", name: "NewName", avatarURL: .documentsDirectory)
|
||||
roomProxyMock.hasOngoingCall = true
|
||||
configuration.name = "NewName"
|
||||
configuration.avatarURL = .documentsDirectory
|
||||
configuration.hasOngoingCall = true
|
||||
roomProxyMock.canUserJoinCallUserIDReturnValue = .success(true)
|
||||
|
||||
deferred = deferFulfillment(viewModel.context.$viewState) { viewState in
|
||||
@@ -193,7 +195,7 @@ class RoomScreenViewModelTests: XCTestCase {
|
||||
viewState.hasOngoingCall
|
||||
}
|
||||
|
||||
updateSubject.send(.roomInfoUpdate)
|
||||
infoSubject.send(.init(roomInfo: RoomInfo(configuration)))
|
||||
try await deferred.fulfill()
|
||||
}
|
||||
|
||||
|
||||
@@ -349,10 +349,11 @@ class TimelineViewModelTests: XCTestCase {
|
||||
// MARK: - Pins
|
||||
|
||||
func testPinnedEvents() async throws {
|
||||
let roomProxyMock = JoinedRoomProxyMock(.init(name: "",
|
||||
pinnedEventIDs: .init(["test1"])))
|
||||
let actionsSubject = PassthroughSubject<JoinedRoomProxyAction, Never>()
|
||||
roomProxyMock.underlyingActionsPublisher = actionsSubject.eraseToAnyPublisher()
|
||||
var configuration = JoinedRoomProxyMockConfiguration(name: "",
|
||||
pinnedEventIDs: .init(["test1"]))
|
||||
let roomProxyMock = JoinedRoomProxyMock(configuration)
|
||||
let infoSubject = CurrentValueSubject<RoomInfoProxy, Never>(.init(roomInfo: RoomInfo(configuration)))
|
||||
roomProxyMock.underlyingInfoPublisher = infoSubject.asCurrentValuePublisher()
|
||||
|
||||
let viewModel = TimelineViewModel(roomProxy: roomProxyMock,
|
||||
timelineController: MockRoomTimelineController(),
|
||||
@@ -364,24 +365,21 @@ class TimelineViewModelTests: XCTestCase {
|
||||
appSettings: ServiceLocator.shared.settings,
|
||||
analyticsService: ServiceLocator.shared.analytics,
|
||||
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings))
|
||||
XCTAssertEqual(configuration.pinnedEventIDs, viewModel.context.viewState.pinnedEventIDs)
|
||||
|
||||
var deferred = deferFulfillment(viewModel.context.$viewState) { value in
|
||||
value.pinnedEventIDs == ["test1"]
|
||||
}
|
||||
try await deferred.fulfill()
|
||||
|
||||
roomProxyMock.underlyingPinnedEventIDs = ["test1", "test2"]
|
||||
deferred = deferFulfillment(viewModel.context.$viewState) { value in
|
||||
configuration.pinnedEventIDs = ["test1", "test2"]
|
||||
let deferred = deferFulfillment(viewModel.context.$viewState) { value in
|
||||
value.pinnedEventIDs == ["test1", "test2"]
|
||||
}
|
||||
actionsSubject.send(.roomInfoUpdate)
|
||||
infoSubject.send(.init(roomInfo: RoomInfo(configuration)))
|
||||
try await deferred.fulfill()
|
||||
}
|
||||
|
||||
func testCanUserPinEvents() async throws {
|
||||
let roomProxyMock = JoinedRoomProxyMock(.init(name: "", canUserPin: true))
|
||||
let actionsSubject = PassthroughSubject<JoinedRoomProxyAction, Never>()
|
||||
roomProxyMock.underlyingActionsPublisher = actionsSubject.eraseToAnyPublisher()
|
||||
let configuration = JoinedRoomProxyMockConfiguration(name: "", canUserPin: true)
|
||||
let roomProxyMock = JoinedRoomProxyMock(configuration)
|
||||
let infoSubject = CurrentValueSubject<RoomInfoProxy, Never>(.init(roomInfo: RoomInfo(configuration)))
|
||||
roomProxyMock.underlyingInfoPublisher = infoSubject.asCurrentValuePublisher()
|
||||
|
||||
let viewModel = TimelineViewModel(roomProxy: roomProxyMock,
|
||||
timelineController: MockRoomTimelineController(),
|
||||
@@ -403,7 +401,7 @@ class TimelineViewModelTests: XCTestCase {
|
||||
deferred = deferFulfillment(viewModel.context.$viewState) { value in
|
||||
!value.canCurrentUserPin
|
||||
}
|
||||
actionsSubject.send(.roomInfoUpdate)
|
||||
infoSubject.send(.init(roomInfo: RoomInfo(configuration)))
|
||||
try await deferred.fulfill()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user