Handle external links to a user. (#2690)

This commit is contained in:
Doug
2024-04-15 11:08:00 +01:00
committed by GitHub
parent e0138eeb35
commit e7af7fb59c
22 changed files with 450 additions and 154 deletions
+25 -1
View File
@@ -118,7 +118,7 @@ class AppRouteURLParserTests: XCTestCase {
let route = appRouteURLParser.route(from: url)
XCTAssertEqual(route, .roomMemberDetails(userID: userID))
XCTAssertEqual(route, .userProfile(userID: userID))
}
func testMatrixRoomIdentifierURL() {
@@ -132,4 +132,28 @@ class AppRouteURLParserTests: XCTestCase {
XCTAssertEqual(route, .room(roomID: id))
}
func testWebRoomIDURL() {
let id = "!abcdefghijklmnopqrstuvwxyz1234567890:matrix.org"
guard let url = URL(string: "https://app.element.io/#/room/\(id)") else {
XCTFail("URL invalid")
return
}
let route = appRouteURLParser.route(from: url)
XCTAssertEqual(route, .room(roomID: id))
}
func testWebUserIDURL() {
let id = "@alice:matrix.org"
guard let url = URL(string: "https://develop.element.io/#/user/\(id)") else {
XCTFail("URL invalid")
return
}
let route = appRouteURLParser.route(from: url)
XCTAssertEqual(route, .userProfile(userID: id))
}
}
@@ -39,7 +39,8 @@ class RoomMemberDetailsViewModelTests: XCTestCase {
roomProxy: roomProxyMock,
clientProxy: ClientProxyMock(.init()),
mediaProvider: MockMediaProvider(),
userIndicatorController: ServiceLocator.shared.userIndicatorController)
userIndicatorController: ServiceLocator.shared.userIndicatorController,
analytics: ServiceLocator.shared.analytics)
let waitForMemberToLoad = deferFulfillment(context.$viewState) { $0.memberDetails != nil }
try await waitForMemberToLoad.fulfill()
@@ -55,7 +56,8 @@ class RoomMemberDetailsViewModelTests: XCTestCase {
roomProxy: roomProxyMock,
clientProxy: ClientProxyMock(.init()),
mediaProvider: MockMediaProvider(),
userIndicatorController: ServiceLocator.shared.userIndicatorController)
userIndicatorController: ServiceLocator.shared.userIndicatorController,
analytics: ServiceLocator.shared.analytics)
let waitForMemberToLoad = deferFulfillment(context.$viewState) { $0.memberDetails != nil }
try await waitForMemberToLoad.fulfill()
@@ -92,7 +94,8 @@ class RoomMemberDetailsViewModelTests: XCTestCase {
roomProxy: roomProxyMock,
clientProxy: clientProxy,
mediaProvider: MockMediaProvider(),
userIndicatorController: ServiceLocator.shared.userIndicatorController)
userIndicatorController: ServiceLocator.shared.userIndicatorController,
analytics: ServiceLocator.shared.analytics)
let waitForMemberToLoad = deferFulfillment(context.$viewState) { $0.memberDetails != nil }
try await waitForMemberToLoad.fulfill()
@@ -128,7 +131,8 @@ class RoomMemberDetailsViewModelTests: XCTestCase {
roomProxy: roomProxyMock,
clientProxy: ClientProxyMock(.init()),
mediaProvider: MockMediaProvider(),
userIndicatorController: ServiceLocator.shared.userIndicatorController)
userIndicatorController: ServiceLocator.shared.userIndicatorController,
analytics: ServiceLocator.shared.analytics)
let waitForMemberToLoad = deferFulfillment(context.$viewState) { $0.memberDetails != nil }
try await waitForMemberToLoad.fulfill()
@@ -163,7 +167,8 @@ class RoomMemberDetailsViewModelTests: XCTestCase {
roomProxy: roomProxyMock,
clientProxy: clientProxy,
mediaProvider: MockMediaProvider(),
userIndicatorController: ServiceLocator.shared.userIndicatorController)
userIndicatorController: ServiceLocator.shared.userIndicatorController,
analytics: ServiceLocator.shared.analytics)
let waitForMemberToLoad = deferFulfillment(context.$viewState) { $0.memberDetails != nil }
try await waitForMemberToLoad.fulfill()
@@ -198,7 +203,8 @@ class RoomMemberDetailsViewModelTests: XCTestCase {
roomProxy: roomProxyMock,
clientProxy: ClientProxyMock(.init()),
mediaProvider: MockMediaProvider(),
userIndicatorController: ServiceLocator.shared.userIndicatorController)
userIndicatorController: ServiceLocator.shared.userIndicatorController,
analytics: ServiceLocator.shared.analytics)
let waitForMemberToLoad = deferFulfillment(context.$viewState) { $0.memberDetails != nil }
try await waitForMemberToLoad.fulfill()
@@ -214,7 +220,8 @@ class RoomMemberDetailsViewModelTests: XCTestCase {
roomProxy: roomProxyMock,
clientProxy: ClientProxyMock(.init()),
mediaProvider: MockMediaProvider(),
userIndicatorController: ServiceLocator.shared.userIndicatorController)
userIndicatorController: ServiceLocator.shared.userIndicatorController,
analytics: ServiceLocator.shared.analytics)
let waitForMemberToLoad = deferFulfillment(context.$viewState) { $0.memberDetails != nil }
try await waitForMemberToLoad.fulfill()
@@ -0,0 +1,65 @@
//
// Copyright 2022 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
@testable import ElementX
@MainActor
class UserProfileScreenViewModelTests: XCTestCase {
var viewModel: UserProfileScreenViewModel!
var context: UserProfileScreenViewModelType.Context { viewModel.context }
func testInitialState() async throws {
let profile = UserProfileProxy(userID: "@alice:matrix.org", displayName: "Alice", avatarURL: .picturesDirectory)
let clientProxy = ClientProxyMock(.init())
clientProxy.profileForReturnValue = .success(profile)
viewModel = UserProfileScreenViewModel(userID: profile.userID,
isPresentedModally: false,
clientProxy: clientProxy,
mediaProvider: MockMediaProvider(),
userIndicatorController: ServiceLocator.shared.userIndicatorController,
analytics: ServiceLocator.shared.analytics)
let waitForMemberToLoad = deferFulfillment(context.$viewState) { $0.userProfile != nil }
try await waitForMemberToLoad.fulfill()
XCTAssertFalse(context.viewState.isOwnUser)
XCTAssertEqual(context.viewState.userProfile, profile)
XCTAssertNotNil(context.viewState.permalink)
}
func testInitialStateAccountOwner() async throws {
let profile = UserProfileProxy(userID: RoomMemberProxyMock.mockMe.userID, displayName: "Me", avatarURL: .picturesDirectory)
let clientProxy = ClientProxyMock(.init())
clientProxy.profileForReturnValue = .success(profile)
viewModel = UserProfileScreenViewModel(userID: profile.userID,
isPresentedModally: false,
clientProxy: clientProxy,
mediaProvider: MockMediaProvider(),
userIndicatorController: ServiceLocator.shared.userIndicatorController,
analytics: ServiceLocator.shared.analytics)
let waitForMemberToLoad = deferFulfillment(context.$viewState) { $0.userProfile != nil }
try await waitForMemberToLoad.fulfill()
XCTAssertTrue(context.viewState.isOwnUser)
XCTAssertEqual(context.viewState.userProfile, profile)
XCTAssertNotNil(context.viewState.permalink)
}
}
@@ -27,14 +27,9 @@ class UserSessionFlowCoordinatorTests: XCTestCase {
var cancellables = Set<AnyCancellable>()
var detailCoordinator: CoordinatorProtocol? {
let navigationSplitCoordinator = navigationRootCoordinator.rootCoordinator as? NavigationSplitCoordinator
return navigationSplitCoordinator?.detailCoordinator
}
var detailNavigationStack: NavigationStackCoordinator? {
detailCoordinator as? NavigationStackCoordinator
}
var splitCoordinator: NavigationSplitCoordinator? { navigationRootCoordinator.rootCoordinator as? NavigationSplitCoordinator }
var detailCoordinator: CoordinatorProtocol? { splitCoordinator?.detailCoordinator }
var detailNavigationStack: NavigationStackCoordinator? { detailCoordinator as? NavigationStackCoordinator }
override func setUp() async throws {
cancellables.removeAll()
@@ -157,6 +152,21 @@ class UserSessionFlowCoordinatorTests: XCTestCase {
XCTAssertNotNil(detailCoordinator)
}
func testUserProfileClearsStack() async throws {
try await process(route: .roomDetails(roomID: "1"), expectedState: .roomList(selectedRoomID: "1"))
XCTAssertTrue(detailNavigationStack?.rootCoordinator is RoomDetailsScreenCoordinator)
XCTAssertNotNil(detailCoordinator)
XCTAssertNil(splitCoordinator?.sheetCoordinator)
try await process(route: .userProfile(userID: "alice"), expectedState: .userProfileScreen)
XCTAssertNil(detailNavigationStack?.rootCoordinator)
guard let sheetStackCoordinator = splitCoordinator?.sheetCoordinator as? NavigationStackCoordinator else {
XCTFail("There should be a navigation stack presented as a sheet.")
return
}
XCTAssertTrue(sheetStackCoordinator.rootCoordinator is UserProfileScreenCoordinator)
}
// MARK: - Private
private func process(route: AppRoute, expectedState: UserSessionFlowCoordinatorStateMachine.State) async throws {