mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 12:07:55 +00:00
Switch callbacks to combine (#1710)
* #750 - Convert the SoftLogoutScreen to combine * #750 - Convert the UserSessionFlowCoordinator to Combine * #750 - Convert the AnalyticsPromptScreen to Combine * #750 - Convert the LoginScreen to Combine * #750 - Convert the ServerSelectionScreen to Combine * #750 - Convert the EmojiPickerScreen to Combine * #750 - Convert the HomeScreen to Combine * #750 - Convert the MediaUploadPreviewScreen to Combine * #750 - Convert the OnboardingScreen to Combine * Rename `Onboarding` to `OnboardingScreen` * #750 - Convert the ReportContentScreen to Combine * #750 - Convert the RoomDetailsSscreen to Combine * #750 - Convert the RoomMemberDetailsScreen to Combine * #750 - Convert the RoomMembersListScreen to Combine * #750 - Convert the SessionVerificationScreen to Combine * #750 - Convert the SettingsScreen to Combine * #750 - Convert the AdvancedSettingsScreen to Combine * #750 - Convert the DeveloperOptionsScreen to Combine * Fix the unit tests * Use .sink action and the same cancellables constructor everywhere * Cleanup cancellables when setting up tests
This commit is contained in:
@@ -23,12 +23,11 @@ import XCTest
|
||||
class HomeScreenViewModelTests: XCTestCase {
|
||||
var viewModel: HomeScreenViewModelProtocol!
|
||||
var clientProxy: MockClientProxy!
|
||||
|
||||
var context: HomeScreenViewModelType.Context! {
|
||||
viewModel.context
|
||||
}
|
||||
var context: HomeScreenViewModelType.Context! { viewModel.context }
|
||||
var cancellables = Set<AnyCancellable>()
|
||||
|
||||
override func setUpWithError() throws {
|
||||
cancellables.removeAll()
|
||||
clientProxy = MockClientProxy(userID: "@mock:client.com")
|
||||
viewModel = HomeScreenViewModel(userSession: MockUserSession(clientProxy: clientProxy,
|
||||
mediaProvider: MockMediaProvider()),
|
||||
@@ -43,16 +42,19 @@ class HomeScreenViewModelTests: XCTestCase {
|
||||
let mockRoomId = "mock_room_id"
|
||||
var correctResult = false
|
||||
var selectedRoomId = ""
|
||||
viewModel.callback = { result in
|
||||
switch result {
|
||||
case .presentRoom(let roomId):
|
||||
correctResult = true
|
||||
selectedRoomId = roomId
|
||||
default:
|
||||
break
|
||||
|
||||
viewModel.actions
|
||||
.sink { action in
|
||||
switch action {
|
||||
case .presentRoom(let roomId):
|
||||
correctResult = true
|
||||
selectedRoomId = roomId
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.store(in: &cancellables)
|
||||
|
||||
context.send(viewAction: .selectRoom(roomIdentifier: mockRoomId))
|
||||
await Task.yield()
|
||||
XCTAssert(correctResult)
|
||||
@@ -61,15 +63,18 @@ class HomeScreenViewModelTests: XCTestCase {
|
||||
|
||||
func testTapUserAvatar() async throws {
|
||||
var correctResult = false
|
||||
viewModel.callback = { result in
|
||||
switch result {
|
||||
case .presentSettingsScreen:
|
||||
correctResult = true
|
||||
default:
|
||||
break
|
||||
|
||||
viewModel.actions
|
||||
.sink { action in
|
||||
switch action {
|
||||
case .presentSettingsScreen:
|
||||
correctResult = true
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.store(in: &cancellables)
|
||||
|
||||
context.send(viewAction: .userMenu(action: .settings))
|
||||
await Task.yield()
|
||||
XCTAssert(correctResult)
|
||||
@@ -97,15 +102,17 @@ class HomeScreenViewModelTests: XCTestCase {
|
||||
let mockRoomId = "1"
|
||||
var correctResult = false
|
||||
let expectation = expectation(description: #function)
|
||||
viewModel.callback = { result in
|
||||
switch result {
|
||||
case .roomLeft(let roomIdentifier):
|
||||
correctResult = roomIdentifier == mockRoomId
|
||||
default:
|
||||
break
|
||||
viewModel.actions
|
||||
.sink { action in
|
||||
switch action {
|
||||
case .roomLeft(let roomIdentifier):
|
||||
correctResult = roomIdentifier == mockRoomId
|
||||
default:
|
||||
break
|
||||
}
|
||||
expectation.fulfill()
|
||||
}
|
||||
expectation.fulfill()
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
let room: RoomProxyMock = .init(with: .init(id: mockRoomId, displayName: "Some room"))
|
||||
room.leaveRoomClosure = { .success(()) }
|
||||
clientProxy.roomForIdentifierMocks[mockRoomId] = room
|
||||
@@ -118,14 +125,16 @@ class HomeScreenViewModelTests: XCTestCase {
|
||||
func testShowRoomDetails() async throws {
|
||||
let mockRoomId = "1"
|
||||
var correctResult = false
|
||||
viewModel.callback = { result in
|
||||
switch result {
|
||||
case .presentRoomDetails(let roomIdentifier):
|
||||
correctResult = roomIdentifier == mockRoomId
|
||||
default:
|
||||
break
|
||||
viewModel.actions
|
||||
.sink { action in
|
||||
switch action {
|
||||
case .presentRoomDetails(let roomIdentifier):
|
||||
correctResult = roomIdentifier == mockRoomId
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
context.send(viewAction: .showRoomDetails(roomIdentifier: mockRoomId))
|
||||
await Task.yield()
|
||||
XCTAssertNil(context.alertInfo)
|
||||
|
||||
Reference in New Issue
Block a user