Update environment object setup and view model context wrapping to restore SwiftUI UI tests

This commit is contained in:
aringenbach
2023-03-23 15:45:31 +01:00
parent b26e0ccea3
commit 9ea625e470
8 changed files with 30 additions and 26 deletions
@@ -30,8 +30,6 @@ enum MockComposerScreenState: MockScreenState, CaseIterable {
var screenView: ([Any], AnyView) {
let viewModel: ComposerViewModel
let userSuggestionViewModel = MockUserSuggestionViewModel(initialViewState: UserSuggestionViewState(items: []))
let userSuggestionSharedContext = UserSuggestionSharedContext(context: userSuggestionViewModel.context,
mediaManager: MXMediaManager())
let bindings = ComposerBindings(focused: false)
switch self {
@@ -69,7 +67,7 @@ enum MockComposerScreenState: MockScreenState, CaseIterable {
Spacer()
Composer(viewModel: viewModel.context,
wysiwygViewModel: wysiwygviewModel,
userSuggestionSharedContext: userSuggestionSharedContext,
userSuggestionSharedContext: userSuggestionViewModel.context,
resizeAnimationDuration: 0.1,
sendMessageAction: { _ in },
showSendMediaActions: { })
@@ -23,7 +23,7 @@ struct Composer: View {
// MARK: Private
@ObservedObject private var viewModel: ComposerViewModelType.Context
@ObservedObject private var wysiwygViewModel: WysiwygComposerViewModel
private let userSuggestionSharedContext: UserSuggestionSharedContext
private let userSuggestionSharedContext: UserSuggestionViewModelType.Context
private let resizeAnimationDuration: Double
private let sendMessageAction: (WysiwygComposerContent) -> Void
@@ -223,7 +223,7 @@ struct Composer: View {
init(
viewModel: ComposerViewModelType.Context,
wysiwygViewModel: WysiwygComposerViewModel,
userSuggestionSharedContext: UserSuggestionSharedContext,
userSuggestionSharedContext: UserSuggestionViewModelType.Context,
resizeAnimationDuration: Double,
sendMessageAction: @escaping (WysiwygComposerContent) -> Void,
showSendMediaActions: @escaping () -> Void) {
@@ -256,8 +256,7 @@ struct Composer: View {
}
}
if wysiwygViewModel.maximised {
UserSuggestionList(viewModel: userSuggestionSharedContext.context, showBackgroundShadow: false)
.environmentObject(AvatarViewModel(avatarService: AvatarService(mediaManager: userSuggestionSharedContext.mediaManager)))
UserSuggestionList(viewModel: userSuggestionSharedContext, showBackgroundShadow: false)
}
}
.frame(height: composerHeight)
@@ -30,16 +30,12 @@ struct UserSuggestionCoordinatorParameters {
let room: MXRoom
}
/// Defines a shared context providing the ability to use a single `UserSuggestionViewModel` for multiple
/// `UserSuggestionList` e.g. the list component can then be displayed seemlessly in both `RoomViewController`
/// UIKit hosted context, and in Rich-Text-Editor's SwiftUI fullscreen mode, without need to reload data.
final class UserSuggestionSharedContext: NSObject {
/// Wrapper around `UserSuggestionViewModelType.Context` to pass it through obj-c.
final class UserSuggestionViewModelContextWrapper: NSObject {
let context: UserSuggestionViewModelType.Context
let mediaManager: MXMediaManager
init(context: UserSuggestionViewModelType.Context, mediaManager: MXMediaManager) {
init(context: UserSuggestionViewModelType.Context) {
self.context = context
self.mediaManager = mediaManager
}
}
@@ -118,9 +114,8 @@ final class UserSuggestionCoordinator: Coordinator, Presentable {
userSuggestionHostingController
}
func sharedContext() -> UserSuggestionSharedContext {
UserSuggestionSharedContext(context: userSuggestionViewModel.sharedContext,
mediaManager: parameters.mediaManager)
func sharedContext() -> UserSuggestionViewModelContextWrapper {
UserSuggestionViewModelContextWrapper(context: userSuggestionViewModel.sharedContext)
}
// MARK: - Private
@@ -53,7 +53,7 @@ final class UserSuggestionCoordinatorBridge: NSObject {
userSuggestionCoordinator.toPresentable()
}
func sharedContext() -> UserSuggestionSharedContext {
func sharedContext() -> UserSuggestionViewModelContextWrapper {
userSuggestionCoordinator.sharedContext()
}
}
@@ -17,6 +17,9 @@
import Foundation
protocol UserSuggestionViewModelProtocol {
/// Defines a shared context providing the ability to use a single `UserSuggestionViewModel` for multiple
/// `UserSuggestionList` e.g. the list component can then be displayed seemlessly in both `RoomViewController`
/// UIKit hosted context, and in Rich-Text-Editor's SwiftUI fullscreen mode, without need to reload the data.
var sharedContext: UserSuggestionViewModelType.Context { get }
var completion: ((UserSuggestionViewModelResult) -> Void)? { get set }
}