mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 12:07:55 +00:00
0082aba9d4
Squashed commits: Add unit tests and move the state machine into the FlowCoordinator [bb686861] Replace the RoomFlowCoordinator's public interface with just `handleAppRoute` [0d9a4f8d] Remove the navigationStackCoordinator dependency from the roomScreenCoordinator [4b5fbdf2] Allow rooms to be selected from any other state [41dbd127] Move all missing coordinators to the RoomFlowCoordinator and state machines [f32431b7] The UserSessionFlowCoordinator does not need to conform to the CoordinatorProtocol [0f07e87d] Fix leaving a room dismissing the currently selected one when different [138385a2] Rewind the navigation stack when re-selecting the same room (iPad) [0727eb93] Fix presenting different room details from the side menu on iPads [faf4cc60] Fix selecting the same room multiple times [fb3391da] Move room details presentation responsibility to the RoomFlowCoordinator. Fixed invitation flows. [fa2a68d9] Rename RoomTimelineFlowCoordinator -> RoomFlowCoordinator [0c9c06b5] Start moving things away from the RoomScreenCoordinator and into the RoomTimelineFlowCoordinator [86cbbdcc] Introduce a RoomTimelineFlowCoordinator to deal with timeline related operations [9b2381be] Introduce the FlowCoordinatorProtocol
88 lines
4.3 KiB
Swift
88 lines
4.3 KiB
Swift
//
|
|
// Copyright 2023 New Vector Ltd
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
//
|
|
|
|
import XCTest
|
|
|
|
import Combine
|
|
@testable import ElementX
|
|
|
|
@MainActor
|
|
class RoomFlowCoordinatorTests: XCTestCase {
|
|
var roomFlowCoordinator: RoomFlowCoordinator!
|
|
var navigationStackCoordinator: NavigationStackCoordinator!
|
|
private var cancellables: Set<AnyCancellable> = .init()
|
|
|
|
override func setUp() async throws {
|
|
let clientProxy = MockClientProxy(userID: "hi@bob", roomSummaryProvider: MockRoomSummaryProvider(state: .loaded(.mockRooms)))
|
|
let mediaProvider = MockMediaProvider()
|
|
let userSession = MockUserSession(clientProxy: clientProxy, mediaProvider: mediaProvider)
|
|
|
|
let navigationSplitCoordinator = NavigationSplitCoordinator(placeholderCoordinator: SplashScreenCoordinator())
|
|
navigationStackCoordinator = NavigationStackCoordinator()
|
|
navigationSplitCoordinator.setDetailCoordinator(navigationStackCoordinator)
|
|
|
|
roomFlowCoordinator = RoomFlowCoordinator(userSession: userSession,
|
|
roomTimelineControllerFactory: MockRoomTimelineControllerFactory(),
|
|
navigationStackCoordinator: navigationStackCoordinator,
|
|
navigationSplitCoordinator: navigationSplitCoordinator,
|
|
emojiProvider: EmojiProvider())
|
|
}
|
|
|
|
func testRoomPresentation() async {
|
|
await process(route: .room(roomID: "1"), expectedAction: .presentedRoom("1"))
|
|
XCTAssert(navigationStackCoordinator.rootCoordinator is RoomScreenCoordinator)
|
|
|
|
await process(route: .roomList, expectedAction: .dismissedRoom)
|
|
XCTAssertNil(navigationStackCoordinator.rootCoordinator)
|
|
|
|
await process(route: .room(roomID: "1"), expectedAction: .presentedRoom("1"))
|
|
XCTAssert(navigationStackCoordinator.rootCoordinator is RoomScreenCoordinator)
|
|
|
|
await process(route: .room(roomID: "2"), expectedAction: .presentedRoom("2"))
|
|
XCTAssert(navigationStackCoordinator.rootCoordinator is RoomScreenCoordinator)
|
|
|
|
await process(route: .roomList, expectedAction: .dismissedRoom)
|
|
XCTAssertNil(navigationStackCoordinator.rootCoordinator)
|
|
}
|
|
|
|
func testRoomDetailsPresentation() async {
|
|
await process(route: .roomDetails(roomID: "1"), expectedAction: .presentedRoom("1"))
|
|
XCTAssert(navigationStackCoordinator.rootCoordinator is RoomScreenCoordinator)
|
|
XCTAssertEqual(navigationStackCoordinator.stackCoordinators.count, 1)
|
|
XCTAssert(navigationStackCoordinator.stackCoordinators.first is RoomDetailsScreenCoordinator)
|
|
|
|
await process(route: .roomList, expectedAction: .dismissedRoom)
|
|
XCTAssertNil(navigationStackCoordinator.rootCoordinator)
|
|
}
|
|
|
|
func testStackUnwinding() async {
|
|
await process(route: .roomDetails(roomID: "1"), expectedAction: .presentedRoom("1"))
|
|
XCTAssert(navigationStackCoordinator.rootCoordinator is RoomScreenCoordinator)
|
|
XCTAssertEqual(navigationStackCoordinator.stackCoordinators.count, 1)
|
|
XCTAssert(navigationStackCoordinator.stackCoordinators.first is RoomDetailsScreenCoordinator)
|
|
|
|
await process(route: .room(roomID: "2"), expectedAction: .presentedRoom("2"))
|
|
XCTAssert(navigationStackCoordinator.rootCoordinator is RoomScreenCoordinator)
|
|
}
|
|
|
|
// MARK: - Private
|
|
|
|
func process(route: AppRoute, expectedAction: RoomFlowCoordinatorAction) async {
|
|
Task { try? await Task.sleep(for: .seconds(0.1)); roomFlowCoordinator.handleAppRoute(route, animated: true) }
|
|
_ = await roomFlowCoordinator.actions.values.first(where: { $0 == expectedAction })
|
|
}
|
|
}
|