mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 21:33:26 +00:00
fixed existing tests and added tests for all the threaded flows
This commit is contained in:
@@ -18,6 +18,10 @@ class RoomFlowCoordinatorTests: XCTestCase {
|
||||
var navigationStackCoordinator: NavigationStackCoordinator!
|
||||
var cancellables = Set<AnyCancellable>()
|
||||
|
||||
override func tearDown() {
|
||||
AppSettings.resetAllSettings()
|
||||
}
|
||||
|
||||
func testRoomPresentation() async throws {
|
||||
setupRoomFlowCoordinator()
|
||||
|
||||
@@ -218,6 +222,87 @@ class RoomFlowCoordinatorTests: XCTestCase {
|
||||
XCTAssert(navigationStackCoordinator.stackCoordinators.first is RoomScreenCoordinator)
|
||||
}
|
||||
|
||||
func testThreadedEventRoutes() async throws {
|
||||
ServiceLocator.shared.settings.threadsEnabled = true
|
||||
setupRoomFlowCoordinator()
|
||||
|
||||
// Navigate directly to the threaded event
|
||||
var configuration = JoinedRoomProxyMockConfiguration(id: "1")
|
||||
var roomProxy = JoinedRoomProxyMock(configuration)
|
||||
|
||||
var roomInfoSubject = CurrentValueSubject<RoomInfoProxyProtocol, Never>(RoomInfoProxyMock(configuration))
|
||||
roomProxy.infoPublisher = roomInfoSubject.asCurrentValuePublisher()
|
||||
|
||||
var mockedEvent = TimelineEventSDKMock()
|
||||
mockedEvent.threadRootEventIdReturnValue = "1"
|
||||
roomProxy.loadOrFetchEventForReturnValue = .success(mockedEvent)
|
||||
|
||||
clientProxy.roomForIdentifierClosure = { _ in
|
||||
.joined(roomProxy)
|
||||
}
|
||||
|
||||
try await process(route: .event(eventID: "2", roomID: "1", via: []))
|
||||
XCTAssert(navigationStackCoordinator.rootCoordinator is RoomScreenCoordinator)
|
||||
XCTAssertEqual(navigationStackCoordinator.stackCoordinators.count, 1)
|
||||
XCTAssert(navigationStackCoordinator.stackCoordinators[0] is ThreadTimelineScreenCoordinator)
|
||||
|
||||
// From the thread screen, navigate to another threaded event in the same room, and in the same thread.
|
||||
let threadCoordinator = navigationStackCoordinator.stackCoordinators[0] as? ThreadTimelineScreenCoordinator
|
||||
try await process(route: .childEvent(eventID: "3", roomID: "1", via: []))
|
||||
XCTAssert(navigationStackCoordinator.rootCoordinator is RoomScreenCoordinator)
|
||||
XCTAssertEqual(navigationStackCoordinator.stackCoordinators.count, 1)
|
||||
XCTAssert(navigationStackCoordinator.stackCoordinators[0] is ThreadTimelineScreenCoordinator)
|
||||
XCTAssertIdentical(navigationStackCoordinator.stackCoordinators[0], threadCoordinator)
|
||||
// Would be nice to test if the focusEvent function has been called but there is no way to mock that.
|
||||
|
||||
// From the thread screen, navigate to another threaded event in the same room, but in a different thread.
|
||||
mockedEvent = TimelineEventSDKMock()
|
||||
mockedEvent.threadRootEventIdReturnValue = "4"
|
||||
roomProxy.loadOrFetchEventForReturnValue = .success(mockedEvent)
|
||||
try await process(route: .childEvent(eventID: "5", roomID: "1", via: []))
|
||||
XCTAssert(navigationStackCoordinator.rootCoordinator is RoomScreenCoordinator)
|
||||
XCTAssertEqual(navigationStackCoordinator.stackCoordinators.count, 2)
|
||||
XCTAssert(navigationStackCoordinator.stackCoordinators[0] is ThreadTimelineScreenCoordinator)
|
||||
XCTAssert(navigationStackCoordinator.stackCoordinators[1] is ThreadTimelineScreenCoordinator)
|
||||
|
||||
// From the thread screen, navigate to another threaded event in a different room.
|
||||
configuration = JoinedRoomProxyMockConfiguration(id: "2")
|
||||
roomProxy = JoinedRoomProxyMock(configuration)
|
||||
|
||||
roomInfoSubject = CurrentValueSubject<RoomInfoProxyProtocol, Never>(RoomInfoProxyMock(configuration))
|
||||
roomProxy.infoPublisher = roomInfoSubject.asCurrentValuePublisher()
|
||||
|
||||
mockedEvent = TimelineEventSDKMock()
|
||||
mockedEvent.threadRootEventIdReturnValue = "1"
|
||||
roomProxy.loadOrFetchEventForReturnValue = .success(mockedEvent)
|
||||
|
||||
clientProxy.roomForIdentifierClosure = { _ in
|
||||
.joined(roomProxy)
|
||||
}
|
||||
|
||||
try await process(route: .childEvent(eventID: "2", roomID: "2", via: []))
|
||||
XCTAssert(navigationStackCoordinator.rootCoordinator is RoomScreenCoordinator)
|
||||
XCTAssertEqual(navigationStackCoordinator.stackCoordinators.count, 4)
|
||||
XCTAssert(navigationStackCoordinator.stackCoordinators[0] is ThreadTimelineScreenCoordinator)
|
||||
XCTAssert(navigationStackCoordinator.stackCoordinators[1] is ThreadTimelineScreenCoordinator)
|
||||
XCTAssert(navigationStackCoordinator.stackCoordinators[2] is RoomScreenCoordinator)
|
||||
XCTAssert(navigationStackCoordinator.stackCoordinators[3] is ThreadTimelineScreenCoordinator)
|
||||
|
||||
// From the thread screen, navigate to an event of the same room that is not threaded
|
||||
mockedEvent = TimelineEventSDKMock()
|
||||
mockedEvent.threadRootEventIdReturnValue = nil
|
||||
roomProxy.loadOrFetchEventForReturnValue = .success(mockedEvent)
|
||||
|
||||
try await process(route: .childEvent(eventID: "3", roomID: "2", via: []))
|
||||
XCTAssert(navigationStackCoordinator.rootCoordinator is RoomScreenCoordinator)
|
||||
XCTAssertEqual(navigationStackCoordinator.stackCoordinators.count, 5)
|
||||
XCTAssert(navigationStackCoordinator.stackCoordinators[0] is ThreadTimelineScreenCoordinator)
|
||||
XCTAssert(navigationStackCoordinator.stackCoordinators[1] is ThreadTimelineScreenCoordinator)
|
||||
XCTAssert(navigationStackCoordinator.stackCoordinators[2] is RoomScreenCoordinator)
|
||||
XCTAssert(navigationStackCoordinator.stackCoordinators[3] is ThreadTimelineScreenCoordinator)
|
||||
XCTAssert(navigationStackCoordinator.stackCoordinators[4] is RoomScreenCoordinator)
|
||||
}
|
||||
|
||||
func testShareMediaRoute() async throws {
|
||||
setupRoomFlowCoordinator()
|
||||
|
||||
@@ -292,7 +377,7 @@ class RoomFlowCoordinatorTests: XCTestCase {
|
||||
|
||||
try await fulfillment.fulfill()
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private func process(route: AppRoute) async throws {
|
||||
|
||||
Reference in New Issue
Block a user