mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-26 19:34:25 +02:00
#1098 - Stopped relying on the SDK in the suggestionService and added unit and ui tests.
This commit is contained in:
+40
-13
@@ -22,9 +22,7 @@ import SwiftUI
|
||||
|
||||
@available(iOS 14.0, *)
|
||||
protocol UserSuggestionCoordinatorDelegate: AnyObject {
|
||||
func userSuggestionCoordinator(_ coordinator: UserSuggestionCoordinator,
|
||||
didRequestMentionForMember member: MXRoomMember,
|
||||
textTrigger: String?)
|
||||
func userSuggestionCoordinator(_ coordinator: UserSuggestionCoordinator, didRequestMentionForMember member: MXRoomMember, textTrigger: String?)
|
||||
}
|
||||
|
||||
@available(iOS 14.0, *)
|
||||
@@ -35,10 +33,12 @@ final class UserSuggestionCoordinator: Coordinator {
|
||||
// MARK: Private
|
||||
|
||||
private let parameters: UserSuggestionCoordinatorParameters
|
||||
private let userSuggestionHostingController: UIViewController
|
||||
|
||||
private var userSuggestionService: UserSuggestionService
|
||||
private var userSuggestionViewModel: UserSuggestionViewModelProtocol
|
||||
private var userSuggestionHostingController: UIViewController!
|
||||
private var userSuggestionService: UserSuggestionServiceProtocol!
|
||||
private var userSuggestionViewModel: UserSuggestionViewModelProtocol!
|
||||
|
||||
private var roomMembers: [MXRoomMember] = []
|
||||
|
||||
// MARK: Public
|
||||
|
||||
@@ -54,13 +54,13 @@ final class UserSuggestionCoordinator: Coordinator {
|
||||
init(parameters: UserSuggestionCoordinatorParameters) {
|
||||
self.parameters = parameters
|
||||
|
||||
userSuggestionService = UserSuggestionService(room: parameters.room)
|
||||
userSuggestionService = UserSuggestionService(roomMembersProvider: self)
|
||||
userSuggestionViewModel = UserSuggestionViewModel.makeUserSuggestionViewModel(userSuggestionService: userSuggestionService)
|
||||
|
||||
let view = UserSuggestionList(viewModel: userSuggestionViewModel.context)
|
||||
.addDependency(AvatarService.instantiate(mediaManager: parameters.mediaManager))
|
||||
|
||||
userSuggestionHostingController = UIHostingController(rootView: view)
|
||||
userSuggestionHostingController = VectorHostingController(rootView: view)
|
||||
|
||||
userSuggestionViewModel.completion = { [weak self] result in
|
||||
guard let self = self else {
|
||||
@@ -69,14 +69,11 @@ final class UserSuggestionCoordinator: Coordinator {
|
||||
|
||||
switch result {
|
||||
case .selectedItemWithIdentifier(let identifier):
|
||||
guard let member = self.userSuggestionService.roomMemberForIdentifier(identifier) else {
|
||||
guard let member = self.roomMembers.filter({ $0.userId == identifier }).first else {
|
||||
return
|
||||
}
|
||||
|
||||
self.delegate?.userSuggestionCoordinator(self,
|
||||
didRequestMentionForMember: member,
|
||||
textTrigger: self.userSuggestionService.currentTextTrigger)
|
||||
break
|
||||
self.delegate?.userSuggestionCoordinator(self, didRequestMentionForMember: member, textTrigger: self.userSuggestionService.currentTextTrigger)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -94,3 +91,33 @@ final class UserSuggestionCoordinator: Coordinator {
|
||||
return self.userSuggestionHostingController
|
||||
}
|
||||
}
|
||||
|
||||
@available(iOS 14.0, *)
|
||||
extension UserSuggestionCoordinator: RoomMembersProviderProtocol {
|
||||
func fetchMembers(_ members: @escaping ([RoomMembersProviderMember]) -> Void) {
|
||||
guard roomMembers.count == 0 else {
|
||||
members(roomMembersToProviderMembers(roomMembers))
|
||||
return
|
||||
}
|
||||
|
||||
parameters.room.members({ [weak self] roomMembers in
|
||||
guard let self = self, let joinedMembers = roomMembers?.joinedMembers else {
|
||||
return
|
||||
}
|
||||
self.roomMembers = joinedMembers
|
||||
members(self.roomMembersToProviderMembers(joinedMembers))
|
||||
}, lazyLoadedMembers: { [weak self] lazyRoomMembers in
|
||||
guard let self = self, let joinedMembers = lazyRoomMembers?.joinedMembers else {
|
||||
return
|
||||
}
|
||||
self.roomMembers = joinedMembers
|
||||
members(self.roomMembersToProviderMembers(joinedMembers))
|
||||
}, failure: { error in
|
||||
MXLog.error("[UserSuggestionCoordinator] Failed loading room with error: \(String(describing: error))")
|
||||
})
|
||||
}
|
||||
|
||||
private func roomMembersToProviderMembers(_ roomMembers: [MXRoomMember]) -> [RoomMembersProviderMember] {
|
||||
roomMembers.map { RoomMembersProviderMember(identifier: $0.userId, displayName: $0.displayname ?? "", avatarURL: $0.avatarUrl ?? "") }
|
||||
}
|
||||
}
|
||||
|
||||
+3
-9
@@ -18,9 +18,7 @@ import Foundation
|
||||
|
||||
@objc
|
||||
protocol UserSuggestionCoordinatorBridgeDelegate: AnyObject {
|
||||
func userSuggestionCoordinatorBridge(_ coordinator: UserSuggestionCoordinatorBridge,
|
||||
didRequestMentionForMember member: MXRoomMember,
|
||||
textTrigger: String?)
|
||||
func userSuggestionCoordinatorBridge(_ coordinator: UserSuggestionCoordinatorBridge, didRequestMentionForMember member: MXRoomMember, textTrigger: String?)
|
||||
}
|
||||
|
||||
@objcMembers
|
||||
@@ -65,11 +63,7 @@ final class UserSuggestionCoordinatorBridge: NSObject {
|
||||
|
||||
@available(iOS 14.0, *)
|
||||
extension UserSuggestionCoordinatorBridge: UserSuggestionCoordinatorDelegate {
|
||||
func userSuggestionCoordinator(_ coordinator: UserSuggestionCoordinator,
|
||||
didRequestMentionForMember member: MXRoomMember,
|
||||
textTrigger: String?) {
|
||||
delegate?.userSuggestionCoordinatorBridge(self,
|
||||
didRequestMentionForMember: member,
|
||||
textTrigger: textTrigger)
|
||||
func userSuggestionCoordinator(_ coordinator: UserSuggestionCoordinator, didRequestMentionForMember member: MXRoomMember, textTrigger: String?) {
|
||||
delegate?.userSuggestionCoordinatorBridge(self, didRequestMentionForMember: member, textTrigger: textTrigger)
|
||||
}
|
||||
}
|
||||
|
||||
-112
@@ -1,112 +0,0 @@
|
||||
// File created from SimpleUserProfileExample
|
||||
// $ createScreen.sh Room/UserSuggestion UserSuggestion
|
||||
//
|
||||
// Copyright 2021 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 Foundation
|
||||
import Combine
|
||||
|
||||
@available(iOS 14.0, *)
|
||||
struct UserSuggestionServiceItem: UserSuggestionItemProtocol {
|
||||
let userId: String
|
||||
let displayName: String?
|
||||
let avatarUrl: String?
|
||||
}
|
||||
|
||||
@available(iOS 14.0, *)
|
||||
class UserSuggestionService: UserSuggestionServiceProtocol {
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
// MARK: Private
|
||||
|
||||
private let room: MXRoom
|
||||
|
||||
private var suggestionItems: [UserSuggestionItemProtocol] = []
|
||||
private var roomJoinedMembers: [MXRoomMember] = []
|
||||
|
||||
// MARK: Public
|
||||
|
||||
var items: CurrentValueSubject<[UserSuggestionItemProtocol], Never>
|
||||
var currentTextTrigger: String?
|
||||
|
||||
// MARK: - Setup
|
||||
|
||||
init(room: MXRoom) {
|
||||
self.room = room
|
||||
self.items = CurrentValueSubject([])
|
||||
|
||||
self.room.members { [weak self] members in
|
||||
guard let self = self, let joinedMembers = members?.joinedMembers else {
|
||||
return
|
||||
}
|
||||
|
||||
self.roomJoinedMembers = joinedMembers
|
||||
|
||||
self.suggestionItems = joinedMembers.map { member in
|
||||
UserSuggestionServiceItem(userId: member.userId, displayName: member.displayname, avatarUrl: member.avatarUrl)
|
||||
}
|
||||
} lazyLoadedMembers: { [weak self] lazyMembers in
|
||||
guard let self = self, let joinedMembers = lazyMembers?.joinedMembers else {
|
||||
return
|
||||
}
|
||||
|
||||
self.roomJoinedMembers = joinedMembers
|
||||
|
||||
self.suggestionItems = joinedMembers.map { member in
|
||||
UserSuggestionServiceItem(userId: member.userId, displayName: member.displayname, avatarUrl: member.avatarUrl)
|
||||
}
|
||||
} failure: { error in
|
||||
MXLog.error("[UserSuggestionService] Failed loading room with error: \(String(describing: error))")
|
||||
}
|
||||
}
|
||||
|
||||
func roomMemberForIdentifier(_ identifier: String) -> MXRoomMember? {
|
||||
return roomJoinedMembers.filter { $0.userId == identifier }.first
|
||||
}
|
||||
|
||||
// MARK: - UserSuggestionServiceProtocol
|
||||
|
||||
func processTextMessage(_ textMessage: String) {
|
||||
items.send([])
|
||||
currentTextTrigger = nil
|
||||
|
||||
guard textMessage.count > 0 else {
|
||||
return
|
||||
}
|
||||
|
||||
let components = textMessage.components(separatedBy: .whitespaces)
|
||||
|
||||
guard let lastComponent = components.last else {
|
||||
return
|
||||
}
|
||||
|
||||
guard lastComponent.hasPrefix("@") else {
|
||||
return
|
||||
}
|
||||
|
||||
currentTextTrigger = lastComponent
|
||||
|
||||
var partialName = lastComponent
|
||||
partialName.removeFirst()
|
||||
|
||||
items.send(suggestionItems.filter({ userSuggestion in
|
||||
let containedInUsername = userSuggestion.userId.lowercased().range(of: partialName.lowercased()) != .none
|
||||
let containedInDisplayName = (userSuggestion.displayName ?? "").lowercased().range(of: partialName.lowercased()) != .none
|
||||
return (containedInUsername || containedInDisplayName)
|
||||
}))
|
||||
}
|
||||
}
|
||||
+15
-6
@@ -28,12 +28,7 @@ enum MockUserSuggestionScreenState: MockScreenState, CaseIterable {
|
||||
}
|
||||
|
||||
var screenView: ([Any], AnyView) {
|
||||
let service: MockUserSuggestionService
|
||||
switch self {
|
||||
case .multipleResults:
|
||||
service = MockUserSuggestionService(userCount: 10)
|
||||
}
|
||||
|
||||
let service = UserSuggestionService(roomMembersProvider: self)
|
||||
let listViewModel = UserSuggestionViewModel.makeUserSuggestionViewModel(userSuggestionService: service)
|
||||
|
||||
let viewModel = UserSuggestionListWithInputViewModel(listViewModel: listViewModel) { textMessage in
|
||||
@@ -47,3 +42,17 @@ enum MockUserSuggestionScreenState: MockScreenState, CaseIterable {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@available(iOS 14.0, *)
|
||||
extension MockUserSuggestionScreenState: RoomMembersProviderProtocol {
|
||||
func fetchMembers(_ members: ([RoomMembersProviderMember]) -> Void) {
|
||||
members(generateUsersWithCount(10))
|
||||
}
|
||||
|
||||
private func generateUsersWithCount(_ count: UInt) -> [RoomMembersProviderMember] {
|
||||
return (0..<count).map { _ in
|
||||
let identifier = "@" + UUID().uuidString
|
||||
return RoomMembersProviderMember(identifier: identifier, displayName: identifier, avatarURL: "mxc://matrix.org/VyNYAgahaiAzUoOeZETtQ")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
// File created from SimpleUserProfileExample
|
||||
// $ createScreen.sh Room/UserSuggestion UserSuggestion
|
||||
//
|
||||
// Copyright 2021 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 Foundation
|
||||
import Combine
|
||||
|
||||
@available(iOS 14.0, *)
|
||||
struct MockUserSuggestionServiceItem: UserSuggestionItemProtocol {
|
||||
let userId: String
|
||||
let displayName: String?
|
||||
let avatarUrl: String?
|
||||
}
|
||||
|
||||
@available(iOS 14.0, *)
|
||||
class MockUserSuggestionService: UserSuggestionServiceProtocol {
|
||||
private var suggestionItems: [UserSuggestionItemProtocol] = []
|
||||
|
||||
var items: CurrentValueSubject<[UserSuggestionItemProtocol], Never>
|
||||
|
||||
init(userCount: UInt) {
|
||||
items = CurrentValueSubject([])
|
||||
generateUsersWithCount(userCount)
|
||||
items.send(suggestionItems)
|
||||
}
|
||||
|
||||
func processTextMessage(_ textMessage: String) {
|
||||
|
||||
items.send([])
|
||||
|
||||
guard textMessage.count > 0 else {
|
||||
return
|
||||
}
|
||||
|
||||
let components = textMessage.components(separatedBy: .whitespaces)
|
||||
|
||||
guard let lastComponent = components.last else {
|
||||
return
|
||||
}
|
||||
|
||||
guard lastComponent.hasPrefix("@") else {
|
||||
return
|
||||
}
|
||||
|
||||
var partialName = lastComponent
|
||||
partialName.removeFirst()
|
||||
|
||||
items.send(suggestionItems.filter({ userSuggestion in
|
||||
return (userSuggestion.displayName?.lowercased().range(of: partialName.lowercased()) != .none)
|
||||
}))
|
||||
}
|
||||
|
||||
private func generateUsersWithCount(_ count: UInt) {
|
||||
suggestionItems.removeAll()
|
||||
for _ in 0..<count {
|
||||
let identifier = "@" + UUID().uuidString
|
||||
suggestionItems.append(MockUserSuggestionServiceItem(userId: identifier, displayName: identifier, avatarUrl: "mxc://matrix.org/VyNYAgahaiAzUoOeZETtQ"))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
// File created from SimpleUserProfileExample
|
||||
// $ createScreen.sh Room/UserSuggestion UserSuggestion
|
||||
//
|
||||
// Copyright 2021 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 Foundation
|
||||
import Combine
|
||||
|
||||
@available(iOS 14.0, *)
|
||||
struct RoomMembersProviderMember {
|
||||
var identifier: String
|
||||
var displayName: String
|
||||
var avatarURL: String
|
||||
}
|
||||
|
||||
@available(iOS 14.0, *)
|
||||
protocol RoomMembersProviderProtocol {
|
||||
func fetchMembers(_ members: @escaping ([RoomMembersProviderMember]) -> Void)
|
||||
}
|
||||
|
||||
@available(iOS 14.0, *)
|
||||
struct UserSuggestionServiceItem: UserSuggestionItemProtocol {
|
||||
let userId: String
|
||||
let displayName: String?
|
||||
let avatarUrl: String?
|
||||
}
|
||||
|
||||
@available(iOS 14.0, *)
|
||||
class UserSuggestionService: UserSuggestionServiceProtocol {
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
// MARK: Private
|
||||
|
||||
private let roomMembersProvider: RoomMembersProviderProtocol
|
||||
|
||||
private var suggestionItems: [UserSuggestionItemProtocol] = []
|
||||
|
||||
// MARK: Public
|
||||
|
||||
var items: CurrentValueSubject<[UserSuggestionItemProtocol], Never>
|
||||
var currentTextTrigger: String?
|
||||
|
||||
// MARK: - Setup
|
||||
|
||||
init(roomMembersProvider: RoomMembersProviderProtocol) {
|
||||
self.roomMembersProvider = roomMembersProvider
|
||||
self.items = CurrentValueSubject([])
|
||||
}
|
||||
|
||||
// MARK: - UserSuggestionServiceProtocol
|
||||
|
||||
func processTextMessage(_ textMessage: String) {
|
||||
roomMembersProvider.fetchMembers { [weak self] members in
|
||||
guard let self = self else {
|
||||
return
|
||||
}
|
||||
|
||||
self.suggestionItems = members.map { member in
|
||||
UserSuggestionServiceItem(userId: member.identifier, displayName: member.displayName, avatarUrl: member.avatarURL)
|
||||
}
|
||||
|
||||
self.items.send([])
|
||||
self.currentTextTrigger = nil
|
||||
|
||||
guard textMessage.count > 0 else {
|
||||
return
|
||||
}
|
||||
|
||||
let components = textMessage.components(separatedBy: .whitespaces)
|
||||
|
||||
guard let lastComponent = components.last else {
|
||||
return
|
||||
}
|
||||
|
||||
// Partial username should start with one and only one "@" character
|
||||
guard lastComponent.prefix(while: { character in character == "@" }).count == 1 else {
|
||||
return
|
||||
}
|
||||
|
||||
self.currentTextTrigger = lastComponent
|
||||
|
||||
var partialName = lastComponent
|
||||
partialName.removeFirst()
|
||||
|
||||
self.items.send(self.suggestionItems.filter({ userSuggestion in
|
||||
let containedInUsername = userSuggestion.userId.lowercased().range(of: partialName.lowercased()) != .none
|
||||
let containedInDisplayName = (userSuggestion.displayName ?? "").lowercased().range(of: partialName.lowercased()) != .none
|
||||
|
||||
return (containedInUsername || containedInDisplayName)
|
||||
}))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,8 @@ protocol UserSuggestionServiceProtocol {
|
||||
|
||||
var items: CurrentValueSubject<[UserSuggestionItemProtocol], Never> { get }
|
||||
|
||||
var currentTextTrigger: String? { get }
|
||||
|
||||
func processTextMessage(_ textMessage: String)
|
||||
}
|
||||
|
||||
|
||||
@@ -31,17 +31,10 @@ class UserSuggestionUITests: MockScreenTest {
|
||||
}
|
||||
|
||||
func verifyUserSuggestionScreen() throws {
|
||||
guard let screenState = screenState as? MockUserSuggestionScreenState else { fatalError("no screen") }
|
||||
switch screenState {
|
||||
case .longDisplayName(let name):
|
||||
verifyUserSuggestionLongName(name: name)
|
||||
}
|
||||
XCTAssert(app.tables.firstMatch.exists)
|
||||
|
||||
let firstButton = app.tables.firstMatch.buttons.firstMatch
|
||||
_ = firstButton.waitForExistence(timeout: 10)
|
||||
XCTAssert(firstButton.identifier == "displayNameText-userIdText")
|
||||
}
|
||||
|
||||
func verifyUserSuggestionLongName(name: String) {
|
||||
let displayNameText = app.staticTexts["displayNameText"]
|
||||
XCTAssert(displayNameText.exists)
|
||||
XCTAssertEqual(displayNameText.label, name)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
// File created from SimpleUserProfileExample
|
||||
// $ createScreen.sh Room/UserSuggestion UserSuggestion
|
||||
//
|
||||
// Copyright 2021 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 RiotSwiftUI
|
||||
|
||||
@available(iOS 14.0, *)
|
||||
class UserSuggestionServiceTests: XCTestCase {
|
||||
|
||||
var service: UserSuggestionService?
|
||||
|
||||
override func setUp() {
|
||||
service = UserSuggestionService(roomMembersProvider: self)
|
||||
}
|
||||
|
||||
func testAlice() {
|
||||
service?.processTextMessage("@Al")
|
||||
assert(service?.items.value.first?.displayName == "Alice")
|
||||
|
||||
service?.processTextMessage("@al")
|
||||
assert(service?.items.value.first?.displayName == "Alice")
|
||||
|
||||
service?.processTextMessage("@ice")
|
||||
assert(service?.items.value.first?.displayName == "Alice")
|
||||
|
||||
service?.processTextMessage("@Alice")
|
||||
assert(service?.items.value.first?.displayName == "Alice")
|
||||
|
||||
service?.processTextMessage("@alice:matrix.org")
|
||||
assert(service?.items.value.first?.displayName == "Alice")
|
||||
}
|
||||
|
||||
func testBob() {
|
||||
service?.processTextMessage("@ob")
|
||||
assert(service?.items.value.first?.displayName == "Bob")
|
||||
|
||||
service?.processTextMessage("@ob:")
|
||||
assert(service?.items.value.first?.displayName == "Bob")
|
||||
|
||||
service?.processTextMessage("@b:matrix")
|
||||
assert(service?.items.value.first?.displayName == "Bob")
|
||||
}
|
||||
|
||||
func testBoth() {
|
||||
service?.processTextMessage("@:matrix")
|
||||
assert(service?.items.value.first?.displayName == "Alice")
|
||||
assert(service?.items.value.last?.displayName == "Bob")
|
||||
|
||||
service?.processTextMessage("@.org")
|
||||
assert(service?.items.value.first?.displayName == "Alice")
|
||||
assert(service?.items.value.last?.displayName == "Bob")
|
||||
}
|
||||
|
||||
func testEmptyResult() {
|
||||
service?.processTextMessage("Lorem ipsum idolor")
|
||||
assert(service?.items.value.count == 0)
|
||||
|
||||
service?.processTextMessage("@")
|
||||
assert(service?.items.value.count == 0)
|
||||
|
||||
service?.processTextMessage("@@")
|
||||
assert(service?.items.value.count == 0)
|
||||
}
|
||||
|
||||
func testStuff() {
|
||||
service?.processTextMessage("@@")
|
||||
assert(service?.items.value.count == 0)
|
||||
}
|
||||
|
||||
func testWhitespaces() {
|
||||
service?.processTextMessage("")
|
||||
assert(service?.items.value.count == 0)
|
||||
|
||||
service?.processTextMessage(" ")
|
||||
assert(service?.items.value.count == 0)
|
||||
|
||||
service?.processTextMessage("\n")
|
||||
assert(service?.items.value.count == 0)
|
||||
|
||||
service?.processTextMessage(" \n ")
|
||||
assert(service?.items.value.count == 0)
|
||||
|
||||
service?.processTextMessage("@A ")
|
||||
assert(service?.items.value.count == 0)
|
||||
|
||||
service?.processTextMessage(" @A ")
|
||||
assert(service?.items.value.count == 0)
|
||||
}
|
||||
}
|
||||
|
||||
@available(iOS 14.0, *)
|
||||
extension UserSuggestionServiceTests: RoomMembersProviderProtocol {
|
||||
func fetchMembers(_ members: @escaping ([RoomMembersProviderMember]) -> Void) {
|
||||
|
||||
let users = [("Alice", "@alice:matrix.org"),
|
||||
("Bob", "@bob:matrix.org")]
|
||||
|
||||
members(users.map({ user in
|
||||
RoomMembersProviderMember(identifier: user.1, displayName: user.0, avatarURL: "")
|
||||
}))
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
// File created from SimpleUserProfileExample
|
||||
// $ createScreen.sh Room/UserSuggestion UserSuggestion
|
||||
//
|
||||
// Copyright 2021 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 RiotSwiftUI
|
||||
|
||||
@available(iOS 14.0, *)
|
||||
class UserSuggestionViewModelTests: XCTestCase {
|
||||
private enum Constants {
|
||||
static let displayName = "Alice"
|
||||
}
|
||||
var service: MockUserSuggestionService!
|
||||
var viewModel: UserSuggestionViewModelProtocol!
|
||||
var context: UserSuggestionViewModelType.Context!
|
||||
var cancellables = Set<AnyCancellable>()
|
||||
override func setUpWithError() throws {
|
||||
service = MockUserSuggestionService(userCount: 10)
|
||||
viewModel = UserSuggestionViewModel.makeUserSuggestionViewModel(userSuggestionService: service)
|
||||
context = viewModel.context
|
||||
}
|
||||
|
||||
func testInitialState() {
|
||||
// XCTAssertEqual(context.viewState.displayName, Constants.displayName)
|
||||
}
|
||||
}
|
||||
@@ -44,6 +44,9 @@ struct UserSuggestionListWithInput: View {
|
||||
})
|
||||
.border(Color.black)
|
||||
.padding([.leading, .trailing])
|
||||
.onAppear(perform: {
|
||||
inputText = "@-" // Make the list show all available mock results
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user