mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:55:59 +00:00
pr suggestions and implemented a simpler way to clear the route, that always brings back to the initial coordinator
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
//
|
||||
// Copyright 2025 Element Creations Ltd.
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
// Please see LICENSE files in the repository root for full details.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
|
||||
import Combine
|
||||
@testable import ElementX
|
||||
|
||||
@MainActor
|
||||
class RoomMembersFlowCoordinatorTests: XCTestCase {
|
||||
var membersFlowCoordinator: RoomMembersFlowCoordinator!
|
||||
var navigationStackCoordinator: NavigationStackCoordinator!
|
||||
let stateMachineFactory = PublishedStateMachineFactory()
|
||||
|
||||
func testClearRoute() async throws {
|
||||
try await setUp(entryPoint: .roomMembersList)
|
||||
XCTAssertTrue(navigationStackCoordinator.stackCoordinators.last is RoomMembersListScreenCoordinator)
|
||||
|
||||
var deferred = deferFulfillment(stateMachineFactory.membersFlowStatePublisher) { $0 == .roomMemberDetails(userID: "test", previousState: .roomMembersList) }
|
||||
membersFlowCoordinator.handleAppRoute(.roomMemberDetails(userID: "test"), animated: false)
|
||||
try await deferred.fulfill()
|
||||
XCTAssertTrue(navigationStackCoordinator.stackCoordinators.last is RoomMemberDetailsScreenCoordinator)
|
||||
|
||||
deferred = deferFulfillment(stateMachineFactory.membersFlowStatePublisher) { $0 == .roomMembersList }
|
||||
let deferredAction = deferFulfillment(membersFlowCoordinator.actions) { action in
|
||||
switch action {
|
||||
case .finished:
|
||||
true
|
||||
default:
|
||||
false
|
||||
}
|
||||
}
|
||||
membersFlowCoordinator.clearRoute(animated: false)
|
||||
try await deferred.fulfill()
|
||||
try await deferredAction.fulfill()
|
||||
XCTAssertTrue(navigationStackCoordinator.stackCoordinators.last is BlankFormCoordinator)
|
||||
}
|
||||
|
||||
private func setUp(entryPoint: RoomMembersFlowCoordinatorEntryPoint) async throws {
|
||||
navigationStackCoordinator = NavigationStackCoordinator()
|
||||
navigationStackCoordinator.setRootCoordinator(PlaceholderScreenCoordinator(hideBrandChrome: false))
|
||||
navigationStackCoordinator.push(BlankFormCoordinator())
|
||||
|
||||
let flowParameters = CommonFlowParameters(userSession: UserSessionMock(.init()),
|
||||
bugReportService: BugReportServiceMock(.init()),
|
||||
elementCallService: ElementCallServiceMock(.init()),
|
||||
timelineControllerFactory: TimelineControllerFactoryMock(.init()),
|
||||
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings),
|
||||
linkMetadataProvider: LinkMetadataProvider(),
|
||||
appMediator: AppMediatorMock.default,
|
||||
appSettings: ServiceLocator.shared.settings,
|
||||
appHooks: AppHooks(),
|
||||
analytics: ServiceLocator.shared.analytics,
|
||||
userIndicatorController: UserIndicatorControllerMock(),
|
||||
notificationManager: NotificationManagerMock(),
|
||||
stateMachineFactory: stateMachineFactory)
|
||||
|
||||
let roomProxy = JoinedRoomProxyMock(.init())
|
||||
membersFlowCoordinator = RoomMembersFlowCoordinator(entryPoint: entryPoint,
|
||||
roomProxy: roomProxy,
|
||||
navigationStackCoordinator: navigationStackCoordinator,
|
||||
flowParameters: flowParameters)
|
||||
|
||||
let deferred = deferFulfillment(stateMachineFactory.membersFlowStatePublisher) { state in
|
||||
switch entryPoint {
|
||||
case .roomMember(let userID):
|
||||
state == .roomMemberDetails(userID: userID, previousState: .initial)
|
||||
case .roomMembersList:
|
||||
state == .roomMembersList
|
||||
}
|
||||
}
|
||||
|
||||
membersFlowCoordinator.start()
|
||||
try await deferred.fulfill()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user