mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-20 16:42:44 +02:00
#1098 - Stopped relying on the SDK in the suggestionService and added unit and ui tests.
This commit is contained in:
+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"))
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user