Replace the ServiceLocator with direct dependency injection (#5548)

Removes the ServiceLocator singleton and instead directly injects the dependencies it was holding for more control over instantiation of the various component subtrees and better visibility over how they're being used.
This commit is contained in:
Michael
2026-05-14 01:45:49 -05:00
committed by GitHub
parent f70182d09a
commit ff5dcb040d
108 changed files with 971 additions and 729 deletions
@@ -40,17 +40,9 @@ class AccessibilityTestsAppCoordinator: AppCoordinatorProtocol {
MXLog.configure(currentTarget: "accessibility-tests")
ServiceLocator.shared.register(userIndicatorController: UserIndicatorController())
AppSettings.configureWithSuiteName("io.element.elementx.accessibilitytests")
AppSettings.resetAllSettings()
ServiceLocator.shared.register(appSettings: AppSettings())
let analyticsClient = AnalyticsClientMock()
analyticsClient.isRunning = false
ServiceLocator.shared.register(analytics: AnalyticsService(client: analyticsClient,
appSettings: ServiceLocator.shared.settings))
guard let name = ProcessInfo.accessibilityViewID,
let previewType = TestablePreviewsDictionary.dictionary[name] else {
fatalError("Unable to launch with unknown screen.")
@@ -22,6 +22,9 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
private let targetConfiguration: Target.ConfigurationResult
private let appMediator: AppMediator
private let appSettings: AppSettings
private let analyticsService: AnalyticsService
private let userIndicatorController: UserIndicatorControllerProtocol
private let appDelegate: AppDelegate
private let appHooks: AppHooks
private let bugReportService: BugReportServiceProtocol
@@ -76,7 +79,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
appMediator = AppMediator(windowManager: windowManager, networkMonitor: networkMonitor)
let appSettings = appHooks.appSettingsHook.configure(AppSettings())
ServiceLocator.shared.register(appSettings: appSettings)
self.appSettings = appSettings
targetConfiguration = Target.mainApp.configure(logLevel: appSettings.logLevel,
traceLogPacks: appSettings.traceLogPacks,
@@ -94,17 +97,15 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
}
self.appDelegate = appDelegate
self.appSettings = appSettings
self.appHooks = appHooks
appRouteURLParser = AppRouteURLParser(appSettings: appSettings)
ServiceLocator.shared.register(userIndicatorController: UserIndicatorController())
let posthogAnalyticsClient = PostHogAnalyticsClient()
posthogAnalyticsClient.updateSuperProperties(AnalyticsEvent.SuperProperties(appPlatform: .EXI, cryptoSDK: .Rust, cryptoSDKVersion: sdkGitSha()))
let analyticsService = AnalyticsService(client: posthogAnalyticsClient, appSettings: appSettings)
ServiceLocator.shared.register(analytics: analyticsService)
analyticsService = AnalyticsService(client: posthogAnalyticsClient, appSettings: appSettings)
userIndicatorController = UserIndicatorController()
elementCallService = ElementCallService()
@@ -136,7 +137,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
sdkGitSHA: sdkGitSha(),
appHooks: appHooks)
Self.setupSentry(bugReportService: bugReportService, appSettings: appSettings)
Self.setupSentry(bugReportService: bugReportService, appSettings: appSettings, analytics: analyticsService)
analyticsService.startIfEnabled()
@@ -165,9 +166,9 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
registerBackgroundAppRefresh()
appSettings.$analyticsConsentState
.dropFirst() // Called above before configuring the ServiceLocator
.sink { [bugReportService] _ in
Self.setupSentry(bugReportService: bugReportService, appSettings: appSettings)
.dropFirst() // Sentry is configured during init; only reconfigure when consent state actually changes
.sink { [bugReportService, analyticsService, appSettings] _ in
Self.setupSentry(bugReportService: bugReportService, appSettings: appSettings, analytics: analyticsService)
}
.store(in: &cancellables)
@@ -216,7 +217,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
func toPresentable() -> AnyView {
AnyView(navigationRootCoordinator.toPresentable()
.environment(\.analyticsService, ServiceLocator.shared.analytics)
.environment(\.analyticsService, analyticsService)
.onReceive(appSettings.$appAppearance) { [weak self] appAppearance in
guard let self else { return }
@@ -370,7 +371,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
func windowManagerDidConfigureWindows(_ windowManager: SecureWindowManagerProtocol) {
windowManager.alternateWindow.rootViewController = UIHostingController(rootView: appLockFlowCoordinator.toPresentable())
ServiceLocator.shared.userIndicatorController.window = windowManager.overlayWindow
userIndicatorController.window = windowManager.overlayWindow
}
// MARK: - NotificationManagerDelegate
@@ -414,7 +415,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
handleAppRoute(.thread(roomID: roomID, threadRootEventID: threadRootEventID, focusEventID: eventID), windowType: nil)
} else if let eventID {
// Only track main timeline event deeplinking
ServiceLocator.shared.analytics.signpost.startTransaction(.notificationToMessage)
analyticsService.signpost.startTransaction(.notificationToMessage)
handleAppRoute(.event(eventID: eventID, roomID: roomID, via: []), windowType: nil)
} else {
handleAppRoute(.room(roomID: roomID, via: []), windowType: nil)
@@ -665,8 +666,8 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
appMediator: appMediator,
appSettings: appSettings,
appHooks: appHooks,
analytics: ServiceLocator.shared.analytics,
userIndicatorController: ServiceLocator.shared.userIndicatorController)
analytics: analyticsService,
userIndicatorController: userIndicatorController)
coordinator.delegate = self
authenticationFlowCoordinator = coordinator
@@ -721,7 +722,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
appMediator: appMediator,
appSettings: appSettings,
appHooks: appHooks,
userIndicatorController: ServiceLocator.shared.userIndicatorController)
userIndicatorController: userIndicatorController)
let coordinator = SoftLogoutScreenCoordinator(parameters: parameters)
self.softLogoutCoordinator = coordinator
coordinator.actions
@@ -750,24 +751,24 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
}
if let serverName = userSession.clientProxy.userIDServerName {
ServiceLocator.shared.analytics.signpost.addGlobalTag(.homeserver, value: serverName)
analyticsService.signpost.addGlobalTag(.homeserver, value: serverName)
}
if !isNewLogin {
ServiceLocator.shared.analytics.signpost.startTransaction(.cachedRoomList)
analyticsService.signpost.startTransaction(.cachedRoomList)
}
let flowParameters = CommonFlowParameters(userSession: userSession,
bugReportService: bugReportService,
elementCallService: elementCallService,
timelineControllerFactory: TimelineControllerFactory(),
timelineControllerFactory: TimelineControllerFactory(appSettings: appSettings),
emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(),
appMediator: appMediator,
appSettings: appSettings,
appHooks: appHooks,
analytics: ServiceLocator.shared.analytics,
userIndicatorController: ServiceLocator.shared.userIndicatorController,
analytics: analyticsService,
userIndicatorController: userIndicatorController,
notificationManager: notificationManager,
stateMachineFactory: StateMachineFactory())
@@ -837,8 +838,8 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
appHooks.remoteSettingsHook.reset(appSettings)
// Reset analytics
ServiceLocator.shared.analytics.optOut()
ServiceLocator.shared.analytics.resetConsentState()
analyticsService.optOut()
analyticsService.resetConsentState()
stateMachine.processEvent(.completedSigningOut)
@@ -847,7 +848,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
}
private func tearDownUserSession() {
ServiceLocator.shared.userIndicatorController.retractAllIndicators()
userIndicatorController.retractAllIndicators()
userSession = nil
@@ -949,7 +950,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
}
}
private static func setupSentry(bugReportService: BugReportServiceProtocol, appSettings: AppSettings) {
private static func setupSentry(bugReportService: BugReportServiceProtocol, appSettings: AppSettings, analytics: AnalyticsService) {
guard let bugReportSentryURL = appSettings.bugReportSentryURL else { return }
let options: Options = .init()
@@ -1008,7 +1009,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
// Any ongoing transactions will no longer be valid after calling SentrySDK.start so lets
// remove them and start over, otherwise the app will crash if finishTransaction is used.
ServiceLocator.shared.analytics.signpost.resetTransactions()
analytics.signpost.resetTransactions()
SentrySDK.start(options: options) // Swift
enableSentryLogging(enabled: options.enabled) // Rust
@@ -1043,18 +1044,18 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
private static let loadingIndicatorIdentifier = "\(AppCoordinator.self)-Loading"
private func showLoadingIndicator() {
ServiceLocator.shared.userIndicatorController.submitIndicator(UserIndicator(id: Self.loadingIndicatorIdentifier,
type: .modal,
title: L10n.commonLoading,
persistent: true))
userIndicatorController.submitIndicator(UserIndicator(id: Self.loadingIndicatorIdentifier,
type: .modal,
title: L10n.commonLoading,
persistent: true))
}
private func hideLoadingIndicator() {
ServiceLocator.shared.userIndicatorController.retractIndicatorWithId(Self.loadingIndicatorIdentifier)
userIndicatorController.retractIndicatorWithId(Self.loadingIndicatorIdentifier)
}
private func showLoginErrorToast() {
ServiceLocator.shared.userIndicatorController.submitIndicator(UserIndicator(title: "Failed logging in"))
userIndicatorController.submitIndicator(UserIndicator(title: "Failed logging in"))
}
// MARK: - Application State
@@ -1074,8 +1075,8 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
private func startSync() {
guard let userSession else { return }
ServiceLocator.shared.analytics.signpost.startTransaction(.upToDateRoomList)
analyticsService.signpost.startTransaction(.upToDateRoomList)
userSession.clientProxy.startSync()
guard clientProxyObserver == nil else {
@@ -1089,16 +1090,17 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
.receive(on: DispatchQueue.main)
.sink { [weak self] state in
let toastIdentifier = "StaleDataIndicator"
guard let self else { return }
switch state {
case .loading:
if self?.userSession?.clientProxy.homeserverReachabilityPublisher.value == .reachable,
self?.appMediator.networkMonitor.reachabilityPublisher.value == .reachable {
ServiceLocator.shared.userIndicatorController.submitIndicator(.init(id: toastIdentifier, type: .toast(progress: .indeterminate), title: L10n.commonSyncing, persistent: true))
if self.userSession?.clientProxy.homeserverReachabilityPublisher.value == .reachable,
self.appMediator.networkMonitor.reachabilityPublisher.value == .reachable {
self.userIndicatorController.submitIndicator(.init(id: toastIdentifier, type: .toast(progress: .indeterminate), title: L10n.commonSyncing, persistent: true))
}
case .notLoading:
ServiceLocator.shared.analytics.signpost.finishTransaction(.upToDateRoomList)
ServiceLocator.shared.userIndicatorController.retractIndicatorWithId(toastIdentifier)
self.analyticsService.signpost.finishTransaction(.upToDateRoomList)
self.userIndicatorController.retractIndicatorWithId(toastIdentifier)
}
}
}
@@ -1,33 +0,0 @@
//
// Copyright 2025 Element Creations Ltd.
// Copyright 2022-2025 New Vector Ltd.
//
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
// Please see LICENSE files in the repository root for full details.
//
import Foundation
class ServiceLocator {
private(set) static var shared = ServiceLocator()
private init() { }
private(set) var userIndicatorController: UserIndicatorControllerProtocol!
func register(userIndicatorController: UserIndicatorControllerProtocol) {
self.userIndicatorController = userIndicatorController
}
private(set) var settings: AppSettings!
func register(appSettings: AppSettings) {
settings = appSettings
}
private(set) var analytics: AnalyticsService!
func register(analytics: AnalyticsService) {
self.analytics = analytics
}
}
@@ -0,0 +1,21 @@
//
// Copyright 2026 Element Creations Ltd.
//
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
// Please see LICENSE files in the repository root for full details.
//
extension AnalyticsService {
static func mock(_ clientOverride: AnalyticsClientProtocol? = nil, settings: AppSettings? = nil) -> AnalyticsService {
let client: AnalyticsClientProtocol
if let clientOverride {
client = clientOverride
} else {
let mockClient = AnalyticsClientMock()
mockClient.isRunning = false
client = mockClient
}
return .init(client: client, appSettings: settings ?? AppSettings())
}
}
@@ -18,7 +18,7 @@ struct ScreenTrackerViewModifier: ViewModifier {
func body(content: Content) -> some View {
content
.onAppear {
analyticsService.track(screen: screen)
analyticsService?.track(screen: screen)
}
}
}
@@ -56,7 +56,7 @@ private struct VisualListItemLabelStyle: LabelStyle {
// MARK: - Previews
struct VisualListItem_Previews: PreviewProvider, TestablePreview {
static let strings = AnalyticsPromptScreenStrings(termsURL: ServiceLocator.shared.settings.analyticsTermsURL)
static let strings = AnalyticsPromptScreenStrings(termsURL: AppSettings().analyticsTermsURL)
static var testImage1: some View {
Image(systemName: "circle")
@@ -158,11 +158,14 @@ struct LoginScreen_Previews: PreviewProvider, TestablePreview {
Task { await authenticationService.configure(for: homeserverAddress, flow: .login) }
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
let viewModel = LoginScreenViewModel(authenticationService: authenticationService,
loginHint: nil,
userIndicatorController: UserIndicatorControllerMock(),
appSettings: ServiceLocator.shared.settings,
analytics: ServiceLocator.shared.analytics)
appSettings: appSettings,
analytics: analytics)
if withCredentials {
viewModel.context.username = "alice"
@@ -163,7 +163,7 @@ struct ServerConfirmationScreen_Previews: PreviewProvider, TestablePreview {
ServerConfirmationScreenViewModel(authenticationService: AuthenticationService.mock,
mode: mode,
authenticationFlow: flow,
appSettings: ServiceLocator.shared.settings,
userIndicatorController: UserIndicatorControllerMock())
appSettings: AppSettings(),
userIndicatorController: UserIndicatorControllerMock.default)
}
}
@@ -116,8 +116,8 @@ struct ServerSelection_Previews: PreviewProvider, TestablePreview {
let viewModel = ServerSelectionScreenViewModel(authenticationService: authenticationService,
authenticationFlow: .login,
appSettings: ServiceLocator.shared.settings,
userIndicatorController: UserIndicatorControllerMock())
appSettings: AppSettings(),
userIndicatorController: UserIndicatorControllerMock.default)
viewModel.context.homeserverAddress = homeserverAddress
if homeserverAddress == "thisisbad" {
viewModel.context.send(viewAction: .confirm)
@@ -151,7 +151,7 @@ struct AuthenticationClassicAppAccountView_Previews: PreviewProvider { // Not Te
provisioningParameters: nil,
isBugReportServiceEnabled: false,
appMediator: AppMediatorMock(),
appSettings: ServiceLocator.shared.settings,
appSettings: AppSettings(),
mediaProvider: MediaProviderMock(configuration: .init()),
userIndicatorController: UserIndicatorControllerMock())
}
@@ -195,7 +195,7 @@ struct AuthenticationStartScreen_Previews: PreviewProvider, TestablePreview {
provisioningParameters: provisionedServerName.map { .init(accountProvider: $0, loginHint: nil) },
isBugReportServiceEnabled: true,
appMediator: AppMediatorMock(),
appSettings: ServiceLocator.shared.settings,
appSettings: AppSettings(),
mediaProvider: MediaProviderMock(configuration: .init()),
userIndicatorController: UserIndicatorControllerMock())
}
@@ -363,7 +363,10 @@ struct CallScreen_Previews: PreviewProvider {
widgetDriver.startBaseURLClientIDColorSchemeVoiceOnlyRageshakeURLAnalyticsConfigurationReturnValue = .success(URL.userDirectory)
roomProxy.elementCallWidgetDriverDeviceIDReturnValue = widgetDriver
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
return CallScreenViewModel(elementCallService: ElementCallServiceMock(.init()),
configuration: .init(roomProxy: roomProxy,
clientProxy: clientProxy,
@@ -374,8 +377,8 @@ struct CallScreen_Previews: PreviewProvider {
colorScheme: .light),
allowPictureInPicture: false,
appHooks: AppHooks(),
appSettings: ServiceLocator.shared.settings,
analyticsService: ServiceLocator.shared.analytics)
appSettings: appSettings,
analyticsService: analytics)
}()
static var previews: some View {
@@ -227,8 +227,8 @@ struct PollFormScreen_Previews: PreviewProvider, TestablePreview {
static func makeViewModel(mode: PollFormMode) -> PollFormScreenViewModel {
PollFormScreenViewModel(mode: mode,
timelineController: MockTimelineController(),
analytics: ServiceLocator.shared.analytics,
userIndicatorController: UserIndicatorControllerMock())
analytics: .mock(),
userIndicatorController: UserIndicatorControllerMock.default)
}
}
@@ -456,13 +456,13 @@ struct CreateRoom_Previews: PreviewProvider, TestablePreview {
let spaces = [SpaceServiceRoom].mockJoinedSpaces2
clientProxy.spaceService = SpaceServiceProxyMock(.init(editableSpaces: spaces))
let userSession = UserSessionMock(.init(clientProxy: clientProxy))
return CreateRoomScreenViewModel(isSpace: isSpace,
spaceSelectionMode: selectionMode,
shouldShowCancelButton: isSpace,
userSession: userSession,
analytics: ServiceLocator.shared.analytics,
userIndicatorController: UserIndicatorControllerMock(),
analytics: .mock(settings: appSettings),
userIndicatorController: UserIndicatorControllerMock.default,
appSettings: appSettings)
}
}
@@ -66,14 +66,17 @@ struct CreateRoomSpaceSelectionSheet_Previews: PreviewProvider, TestablePreview
let clientProxy = ClientProxyMock(.init(userID: "@userid:example.com"))
clientProxy.spaceService = SpaceServiceProxyMock(.init(editableSpaces: .mockJoinedSpaces2))
let userSession = UserSessionMock(.init(clientProxy: clientProxy))
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
return CreateRoomScreenViewModel(isSpace: false,
spaceSelectionMode: .editableSpacesList(preSelectedSpace: nil),
shouldShowCancelButton: false,
userSession: userSession,
analytics: ServiceLocator.shared.analytics,
userIndicatorController: UserIndicatorControllerMock(),
appSettings: ServiceLocator.shared.settings)
analytics: analytics,
userIndicatorController: UserIndicatorControllerMock.default,
appSettings: appSettings)
}()
static var previews: some View {
@@ -103,7 +103,7 @@ struct EmojiPickerScreen: View {
struct EmojiPickerScreen_Previews: PreviewProvider, TestablePreview {
static let viewModel = EmojiPickerScreenViewModel(itemID: .randomEvent,
selectedEmojis: ["😀", "😄"],
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings),
emojiProvider: EmojiProvider(appSettings: AppSettings()),
timelineController: MockTimelineController())
static var previews: some View {
@@ -116,7 +116,7 @@ struct EmojiPickerScreen_Previews: PreviewProvider, TestablePreview {
struct EmojiPickerScreenSheet_Previews: PreviewProvider {
static let viewModel = EmojiPickerScreenViewModel(itemID: .randomEvent,
selectedEmojis: ["😀", "😄"],
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings),
emojiProvider: EmojiProvider(appSettings: AppSettings()),
timelineController: MockTimelineController())
static var previews: some View {
@@ -59,10 +59,10 @@ struct RoomListFiltersEmptyStateView_Previews: PreviewProvider, TestablePreview
VStack(spacing: 24) {
ForEach(RoomListFilter.allCases) { filter in
RoomListFiltersEmptyStateView(state: .init(activeFilters: [filter],
appSettings: ServiceLocator.shared.settings))
appSettings: AppSettings()))
}
RoomListFiltersEmptyStateView(state: .init(activeFilters: [.people, .favourites],
appSettings: ServiceLocator.shared.settings))
appSettings: AppSettings()))
}
.padding(.bottom)
.previewLayout(.sizeThatFits)
@@ -90,10 +90,10 @@ struct RoomListFiltersView: View {
struct RoomListFiltersView_Previews: PreviewProvider, TestablePreview {
static var previews: some View {
RoomListFiltersView(state: .constant(.init(appSettings: ServiceLocator.shared.settings)))
RoomListFiltersView(state: .constant(.init(appSettings: AppSettings())))
RoomListFiltersView(state: .constant(.init(activeFilters: [.rooms, .favourites],
appSettings: ServiceLocator.shared.settings)))
appSettings: AppSettings())))
RoomListFiltersView(state: .constant(.init(activeFilters: [.lowPriority],
appSettings: ServiceLocator.shared.settings)))
appSettings: AppSettings())))
}
}
@@ -221,12 +221,15 @@ struct HomeScreen_Previews: PreviewProvider, TestablePreview {
roomSummaryProvider: RoomSummaryProviderMock(.init(state: roomSummaryProviderState))))
let userSession = UserSessionMock(.init(clientProxy: clientProxy))
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
return HomeScreenViewModel(userSession: userSession,
selectedRoomPublisher: CurrentValueSubject<String?, Never>(nil).asCurrentValuePublisher(),
appSettings: ServiceLocator.shared.settings,
analyticsService: ServiceLocator.shared.analytics,
appSettings: appSettings,
analyticsService: analytics,
notificationManager: NotificationManagerMock(),
userIndicatorController: ServiceLocator.shared.userIndicatorController)
userIndicatorController: UserIndicatorControllerMock.default)
}
}
@@ -143,12 +143,14 @@ struct HomeScreenEmptyStateView_Previews: PreviewProvider, TestablePreview {
static let viewModel = {
let userSession = UserSessionMock(.init(clientProxy: ClientProxyMock(.init(userID: "@user:example.com",
roomSummaryProvider: RoomSummaryProviderMock(.init(state: .loaded([])))))))
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
return HomeScreenViewModel(userSession: userSession,
selectedRoomPublisher: CurrentValueSubject<String?, Never>(nil).asCurrentValuePublisher(),
appSettings: ServiceLocator.shared.settings,
analyticsService: ServiceLocator.shared.analytics,
appSettings: appSettings,
analyticsService: analytics,
notificationManager: NotificationManagerMock(),
userIndicatorController: ServiceLocator.shared.userIndicatorController)
userIndicatorController: UserIndicatorControllerMock.default)
}()
}
@@ -199,13 +199,16 @@ struct HomeScreenInviteCell_Previews: PreviewProvider, TestablePreview {
let clientProxy = ClientProxyMock(.init())
let userSession = UserSessionMock(.init(clientProxy: clientProxy))
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
return HomeScreenViewModel(userSession: userSession,
selectedRoomPublisher: CurrentValueSubject<String?, Never>(nil).asCurrentValuePublisher(),
appSettings: ServiceLocator.shared.settings,
analyticsService: ServiceLocator.shared.analytics,
appSettings: appSettings,
analyticsService: analytics,
notificationManager: NotificationManagerMock(),
userIndicatorController: ServiceLocator.shared.userIndicatorController)
userIndicatorController: UserIndicatorControllerMock.default)
}
}
@@ -131,13 +131,16 @@ struct HomeScreenKnockedCell_Previews: PreviewProvider, TestablePreview {
let clientProxy = ClientProxyMock(.init())
let userSession = UserSessionMock(.init(clientProxy: clientProxy))
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
return HomeScreenViewModel(userSession: userSession,
selectedRoomPublisher: CurrentValueSubject<String?, Never>(nil).asCurrentValuePublisher(),
appSettings: ServiceLocator.shared.settings,
analyticsService: ServiceLocator.shared.analytics,
appSettings: appSettings,
analyticsService: analytics,
notificationManager: NotificationManagerMock(),
userIndicatorController: ServiceLocator.shared.userIndicatorController)
userIndicatorController: UserIndicatorControllerMock.default)
}
}
@@ -120,12 +120,15 @@ struct HomeScreenRecoveryKeyConfirmationBanner_Previews: PreviewProvider, Testab
roomSummaryProvider: RoomSummaryProviderMock(.init(state: .loading))))
let userSession = UserSessionMock(.init(clientProxy: clientProxy))
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
return HomeScreenViewModel(userSession: userSession,
selectedRoomPublisher: CurrentValueSubject<String?, Never>(nil).asCurrentValuePublisher(),
appSettings: ServiceLocator.shared.settings,
analyticsService: ServiceLocator.shared.analytics,
appSettings: appSettings,
analyticsService: analytics,
notificationManager: NotificationManagerMock(),
userIndicatorController: ServiceLocator.shared.userIndicatorController)
userIndicatorController: UserIndicatorControllerMock.default)
}
}
@@ -253,12 +253,15 @@ struct HomeScreenRoomCell_Previews: PreviewProvider, TestablePreview {
static func makeViewModel(roomSummaryProvider: RoomSummaryProviderProtocol) -> HomeScreenViewModel {
let userSession = UserSessionMock(.init(clientProxy: ClientProxyMock(.init(userID: "John Doe", roomSummaryProvider: roomSummaryProvider))))
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
return HomeScreenViewModel(userSession: userSession,
selectedRoomPublisher: CurrentValueSubject<String?, Never>(nil).asCurrentValuePublisher(),
appSettings: ServiceLocator.shared.settings,
analyticsService: ServiceLocator.shared.analytics,
appSettings: appSettings,
analyticsService: analytics,
notificationManager: NotificationManagerMock(),
userIndicatorController: ServiceLocator.shared.userIndicatorController)
userIndicatorController: UserIndicatorControllerMock.default)
}
static func makeRoom(lastMessageState: RoomSummary.LastMessageState) -> HomeScreenRoom {
@@ -65,7 +65,7 @@ struct InviteUsersConfirmationSheetView_Previews: PreviewProvider, TestablePrevi
isSkippable: true,
userDiscoveryService: UserDiscoveryServiceMock(),
userIndicatorController: UserIndicatorControllerMock(),
appSettings: ServiceLocator.shared.settings)
appSettings: AppSettings())
viewModel.state.usersToConfirm = [.mockAlice, .mockCharlie, .mockBob, .mockDan]
@@ -193,7 +193,7 @@ struct InviteUsersScreen_Previews: PreviewProvider, TestablePreview {
isSkippable: true,
userDiscoveryService: userDiscoveryService,
userIndicatorController: UserIndicatorControllerMock(),
appSettings: ServiceLocator.shared.settings)
appSettings: AppSettings())
if let searchQuery {
viewModel.context.searchQuery = searchQuery
@@ -458,7 +458,7 @@ struct JoinRoomScreenPreviewWrapper: Identifiable {
viewModel = JoinRoomScreenViewModel(source: source,
appSettings: appSettings,
userSession: UserSessionMock(.init(clientProxy: clientProxy)),
userIndicatorController: ServiceLocator.shared.userIndicatorController)
userIndicatorController: UserIndicatorControllerMock.default)
}
var previewDisplayName: String {
@@ -388,13 +388,16 @@ extension LocationSharingScreenViewModel {
let liveLocationServiceMock = RoomLiveLocationServiceMock(.init(shares: liveLocationShares))
let roomProxy = JoinedRoomProxyMock(.init(members: .allMembers, ownUserID: RoomMemberProxyMock.mockMe.userID))
roomProxy.makeLiveLocationServiceReturnValue = liveLocationServiceMock
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
return LocationSharingScreenViewModel(interactionMode: interactionMode,
mapURLBuilder: ServiceLocator.shared.settings.mapTilerConfiguration,
mapURLBuilder: appSettings.mapTilerConfiguration,
roomProxy: roomProxy,
timelineController: MockTimelineController(),
liveLocationManager: LiveLocationManagerMock(),
analytics: ServiceLocator.shared.analytics,
analytics: analytics,
userIndicatorController: UserIndicatorControllerMock(),
mediaProvider: MediaProviderMock(configuration: .init()))
}
@@ -120,7 +120,7 @@ private extension ManageRoomMemberSheetViewModel {
ownPowerLevel: powerLevel),
roomProxy: JoinedRoomProxyMock(.init()),
userIndicatorController: UserIndicatorControllerMock(),
analyticsService: ServiceLocator.shared.analytics,
analyticsService: .mock(),
mediaProvider: MediaProviderMock(configuration: .init()))
}
}
@@ -309,16 +309,19 @@ struct MediaEventsTimelineScreen_Previews: PreviewProvider, TestablePreview {
} else {
MockTimelineController.mediaGallery
}
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
return TimelineViewModel(roomProxy: JoinedRoomProxyMock(.init(name: "Preview room")),
timelineController: timelineController,
userSession: UserSessionMock(.init()),
mediaPlayerProvider: MediaPlayerProviderMock(),
userIndicatorController: UserIndicatorControllerMock(),
appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings,
analyticsService: ServiceLocator.shared.analytics,
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings),
appSettings: appSettings,
analyticsService: analytics,
emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(),
timelineControllerFactory: TimelineControllerFactoryMock(.init()))
}
@@ -370,7 +370,7 @@ struct MediaUploadPreviewScreen_Previews: PreviewProvider, TestablePreview {
title: "App Icon.png",
isRoomEncrypted: true,
shouldShowCaptionWarning: true,
mediaUploadingPreprocessor: MediaUploadingPreprocessor(appSettings: ServiceLocator.shared.settings),
mediaUploadingPreprocessor: MediaUploadingPreprocessor(appSettings: AppSettings()),
timelineController: MockTimelineController(),
clientProxy: ClientProxyMock(.init()),
userIndicatorController: UserIndicatorControllerMock.default)
@@ -102,6 +102,6 @@ struct AnalyticsPromptScreen_Previews: PreviewProvider, TestablePreview {
}
static func makeViewModel(showTerms: Bool = true) -> AnalyticsPromptScreenViewModel {
AnalyticsPromptScreenViewModel(termsURL: showTerms ? ServiceLocator.shared.settings.analyticsTermsURL : nil)
AnalyticsPromptScreenViewModel(termsURL: showTerms ? AppSettings().analyticsTermsURL : nil)
}
}
@@ -140,7 +140,7 @@ struct IdentityConfirmationScreen_Previews: PreviewProvider, TestablePreview {
userSession.sessionSecurityStatePublisher = CurrentValuePublisher<SessionSecurityState, Never>(.init(verificationState: .unverified, recoveryState: recoveryState))
return IdentityConfirmationScreenViewModel(userSession: userSession,
appSettings: ServiceLocator.shared.settings,
userIndicatorController: ServiceLocator.shared.userIndicatorController)
appSettings: AppSettings(),
userIndicatorController: UserIndicatorControllerMock.default)
}
}
@@ -69,20 +69,24 @@ struct PinnedEventsTimelineScreen_Previews: PreviewProvider, TestablePreview {
static let viewModel = PinnedEventsTimelineScreenViewModel(roomProxy: JoinedRoomProxyMock(.init()),
userIndicatorController: UserIndicatorControllerMock(),
appSettings: AppSettings(),
analyticsService: ServiceLocator.shared.analytics)
analyticsService: .mock())
static let emptyTimelineViewModel: TimelineViewModel = {
let timelineController = MockTimelineController(timelineKind: .pinned)
timelineController.timelineItems = []
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
return TimelineViewModel(roomProxy: JoinedRoomProxyMock(.init(name: "Preview room")),
timelineController: timelineController,
userSession: UserSessionMock(.init()),
mediaPlayerProvider: MediaPlayerProviderMock(),
userIndicatorController: UserIndicatorControllerMock(),
appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings,
analyticsService: ServiceLocator.shared.analytics,
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings),
appSettings: appSettings,
analyticsService: analytics,
emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(),
timelineControllerFactory: TimelineControllerFactoryMock(.init()))
}()
@@ -91,6 +91,6 @@ struct RoomChangePermissionsScreen_Previews: PreviewProvider, TestablePreview {
ownPowerLevel: ownPowerLevel,
roomProxy: JoinedRoomProxyMock(.init(isSpace: isSpace)),
userIndicatorController: UserIndicatorControllerMock(),
analytics: ServiceLocator.shared.analytics)
analytics: .mock())
}
}
@@ -151,6 +151,6 @@ struct RoomChangeRolesScreen_Previews: PreviewProvider, TestablePreview {
roomProxy: JoinedRoomProxyMock(.init(members: members)),
mediaProvider: MediaProviderMock(configuration: .init()),
userIndicatorController: UserIndicatorControllerMock(),
analytics: ServiceLocator.shared.analytics)
analytics: .mock())
}
}
@@ -177,7 +177,7 @@ struct RoomDetailsEditScreen_Previews: PreviewProvider, TestablePreview {
return RoomDetailsEditScreenViewModel(roomProxy: roomProxy,
userSession: UserSessionMock(.init()),
mediaUploadingPreprocessor: MediaUploadingPreprocessor(appSettings: ServiceLocator.shared.settings),
mediaUploadingPreprocessor: MediaUploadingPreprocessor(appSettings: AppSettings()),
userIndicatorController: UserIndicatorControllerMock.default)
}
}
@@ -405,14 +405,17 @@ struct RoomDetailsScreen_Previews: PreviewProvider, TestablePreview {
notificationSettingsProxyMockConfiguration.roomMode.isDefault = false
let notificationSettingsProxy = NotificationSettingsProxyMock(with: notificationSettingsProxyMockConfiguration)
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
return .init(roomProxy: roomProxy,
userSession: UserSessionMock(.init()),
analyticsService: ServiceLocator.shared.analytics,
userIndicatorController: ServiceLocator.shared.userIndicatorController,
analyticsService: analytics,
userIndicatorController: UserIndicatorControllerMock.default,
notificationSettingsProxy: notificationSettingsProxy,
attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()),
appSettings: ServiceLocator.shared.settings)
appSettings: appSettings)
}
private static func makeSimpleRoomViewModel() -> RoomDetailsScreenViewModel {
@@ -433,14 +436,17 @@ struct RoomDetailsScreen_Previews: PreviewProvider, TestablePreview {
joinRule: .knock))
let notificationSettingsProxy = NotificationSettingsProxyMock(with: .init())
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
return .init(roomProxy: roomProxy,
userSession: UserSessionMock(.init()),
analyticsService: ServiceLocator.shared.analytics,
userIndicatorController: ServiceLocator.shared.userIndicatorController,
analyticsService: analytics,
userIndicatorController: UserIndicatorControllerMock.default,
notificationSettingsProxy: notificationSettingsProxy,
attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()),
appSettings: ServiceLocator.shared.settings)
appSettings: appSettings)
}
private static func makeDMViewModel(verificationState: UserIdentityVerificationState) -> RoomDetailsScreenViewModel {
@@ -471,13 +477,16 @@ struct RoomDetailsScreen_Previews: PreviewProvider, TestablePreview {
}
let notificationSettingsProxy = NotificationSettingsProxyMock(with: .init())
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
return .init(roomProxy: roomProxy,
userSession: UserSessionMock(.init(clientProxy: clientProxyMock)),
analyticsService: ServiceLocator.shared.analytics,
userIndicatorController: ServiceLocator.shared.userIndicatorController,
analyticsService: analytics,
userIndicatorController: UserIndicatorControllerMock.default,
notificationSettingsProxy: notificationSettingsProxy,
attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()),
appSettings: ServiceLocator.shared.settings)
appSettings: appSettings)
}
}
@@ -235,12 +235,15 @@ struct RoomMemberDetailsScreen_Previews: PreviewProvider, TestablePreview {
if member.userID != RoomMemberProxyMock.mockMe.userID {
clientProxyMock.directRoomForUserIDReturnValue = .success("roomID")
}
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
return RoomMemberDetailsScreenViewModel(userID: member.userID,
roomProxy: roomProxyMock,
userSession: UserSessionMock(.init(clientProxy: clientProxyMock)),
userIndicatorController: ServiceLocator.shared.userIndicatorController,
analytics: ServiceLocator.shared.analytics,
appSettings: ServiceLocator.shared.settings)
userIndicatorController: UserIndicatorControllerMock.default,
analytics: analytics,
appSettings: appSettings)
}
}
@@ -261,7 +261,7 @@ struct RoomMembersListScreen_Previews: PreviewProvider, TestablePreview {
members: members,
ownUserID: ownUserID,
powerLevelsConfiguration: .init(canUserInvite: false))),
userIndicatorController: ServiceLocator.shared.userIndicatorController,
analytics: ServiceLocator.shared.analytics)
userIndicatorController: UserIndicatorControllerMock.default,
analytics: .mock())
}
}
@@ -131,8 +131,8 @@ struct RoomMembersListMemberCell_Previews: PreviewProvider, TestablePreview {
static let viewModel = RoomMembersListScreenViewModel(userSession: UserSessionMock(.init()),
roomProxy: JoinedRoomProxyMock(.init(name: "Some room", members: [])),
userIndicatorController: ServiceLocator.shared.userIndicatorController,
analytics: ServiceLocator.shared.analytics)
userIndicatorController: UserIndicatorControllerMock.default,
analytics: .mock())
static var previews: some View {
VStack(spacing: 0) {
Section("Invited/Joined") {
@@ -121,12 +121,12 @@ struct RoomRolesAndPermissionsScreen_Previews: PreviewProvider, TestablePreview
static let viewModel = RoomRolesAndPermissionsScreenViewModel(initialPermissions: RoomPermissions(powerLevels: .mock),
roomProxy: JoinedRoomProxyMock(.init(members: .allMembersAsAdmin)),
userIndicatorController: UserIndicatorControllerMock(),
analytics: ServiceLocator.shared.analytics)
analytics: .mock())
static let creatorViewModel = RoomRolesAndPermissionsScreenViewModel(initialPermissions: RoomPermissions(powerLevels: .mock),
roomProxy: JoinedRoomProxyMock(.init(members: .allMembersAsCreator)),
userIndicatorController: UserIndicatorControllerMock(),
analytics: ServiceLocator.shared.analytics)
analytics: .mock())
static var previews: some View {
ElementNavigationStack {
RoomRolesAndPermissionsScreen(context: viewModel.context)
@@ -819,15 +819,18 @@ extension ComposerToolbarViewModel {
if !canSend {
roomProxy.identityStatusChangesPublisher = .init([.init(userId: RoomMemberProxyMock.mockAlice.userID, changedTo: .verificationViolation)])
}
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
let wysiwygViewModel = WysiwygComposerViewModel()
let viewModel = ComposerToolbarViewModel(roomProxy: roomProxy,
wysiwygViewModel: wysiwygViewModel,
completionSuggestionService: CompletionSuggestionServiceMock(configuration: .init(suggestions: suggestions)),
mediaProvider: MediaProviderMock(configuration: .init()),
mentionDisplayHelper: ComposerMentionDisplayHelper.mock,
appSettings: ServiceLocator.shared.settings,
analyticsService: ServiceLocator.shared.analytics,
appSettings: appSettings,
analyticsService: analytics,
composerDraftService: ComposerDraftServiceMock(.init()))
viewModel.state.bindings.composerFocused = focused
viewModel.state.bindings.plainComposerText = NSAttributedString(string: message)
@@ -78,14 +78,20 @@ struct RoomAttachmentPicker: View {
}
struct RoomAttachmentPicker_Previews: PreviewProvider, TestablePreview {
static let viewModel = ComposerToolbarViewModel(roomProxy: JoinedRoomProxyMock(.init()),
wysiwygViewModel: WysiwygComposerViewModel(),
completionSuggestionService: CompletionSuggestionServiceMock(configuration: .init()),
mediaProvider: MediaProviderMock(configuration: .init()),
mentionDisplayHelper: ComposerMentionDisplayHelper.mock,
appSettings: ServiceLocator.shared.settings,
analyticsService: ServiceLocator.shared.analytics,
composerDraftService: ComposerDraftServiceMock(.init()))
static let viewModel = makeViewModel()
static func makeViewModel() -> ComposerToolbarViewModel {
let appSettings = AppSettings()
return ComposerToolbarViewModel(roomProxy: JoinedRoomProxyMock(.init()),
wysiwygViewModel: WysiwygComposerViewModel(),
completionSuggestionService: CompletionSuggestionServiceMock(configuration: .init()),
mediaProvider: MediaProviderMock(configuration: .init()),
mentionDisplayHelper: ComposerMentionDisplayHelper.mock,
appSettings: appSettings,
analyticsService: .mock(settings: appSettings),
composerDraftService: ComposerDraftServiceMock(.init()))
}
static var previews: some View {
RoomAttachmentPicker(context: viewModel.context)
@@ -456,14 +456,17 @@ extension RoomScreenViewModel {
static func mock(roomProxyMock: JoinedRoomProxyMock,
clientProxyMock: ClientProxyMock = ClientProxyMock(.init()),
appHooks: AppHooks = AppHooks()) -> RoomScreenViewModel {
RoomScreenViewModel(userSession: UserSessionMock(.init(clientProxy: clientProxyMock)),
roomProxy: roomProxyMock,
initialSelectedPinnedEventID: nil,
ongoingCallRoomIDPublisher: .init(.init(nil)),
appSettings: ServiceLocator.shared.settings,
appHooks: appHooks,
analyticsService: ServiceLocator.shared.analytics,
userIndicatorController: ServiceLocator.shared.userIndicatorController)
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
return RoomScreenViewModel(userSession: UserSessionMock(.init(clientProxy: clientProxyMock)),
roomProxy: roomProxyMock,
initialSelectedPinnedEventID: nil,
ongoingCallRoomIDPublisher: .init(.init(nil)),
appSettings: appSettings,
appHooks: appHooks,
analyticsService: analytics,
userIndicatorController: UserIndicatorControllerMock.default)
}
}
@@ -256,15 +256,19 @@ struct RoomScreen_Previews: PreviewProvider, TestablePreview {
successor: hasSuccessor ? .init(roomId: UUID().uuidString, reason: nil) : nil,
powerLevelsConfiguration: .init(canUserSendMessage: canSendMessage)))
let roomViewModel = RoomScreenViewModel.mock(roomProxyMock: roomProxyMock)
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
let timelineViewModel = TimelineViewModel(roomProxy: roomProxyMock,
timelineController: MockTimelineController(),
userSession: UserSessionMock(.init()),
mediaPlayerProvider: MediaPlayerProviderMock(),
userIndicatorController: ServiceLocator.shared.userIndicatorController,
userIndicatorController: UserIndicatorControllerMock.default,
appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings,
analyticsService: ServiceLocator.shared.analytics,
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings),
appSettings: appSettings,
analyticsService: analytics,
emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(),
timelineControllerFactory: TimelineControllerFactoryMock(.init()))
@@ -162,10 +162,11 @@ private extension AppAppearance {
struct AdvancedSettingsScreen_Previews: PreviewProvider, TestablePreview {
static let viewModel = {
AppSettings.resetAllSettings()
return AdvancedSettingsScreenViewModel(advancedSettings: AppSettings(),
analytics: ServiceLocator.shared.analytics,
let appSettings = AppSettings()
return AdvancedSettingsScreenViewModel(advancedSettings: appSettings,
analytics: .mock(settings: appSettings),
clientProxy: ClientProxyMock(.init()),
userIndicatorController: UserIndicatorControllerMock())
userIndicatorController: UserIndicatorControllerMock.default)
}()
static var previews: some View {
@@ -40,8 +40,9 @@ struct AnalyticsSettingsScreen: View {
struct AnalyticsSettingsScreen_Previews: PreviewProvider, TestablePreview {
static var previews: some View {
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
let viewModel = AnalyticsSettingsScreenViewModel(appSettings: appSettings,
analytics: ServiceLocator.shared.analytics)
analytics: analytics)
AnalyticsSettingsScreen(context: viewModel.context)
}
}
@@ -244,10 +244,11 @@ private extension Set<TraceLogPack> {
// MARK: - Previews
struct DeveloperOptionsScreen_Previews: PreviewProvider {
static let viewModel = DeveloperOptionsScreenViewModel(developerOptions: ServiceLocator.shared.settings,
elementCallBaseURL: ServiceLocator.shared.settings.elementCallBaseURL,
static let viewModel = DeveloperOptionsScreenViewModel(developerOptions: AppSettings(),
elementCallBaseURL: AppSettings().elementCallBaseURL,
appHooks: AppHooks(),
clientProxy: ClientProxyMock(.init()))
static var previews: some View {
ElementNavigationStack {
DeveloperOptionsScreen(context: viewModel.context)
@@ -277,7 +277,7 @@ struct SettingsScreen_Previews: PreviewProvider, TestablePreview {
let userSession = UserSessionMock(.init(clientProxy: ClientProxyMock(.init(userID: "@userid:example.com",
deviceID: "AAAAAAAAAAA"))))
return SettingsScreenViewModel(userSession: userSession,
appSettings: ServiceLocator.shared.settings,
appSettings: AppSettings(),
isBugReportServiceEnabled: isBugReportServiceEnabled,
isInSecondaryWindow: false)
}
@@ -141,7 +141,7 @@ struct UserDetailsEditScreen_Previews: PreviewProvider, TestablePreview {
UserDetailsEditScreenViewModel(userSession: UserSessionMock(.init(clientProxy: ClientProxyMock(.init(userID: "@stefan:matrix.org",
canChangeAvatar: canChangeProfile,
canChangeDisplayName: canChangeProfile)))),
mediaUploadingPreprocessor: .init(appSettings: ServiceLocator.shared.settings),
mediaUploadingPreprocessor: .init(appSettings: AppSettings()),
userIndicatorController: UserIndicatorControllerMock.default)
}
}
@@ -121,30 +121,27 @@ struct SpaceSettingsScreen: View {
// MARK: - Previews
struct SpaceSettingsScreen_Previews: PreviewProvider, TestablePreview {
static let ownerViewModel = RoomDetailsScreenViewModel(roomProxy: JoinedRoomProxyMock(.init(name: "Space",
avatarURL: .mockMXCAvatar,
isSpace: true,
canonicalAlias: "#space:matrix.org",
members: .allMembersAsCreator)),
userSession: UserSessionMock(.init()),
analyticsService: ServiceLocator.shared.analytics,
userIndicatorController: ServiceLocator.shared.userIndicatorController,
notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()),
attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()),
appSettings: ServiceLocator.shared.settings)
static let ownerViewModel = makeViewModel(members: .allMembersAsCreator)
static let userViewModel = RoomDetailsScreenViewModel(roomProxy: JoinedRoomProxyMock(.init(name: "Space",
avatarURL: .mockMXCAvatar,
isSpace: true,
canonicalAlias: "#space:matrix.org",
members: .allMembers)),
userSession: UserSessionMock(.init()),
analyticsService: ServiceLocator.shared.analytics,
userIndicatorController: ServiceLocator.shared.userIndicatorController,
notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()),
attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()),
appSettings: ServiceLocator.shared.settings)
static let userViewModel = makeViewModel(members: .allMembers)
static func makeViewModel(members: [RoomMemberProxyMock]) -> RoomDetailsScreenViewModel {
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
return RoomDetailsScreenViewModel(roomProxy: JoinedRoomProxyMock(.init(name: "Space",
avatarURL: .mockMXCAvatar,
isSpace: true,
canonicalAlias: "#space:matrix.org",
members: members)),
userSession: UserSessionMock(.init()),
analyticsService: analytics,
userIndicatorController: UserIndicatorControllerMock.default,
notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()),
attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()),
appSettings: appSettings)
}
static var previews: some View {
ElementNavigationStack {
SpaceSettingsScreen(context: ownerViewModel.context)
@@ -82,11 +82,15 @@ struct JoinRoomByAddressView_Previews: PreviewProvider, TestablePreview {
let userSession = UserSessionMock(.init(clientProxy: ClientProxyMock(.init(userID: "@userid:example.com"))))
let userDiscoveryService = UserDiscoveryServiceMock()
userDiscoveryService.searchProfilesWithReturnValue = .success([.mockAlice])
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
return StartChatScreenViewModel(userSession: userSession,
analytics: ServiceLocator.shared.analytics,
analytics: analytics,
userIndicatorController: UserIndicatorControllerMock(),
userDiscoveryService: userDiscoveryService,
appSettings: ServiceLocator.shared.settings)
appSettings: appSettings)
}()
static var previews: some View {
@@ -159,7 +159,7 @@ struct StartChatScreen_Previews: PreviewProvider, TestablePreview {
let userDiscoveryService = UserDiscoveryServiceMock()
userDiscoveryService.searchProfilesWithReturnValue = .success([.mockAlice])
return StartChatScreenViewModel(userSession: userSession,
analytics: ServiceLocator.shared.analytics,
analytics: .mock(settings: appSettings),
userIndicatorController: UserIndicatorControllerMock(),
userDiscoveryService: userDiscoveryService,
appSettings: appSettings)
@@ -1056,16 +1056,20 @@ extension TimelineViewModel {
clientProxyMock.roomSummaryForAliasReturnValue = .mock(id: "!room:matrix.org", name: "Room")
clientProxyMock.roomSummaryForIdentifierReturnValue = .mock(id: "!room:matrix.org", name: "Room", canonicalAlias: "#room:matrix.org")
let roomProxy = JoinedRoomProxyMock(.init(name: "Preview room", predecessor: hasPredecessor ? .init(roomId: UUID().uuidString) : nil))
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
return TimelineViewModel(roomProxy: roomProxy,
focussedEventID: nil,
timelineController: timelineController ?? MockTimelineController(timelineKind: timelineKind),
userSession: UserSessionMock(.init(clientProxy: clientProxyMock)),
mediaPlayerProvider: MediaPlayerProviderMock(),
userIndicatorController: ServiceLocator.shared.userIndicatorController,
userIndicatorController: UserIndicatorControllerMock.default,
appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings,
analyticsService: ServiceLocator.shared.analytics,
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings),
appSettings: appSettings,
analyticsService: analytics,
emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(),
timelineControllerFactory: TimelineControllerFactoryMock(.init()))
}
@@ -342,7 +342,7 @@ struct TimelineItemMenu_Previews: PreviewProvider, TestablePreview {
isViewSourceEnabled: true,
areThreadsEnabled: true,
timelineKind: .live,
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings))
emojiProvider: EmojiProvider(appSettings: AppSettings()))
guard let actions = provider.makeActions() else { return nil }
if var textItem = item as? TextRoomTimelineItem {
@@ -44,15 +44,19 @@ struct ReadReceiptsSummaryView_Previews: PreviewProvider, TestablePreview {
.mockDan
]
let roomProxyMock = JoinedRoomProxyMock(.init(name: "Room", members: members))
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
return TimelineViewModel(roomProxy: roomProxyMock,
timelineController: MockTimelineController(),
userSession: UserSessionMock(.init()),
mediaPlayerProvider: MediaPlayerProviderMock(),
userIndicatorController: UserIndicatorControllerMock(),
appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings,
analyticsService: ServiceLocator.shared.analytics,
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings),
appSettings: appSettings,
analyticsService: analytics,
emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(),
timelineControllerFactory: TimelineControllerFactoryMock(.init()))
}()
@@ -343,11 +343,11 @@ struct TimelineItemBubbledStylerView_Previews: PreviewProvider, TestablePreview
timelineController: MockTimelineController(),
userSession: UserSessionMock(.init()),
mediaPlayerProvider: MediaPlayerProviderMock(),
userIndicatorController: ServiceLocator.shared.userIndicatorController,
userIndicatorController: UserIndicatorControllerMock.default,
appMediator: AppMediatorMock.default,
appSettings: appSettings,
analyticsService: ServiceLocator.shared.analytics,
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings),
analyticsService: .mock(settings: appSettings),
emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(),
timelineControllerFactory: TimelineControllerFactoryMock(.init()))
}()
@@ -362,11 +362,11 @@ struct TimelineItemBubbledStylerView_Previews: PreviewProvider, TestablePreview
timelineController: MockTimelineController(),
userSession: UserSessionMock(.init()),
mediaPlayerProvider: MediaPlayerProviderMock(),
userIndicatorController: ServiceLocator.shared.userIndicatorController,
userIndicatorController: UserIndicatorControllerMock.default,
appMediator: AppMediatorMock.default,
appSettings: appSettings,
analyticsService: ServiceLocator.shared.analytics,
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings),
analyticsService: .mock(settings: appSettings),
emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(),
timelineControllerFactory: TimelineControllerFactoryMock(.init()))
}()
@@ -79,18 +79,23 @@ struct TimelineReadReceiptsView_Previews: PreviewProvider, TestablePreview {
.mockMe
]
static let viewModel = TimelineViewModel(roomProxy: JoinedRoomProxyMock(.init(name: "Test", members: members)),
timelineController: MockTimelineController(),
userSession: UserSessionMock(.init()),
mediaPlayerProvider: MediaPlayerProviderMock(),
userIndicatorController: ServiceLocator.shared.userIndicatorController,
appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings,
analyticsService: ServiceLocator.shared.analytics,
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings),
linkMetadataProvider: LinkMetadataProvider(),
timelineControllerFactory: TimelineControllerFactoryMock(.init()))
static let viewModel = {
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
return TimelineViewModel(roomProxy: JoinedRoomProxyMock(.init(name: "Test", members: members)),
timelineController: MockTimelineController(),
userSession: UserSessionMock(.init()),
mediaPlayerProvider: MediaPlayerProviderMock(),
userIndicatorController: UserIndicatorControllerMock.default,
appMediator: AppMediatorMock.default,
appSettings: appSettings,
analyticsService: analytics,
emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(),
timelineControllerFactory: TimelineControllerFactoryMock(.init()))
}()
static let singleReceipt = [ReadReceipt(userID: RoomMemberProxyMock.mockAlice.userID, formattedTimestamp: "Now")]
static let doubleReceipt = [ReadReceipt(userID: RoomMemberProxyMock.mockAlice.userID, formattedTimestamp: "Now"),
ReadReceipt(userID: RoomMemberProxyMock.mockBob.userID, formattedTimestamp: "Before")]
@@ -89,18 +89,23 @@ struct HighlightedTimelineItemTimeline_Previews: PreviewProvider {
static let roomViewModel = RoomScreenViewModel.mock(roomProxyMock: roomProxyMock)
static let focussedEventID = "RoomTimelineItemFixtures.default.5"
static let composerViewModel = ComposerToolbarViewModel.mock()
static let timelineViewModel = TimelineViewModel(roomProxy: roomProxyMock,
focussedEventID: focussedEventID,
timelineController: MockTimelineController(),
userSession: UserSessionMock(.init()),
mediaPlayerProvider: MediaPlayerProviderMock(),
userIndicatorController: ServiceLocator.shared.userIndicatorController,
appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings,
analyticsService: ServiceLocator.shared.analytics,
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings),
linkMetadataProvider: LinkMetadataProvider(),
timelineControllerFactory: TimelineControllerFactoryMock(.init()))
static let timelineViewModel = {
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
return TimelineViewModel(roomProxy: roomProxyMock,
focussedEventID: focussedEventID,
timelineController: MockTimelineController(),
userSession: UserSessionMock(.init()),
mediaPlayerProvider: MediaPlayerProviderMock(),
userIndicatorController: UserIndicatorControllerMock.default,
appMediator: AppMediatorMock.default,
appSettings: appSettings,
analyticsService: analytics,
emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(),
timelineControllerFactory: TimelineControllerFactoryMock(.init()))
}()
static var previews: some View {
ElementNavigationStack {
@@ -146,17 +146,22 @@ struct TimelineView_Previews: PreviewProvider { // Not testable as this preview
name: "Preview room"))
static let roomViewModel = RoomScreenViewModel.mock(roomProxyMock: roomProxyMock)
static let composerViewModel = ComposerToolbarViewModel.mock()
static let timelineViewModel = TimelineViewModel(roomProxy: roomProxyMock,
timelineController: MockTimelineController(),
userSession: UserSessionMock(.init()),
mediaPlayerProvider: MediaPlayerProviderMock(),
userIndicatorController: ServiceLocator.shared.userIndicatorController,
appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings,
analyticsService: ServiceLocator.shared.analytics,
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings),
linkMetadataProvider: LinkMetadataProvider(),
timelineControllerFactory: TimelineControllerFactoryMock(.init()))
static let timelineViewModel = {
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
return TimelineViewModel(roomProxy: roomProxyMock,
timelineController: MockTimelineController(),
userSession: UserSessionMock(.init()),
mediaPlayerProvider: MediaPlayerProviderMock(),
userIndicatorController: UserIndicatorControllerMock.default,
appMediator: AppMediatorMock.default,
appSettings: appSettings,
analyticsService: analytics,
emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(),
timelineControllerFactory: TimelineControllerFactoryMock(.init()))
}()
static var previews: some View {
ElementNavigationStack {
@@ -142,12 +142,15 @@ struct UserProfileScreen_Previews: PreviewProvider, TestablePreview {
if userID != RoomMemberProxyMock.mockMe.userID {
clientProxyMock.directRoomForUserIDReturnValue = .success("roomID")
}
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
return UserProfileScreenViewModel(userID: userID,
isPresentedModally: false,
userSession: UserSessionMock(.init(clientProxy: clientProxyMock)),
userIndicatorController: ServiceLocator.shared.userIndicatorController,
analytics: ServiceLocator.shared.analytics,
appSettings: ServiceLocator.shared.settings)
userIndicatorController: UserIndicatorControllerMock.default,
analytics: analytics,
appSettings: appSettings)
}
}
@@ -9,5 +9,5 @@
import SwiftUI
extension EnvironmentValues {
@Entry var analyticsService: AnalyticsService = ServiceLocator.shared.analytics
@Entry var analyticsService: AnalyticsService?
}
@@ -382,13 +382,13 @@ extension AuthenticationService {
static var mock: AuthenticationService {
mock(classicAppManager: nil)
}
static func mock(classicAppManager: ClassicAppManagerProtocol?) -> AuthenticationService {
AuthenticationService(userSessionStore: UserSessionStoreMock(configuration: .init()),
encryptionKeyProvider: EncryptionKeyProvider(),
classicAppManager: classicAppManager,
clientFactory: AuthenticationClientFactoryMock(configuration: .init()),
appSettings: ServiceLocator.shared.settings,
appSettings: AppSettings(),
appHooks: AppHooks())
}
}
@@ -10,6 +10,8 @@ import Foundation
import MatrixRustSDK
struct TimelineControllerFactory: TimelineControllerFactoryProtocol {
let appSettings: AppSettings
func buildTimelineController(roomProxy: JoinedRoomProxyProtocol,
initialFocussedEventID: String?,
timelineItemFactory: RoomTimelineItemFactoryProtocol,
@@ -19,7 +21,7 @@ struct TimelineControllerFactory: TimelineControllerFactoryProtocol {
initialFocussedEventID: initialFocussedEventID,
timelineItemFactory: timelineItemFactory,
mediaProvider: mediaProvider,
appSettings: ServiceLocator.shared.settings)
appSettings: appSettings)
}
func buildThreadTimelineController(threadRootEventID: String,
@@ -34,7 +36,7 @@ struct TimelineControllerFactory: TimelineControllerFactoryProtocol {
initialFocussedEventID: initialFocussedEventID,
timelineItemFactory: timelineItemFactory,
mediaProvider: mediaProvider,
appSettings: ServiceLocator.shared.settings))
appSettings: appSettings))
case .failure(let error):
return .failure(.roomProxyError(error))
}
@@ -50,7 +52,7 @@ struct TimelineControllerFactory: TimelineControllerFactoryProtocol {
initialFocussedEventID: nil,
timelineItemFactory: timelineItemFactory,
mediaProvider: mediaProvider,
appSettings: ServiceLocator.shared.settings))
appSettings: appSettings))
case .failure(let error):
return .failure(.roomProxyError(error))
}
@@ -69,7 +71,7 @@ struct TimelineControllerFactory: TimelineControllerFactoryProtocol {
initialFocussedEventID: nil,
timelineItemFactory: timelineItemFactory,
mediaProvider: mediaProvider,
appSettings: ServiceLocator.shared.settings))
appSettings: appSettings))
case .failure(let error):
return .failure(.roomProxyError(error))
}
@@ -12,6 +12,10 @@ import SwiftUI
import UIKit
class UITestsAppCoordinator: AppCoordinatorProtocol, SecureWindowManagerDelegate {
private let appSettings: AppSettings
private let analytics: AnalyticsService
private let userIndicatorController: UserIndicatorControllerProtocol
private let navigationRootCoordinator: NavigationRootCoordinator
// periphery:ignore - retaining purpose
@@ -29,26 +33,30 @@ class UITestsAppCoordinator: AppCoordinatorProtocol, SecureWindowManagerDelegate
navigationRootCoordinator = NavigationRootCoordinator()
windowManager.delegate = self
MXLog.configure(currentTarget: "uitests")
ServiceLocator.shared.register(userIndicatorController: UserIndicatorController())
AppSettings.configureWithSuiteName("io.element.elementx.uitests")
AppSettings.resetAllSettings()
ServiceLocator.shared.register(appSettings: AppSettings())
appSettings = AppSettings()
let analyticsClient = AnalyticsClientMock()
analyticsClient.isRunning = false
ServiceLocator.shared.register(analytics: AnalyticsService(client: analyticsClient,
appSettings: ServiceLocator.shared.settings))
analytics = .mock(analyticsClient, settings: appSettings)
userIndicatorController = UserIndicatorController()
windowManager.delegate = self
}
func start() {
guard let screenID = ProcessInfo.testScreenID else { fatalError("Unable to launch with unknown screen.") }
let mockScreen = MockScreen(id: screenID, windowManager: windowManager, navigationRootCoordinator: navigationRootCoordinator)
let mockScreen = MockScreen(id: screenID,
windowManager: windowManager,
navigationRootCoordinator: navigationRootCoordinator,
appSettings: appSettings,
analytics: analytics,
userIndicatorController: userIndicatorController)
if let coordinator = mockScreen.coordinator {
navigationRootCoordinator.setRootCoordinator(coordinator)
@@ -58,7 +66,8 @@ class UITestsAppCoordinator: AppCoordinatorProtocol, SecureWindowManagerDelegate
}
func toPresentable() -> AnyView {
navigationRootCoordinator.toPresentable()
AnyView(navigationRootCoordinator.toPresentable()
.environment(\.analyticsService, analytics))
}
func handlePotentialPhishingAttempt(url: URL, openURLAction: @escaping (URL) -> Void) -> Bool {
@@ -78,13 +87,16 @@ class UITestsAppCoordinator: AppCoordinatorProtocol, SecureWindowManagerDelegate
}
func windowManagerDidConfigureWindows(_ windowManager: SecureWindowManagerProtocol) {
ServiceLocator.shared.userIndicatorController.window = windowManager.overlayWindow
userIndicatorController.window = windowManager.overlayWindow
// Set up the alternate window for the App Lock flow coordinator tests.
guard let screenID = ProcessInfo.testScreenID, screenID == .appLockFlow || screenID == .appLockFlowDisabled else { return }
let screen = MockScreen(id: screenID == .appLockFlow ? .appLockFlowAlternateWindow : .appLockFlowDisabledAlternateWindow,
windowManager: windowManager,
navigationRootCoordinator: navigationRootCoordinator)
navigationRootCoordinator: navigationRootCoordinator,
appSettings: appSettings,
analytics: analytics,
userIndicatorController: userIndicatorController)
guard let coordinator = screen.coordinator else {
fatalError()
@@ -102,6 +114,10 @@ class MockScreen: Identifiable {
let windowManager: SecureWindowManagerProtocol
let navigationRootCoordinator: NavigationRootCoordinator
private let appSettings: AppSettings
private let analytics: AnalyticsService
private let userIndicatorController: UserIndicatorControllerProtocol
private var client: UITestsSignalling.Client?
private var retainedState = [Any]()
@@ -109,10 +125,16 @@ class MockScreen: Identifiable {
init(id: UITestsScreenIdentifier,
windowManager: SecureWindowManagerProtocol,
navigationRootCoordinator: NavigationRootCoordinator) {
navigationRootCoordinator: NavigationRootCoordinator,
appSettings: AppSettings,
analytics: AnalyticsService,
userIndicatorController: UserIndicatorControllerProtocol) {
self.id = id
self.windowManager = windowManager
self.navigationRootCoordinator = navigationRootCoordinator
self.appSettings = appSettings
self.analytics = analytics
self.userIndicatorController = userIndicatorController
}
lazy var coordinator: CoordinatorProtocol? = {
@@ -121,12 +143,12 @@ class MockScreen: Identifiable {
let navigationStackCoordinator = NavigationStackCoordinator()
let coordinator = ServerSelectionScreenCoordinator(parameters: .init(authenticationService: AuthenticationService.mock,
authenticationFlow: .login,
appSettings: ServiceLocator.shared.settings,
userIndicatorController: ServiceLocator.shared.userIndicatorController))
appSettings: appSettings,
userIndicatorController: userIndicatorController))
navigationStackCoordinator.setRootCoordinator(coordinator)
return navigationStackCoordinator
case .authenticationFlow, .provisionedAuthenticationFlow, .singleProviderAuthenticationFlow, .multipleProvidersAuthenticationFlow:
let appSettings: AppSettings! = ServiceLocator.shared.settings
let appSettings: AppSettings! = appSettings
if id == .singleProviderAuthenticationFlow || id == .multipleProvidersAuthenticationFlow {
let accountProviders = id == .singleProviderAuthenticationFlow ? ["example.com"] : ["guest.example.com", "example.com"]
@@ -158,8 +180,8 @@ class MockScreen: Identifiable {
appMediator: AppMediatorMock.default,
appSettings: appSettings,
appHooks: AppHooks(),
analytics: ServiceLocator.shared.analytics,
userIndicatorController: ServiceLocator.shared.userIndicatorController)
analytics: analytics,
userIndicatorController: userIndicatorController)
flowCoordinator.start()
retainedState.append(flowCoordinator)
@@ -184,7 +206,7 @@ class MockScreen: Identifiable {
context.evaluatedPolicyDomainStateValue = Data("😎".utf8)
let appLockService = AppLockService(keychainController: keychainController,
appSettings: ServiceLocator.shared.settings,
appSettings: appSettings,
context: context)
if id == .appLockFlowAlternateWindow {
@@ -206,7 +228,7 @@ class MockScreen: Identifiable {
appLockService: appLockService,
navigationCoordinator: navigationCoordinator,
notificationCenter: notificationCenter,
appSettings: ServiceLocator.shared.settings)
appSettings: appSettings)
flowCoordinator.actions
.sink { [weak self] action in
@@ -240,7 +262,7 @@ class MockScreen: Identifiable {
context.evaluatedPolicyDomainStateValue = Data("😎".utf8)
let appLockService = AppLockService(keychainController: keychainController,
appSettings: ServiceLocator.shared.settings,
appSettings: appSettings,
context: context)
if id == .appLockSetupFlowUnlock, case .failure = appLockService.setupPINCode("2023") {
fatalError("Failed to pre-set the PIN code")
@@ -272,14 +294,14 @@ class MockScreen: Identifiable {
roomProxy: JoinedRoomProxyMock(.init(name: "Some room name", avatarURL: nil)),
timelineController: MockTimelineController(),
mediaPlayerProvider: MediaPlayerProviderMock(),
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings),
emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(),
completionSuggestionService: CompletionSuggestionServiceMock(configuration: .init()),
ongoingCallRoomIDPublisher: .init(.init(nil)),
appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings,
appSettings: appSettings,
appHooks: AppHooks(),
analytics: ServiceLocator.shared.analytics,
analytics: analytics,
composerDraftService: ComposerDraftServiceMock(.init()),
timelineControllerFactory: TimelineControllerFactoryMock(.init()),
userIndicatorController: UserIndicatorControllerMock())
@@ -294,14 +316,14 @@ class MockScreen: Identifiable {
roomProxy: JoinedRoomProxyMock(.init(name: "New room", avatarURL: .mockMXCAvatar)),
timelineController: timelineController,
mediaPlayerProvider: MediaPlayerProviderMock(),
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings),
emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(),
completionSuggestionService: CompletionSuggestionServiceMock(configuration: .init()),
ongoingCallRoomIDPublisher: .init(.init(nil)),
appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings,
appSettings: appSettings,
appHooks: AppHooks(),
analytics: ServiceLocator.shared.analytics,
analytics: analytics,
composerDraftService: ComposerDraftServiceMock(.init()),
timelineControllerFactory: TimelineControllerFactoryMock(.init()),
userIndicatorController: UserIndicatorControllerMock())
@@ -316,14 +338,14 @@ class MockScreen: Identifiable {
roomProxy: JoinedRoomProxyMock(.init(name: "New room", avatarURL: .mockMXCAvatar)),
timelineController: timelineController,
mediaPlayerProvider: MediaPlayerProviderMock(),
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings),
emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(),
completionSuggestionService: CompletionSuggestionServiceMock(configuration: .init()),
ongoingCallRoomIDPublisher: .init(.init(nil)),
appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings,
appSettings: appSettings,
appHooks: AppHooks(),
analytics: ServiceLocator.shared.analytics,
analytics: analytics,
composerDraftService: ComposerDraftServiceMock(.init()),
timelineControllerFactory: TimelineControllerFactoryMock(.init()), userIndicatorController: UserIndicatorControllerMock())
let coordinator = RoomScreenCoordinator(parameters: parameters)
@@ -337,14 +359,14 @@ class MockScreen: Identifiable {
roomProxy: JoinedRoomProxyMock(.init(name: "New room", avatarURL: .mockMXCAvatar)),
timelineController: timelineController,
mediaPlayerProvider: MediaPlayerProviderMock(),
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings),
emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(),
completionSuggestionService: CompletionSuggestionServiceMock(configuration: .init()),
ongoingCallRoomIDPublisher: .init(.init(nil)),
appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings,
appSettings: appSettings,
appHooks: AppHooks(),
analytics: ServiceLocator.shared.analytics,
analytics: analytics,
composerDraftService: ComposerDraftServiceMock(.init()),
timelineControllerFactory: TimelineControllerFactoryMock(.init()), userIndicatorController: UserIndicatorControllerMock())
let coordinator = RoomScreenCoordinator(parameters: parameters)
@@ -361,14 +383,14 @@ class MockScreen: Identifiable {
roomProxy: JoinedRoomProxyMock(.init(name: "Small timeline", avatarURL: .mockMXCAvatar)),
timelineController: timelineController,
mediaPlayerProvider: MediaPlayerProviderMock(),
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings),
emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(),
completionSuggestionService: CompletionSuggestionServiceMock(configuration: .init()),
ongoingCallRoomIDPublisher: .init(.init(nil)),
appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings,
appSettings: appSettings,
appHooks: AppHooks(),
analytics: ServiceLocator.shared.analytics,
analytics: analytics,
composerDraftService: ComposerDraftServiceMock(.init()),
timelineControllerFactory: TimelineControllerFactoryMock(.init()), userIndicatorController: UserIndicatorControllerMock())
let coordinator = RoomScreenCoordinator(parameters: parameters)
@@ -385,14 +407,14 @@ class MockScreen: Identifiable {
roomProxy: JoinedRoomProxyMock(.init(name: "Small timeline, paginating", avatarURL: .mockMXCAvatar)),
timelineController: timelineController,
mediaPlayerProvider: MediaPlayerProviderMock(),
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings),
emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(),
completionSuggestionService: CompletionSuggestionServiceMock(configuration: .init()),
ongoingCallRoomIDPublisher: .init(.init(nil)),
appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings,
appSettings: appSettings,
appHooks: AppHooks(),
analytics: ServiceLocator.shared.analytics,
analytics: analytics,
composerDraftService: ComposerDraftServiceMock(.init()), timelineControllerFactory: TimelineControllerFactoryMock(.init()), userIndicatorController: UserIndicatorControllerMock())
let coordinator = RoomScreenCoordinator(parameters: parameters)
@@ -408,14 +430,14 @@ class MockScreen: Identifiable {
roomProxy: JoinedRoomProxyMock(.init(name: "Large timeline", avatarURL: .mockMXCAvatar)),
timelineController: timelineController,
mediaPlayerProvider: MediaPlayerProviderMock(),
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings),
emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(),
completionSuggestionService: CompletionSuggestionServiceMock(configuration: .init()),
ongoingCallRoomIDPublisher: .init(.init(nil)),
appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings,
appSettings: appSettings,
appHooks: AppHooks(),
analytics: ServiceLocator.shared.analytics,
analytics: analytics,
composerDraftService: ComposerDraftServiceMock(.init()),
timelineControllerFactory: TimelineControllerFactoryMock(.init()), userIndicatorController: UserIndicatorControllerMock())
let coordinator = RoomScreenCoordinator(parameters: parameters)
@@ -433,14 +455,14 @@ class MockScreen: Identifiable {
roomProxy: JoinedRoomProxyMock(.init(name: "Large timeline", avatarURL: .mockMXCAvatar)),
timelineController: timelineController,
mediaPlayerProvider: MediaPlayerProviderMock(),
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings),
emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(),
completionSuggestionService: CompletionSuggestionServiceMock(configuration: .init()),
ongoingCallRoomIDPublisher: .init(.init(nil)),
appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings,
appSettings: appSettings,
appHooks: AppHooks(),
analytics: ServiceLocator.shared.analytics,
analytics: analytics,
composerDraftService: ComposerDraftServiceMock(.init()),
timelineControllerFactory: TimelineControllerFactoryMock(.init()), userIndicatorController: UserIndicatorControllerMock())
let coordinator = RoomScreenCoordinator(parameters: parameters)
@@ -457,14 +479,14 @@ class MockScreen: Identifiable {
roomProxy: JoinedRoomProxyMock(.init(name: "Large timeline", avatarURL: .mockMXCAvatar)),
timelineController: timelineController,
mediaPlayerProvider: MediaPlayerProviderMock(),
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings),
emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(),
completionSuggestionService: CompletionSuggestionServiceMock(configuration: .init()),
ongoingCallRoomIDPublisher: .init(.init(nil)),
appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings,
appSettings: appSettings,
appHooks: AppHooks(),
analytics: ServiceLocator.shared.analytics,
analytics: analytics,
composerDraftService: ComposerDraftServiceMock(.init()),
timelineControllerFactory: TimelineControllerFactoryMock(.init()), userIndicatorController: UserIndicatorControllerMock())
let coordinator = RoomScreenCoordinator(parameters: parameters)
@@ -480,14 +502,14 @@ class MockScreen: Identifiable {
roomProxy: JoinedRoomProxyMock(.init(name: "Timeline highlight", avatarURL: .mockMXCAvatar)),
timelineController: timelineController,
mediaPlayerProvider: MediaPlayerProviderMock(),
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings),
emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(),
completionSuggestionService: CompletionSuggestionServiceMock(configuration: .init()),
ongoingCallRoomIDPublisher: .init(.init(nil)),
appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings,
appSettings: appSettings,
appHooks: AppHooks(),
analytics: ServiceLocator.shared.analytics,
analytics: analytics,
composerDraftService: ComposerDraftServiceMock(.init()),
timelineControllerFactory: TimelineControllerFactoryMock(.init()), userIndicatorController: UserIndicatorControllerMock())
let coordinator = RoomScreenCoordinator(parameters: parameters)
@@ -517,14 +539,14 @@ class MockScreen: Identifiable {
roomProxy: JoinedRoomProxyMock(.init(name: "Polls timeline", avatarURL: .mockMXCAvatar)),
timelineController: timelineController,
mediaPlayerProvider: MediaPlayerProviderMock(),
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings),
emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(),
completionSuggestionService: CompletionSuggestionServiceMock(configuration: .init()),
ongoingCallRoomIDPublisher: .init(.init(nil)),
appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings,
appSettings: appSettings,
appHooks: AppHooks(),
analytics: ServiceLocator.shared.analytics,
analytics: analytics,
composerDraftService: ComposerDraftServiceMock(.init()),
timelineControllerFactory: TimelineControllerFactoryMock(.init()), userIndicatorController: UserIndicatorControllerMock())
let coordinator = RoomScreenCoordinator(parameters: parameters)
@@ -541,14 +563,14 @@ class MockScreen: Identifiable {
roomProxy: JoinedRoomProxyMock(.init(name: "Polls timeline", avatarURL: .mockMXCAvatar)),
timelineController: timelineController,
mediaPlayerProvider: MediaPlayerProviderMock(),
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings),
emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(),
completionSuggestionService: CompletionSuggestionServiceMock(configuration: .init()),
ongoingCallRoomIDPublisher: .init(.init(nil)),
appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings,
appSettings: appSettings,
appHooks: AppHooks(),
analytics: ServiceLocator.shared.analytics,
analytics: analytics,
composerDraftService: ComposerDraftServiceMock(.init()),
timelineControllerFactory: TimelineControllerFactoryMock(.init()), userIndicatorController: UserIndicatorControllerMock())
let coordinator = RoomScreenCoordinator(parameters: parameters)
@@ -565,14 +587,14 @@ class MockScreen: Identifiable {
roomProxy: JoinedRoomProxyMock(.init(name: "Polls timeline", avatarURL: .mockMXCAvatar)),
timelineController: timelineController,
mediaPlayerProvider: MediaPlayerProviderMock(),
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings),
emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(),
completionSuggestionService: CompletionSuggestionServiceMock(configuration: .init()),
ongoingCallRoomIDPublisher: .init(.init(nil)),
appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings,
appSettings: appSettings,
appHooks: AppHooks(),
analytics: ServiceLocator.shared.analytics,
analytics: analytics,
composerDraftService: ComposerDraftServiceMock(.init()),
timelineControllerFactory: TimelineControllerFactoryMock(.init()), userIndicatorController: UserIndicatorControllerMock())
let coordinator = RoomScreenCoordinator(parameters: parameters)
@@ -584,11 +606,11 @@ class MockScreen: Identifiable {
requestDelay: .seconds(5))
let parameters = SessionVerificationScreenCoordinatorParameters(sessionVerificationControllerProxy: sessionVerificationControllerProxy,
flow: .deviceInitiator,
appSettings: ServiceLocator.shared.settings,
appSettings: appSettings,
mediaProvider: MediaProviderMock(configuration: .init()))
return SessionVerificationScreenCoordinator(parameters: parameters)
case .userSessionScreen, .userSessionScreenReply, .userSessionSpacesFlow:
let appSettings: AppSettings = ServiceLocator.shared.settings
let appSettings: AppSettings = appSettings
appSettings.hasRunIdentityConfirmationOnboarding = true
appSettings.hasRunNotificationPermissionsOnboarding = true
appSettings.analyticsConsentState = .optedOut
@@ -616,7 +638,7 @@ class MockScreen: Identifiable {
let flowCoordinator = UserSessionFlowCoordinator(isNewLogin: false,
navigationRootCoordinator: navigationRootCoordinator,
appLockService: AppLockService(keychainController: KeychainControllerMock(),
appSettings: ServiceLocator.shared.settings),
appSettings: appSettings),
flowParameters: CommonFlowParameters(userSession: UserSessionMock(.init(clientProxy: clientProxy)),
bugReportService: BugReportServiceMock(.init()),
elementCallService: ElementCallServiceMock(.init()),
@@ -626,7 +648,7 @@ class MockScreen: Identifiable {
appMediator: appMediator,
appSettings: appSettings,
appHooks: AppHooks(),
analytics: ServiceLocator.shared.analytics,
analytics: analytics,
userIndicatorController: UserIndicatorControllerMock(),
notificationManager: NotificationManagerMock(),
stateMachineFactory: StateMachineFactory()))
@@ -641,8 +663,8 @@ class MockScreen: Identifiable {
let members: [RoomMemberProxyMock] = [.mockInvitedAlice, .mockBob, .mockCharlie]
let coordinator = RoomMembersListScreenCoordinator(parameters: .init(userSession: UserSessionMock(.init()),
roomProxy: JoinedRoomProxyMock(.init(name: "test", members: members)),
userIndicatorController: ServiceLocator.shared.userIndicatorController,
analytics: ServiceLocator.shared.analytics))
userIndicatorController: userIndicatorController,
analytics: analytics))
navigationStackCoordinator.setRootCoordinator(coordinator)
return navigationStackCoordinator
case .roomRolesAndPermissionsFlow:
@@ -651,8 +673,8 @@ class MockScreen: Identifiable {
let coordinator = RoomRolesAndPermissionsFlowCoordinator(parameters: .init(roomProxy: JoinedRoomProxyMock(.init(members: .allMembersAsAdmin)),
mediaProvider: MediaProviderMock(configuration: .init()),
navigationStackCoordinator: navigationStackCoordinator,
userIndicatorController: ServiceLocator.shared.userIndicatorController,
analytics: ServiceLocator.shared.analytics))
userIndicatorController: userIndicatorController,
analytics: analytics))
retainedState.append(coordinator)
coordinator.start()
return navigationStackCoordinator
@@ -673,12 +695,12 @@ class MockScreen: Identifiable {
bugReportService: BugReportServiceMock(.init()),
elementCallService: ElementCallServiceMock(.init()),
timelineControllerFactory: TimelineControllerFactoryMock(.init()),
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings),
emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(),
appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings,
appSettings: appSettings,
appHooks: AppHooks(),
analytics: ServiceLocator.shared.analytics,
analytics: analytics,
userIndicatorController: UserIndicatorControllerMock(),
notificationManager: NotificationManagerMock(),
stateMachineFactory: StateMachineFactory()))
@@ -705,7 +727,7 @@ class MockScreen: Identifiable {
let coordinator = PollFormScreenCoordinator(parameters: .init(mode: .new,
maxNumberOfOptions: 10,
timelineController: MockTimelineController(),
analytics: ServiceLocator.shared.analytics,
analytics: analytics,
userIndicatorController: UserIndicatorControllerMock()))
navigationStackCoordinator.setRootCoordinator(coordinator)
return navigationStackCoordinator
@@ -718,7 +740,7 @@ class MockScreen: Identifiable {
navigationStackCoordinator.setRootCoordinator(BlankFormCoordinator())
let coordinator = EncryptionSettingsFlowCoordinator(parameters: .init(userSession: userSession,
appSettings: ServiceLocator.shared.settings,
appSettings: appSettings,
userIndicatorController: UserIndicatorControllerMock(),
navigationStackCoordinator: navigationStackCoordinator))
retainedState.append(coordinator)
@@ -736,7 +758,7 @@ class MockScreen: Identifiable {
let coordinator = EncryptionResetFlowCoordinator(parameters: .init(userSession: userSession,
appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings,
appSettings: appSettings,
appHooks: AppHooks(),
userIndicatorController: userIndicatorController,
navigationStackCoordinator: navigationStackCoordinator,
@@ -759,12 +781,12 @@ class MockScreen: Identifiable {
bugReportService: BugReportServiceMock(.init()),
elementCallService: ElementCallServiceMock(.init()),
timelineControllerFactory: TimelineControllerFactoryMock(.init()),
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings),
emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(),
appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings,
appSettings: appSettings,
appHooks: AppHooks(),
analytics: ServiceLocator.shared.analytics,
analytics: analytics,
userIndicatorController: UserIndicatorControllerMock(),
notificationManager: NotificationManagerMock(),
stateMachineFactory: StateMachineFactory()))
@@ -787,7 +809,7 @@ class MockScreen: Identifiable {
navigationRootCoordinator.setSheetCoordinator(navigationStackCoordinator)
return PlaceholderScreenCoordinator(hideBrandChrome: false)
case .autoUpdatingTimeline:
let appSettings: AppSettings = ServiceLocator.shared.settings
let appSettings: AppSettings = appSettings
appSettings.hasRunIdentityConfirmationOnboarding = true
appSettings.hasRunNotificationPermissionsOnboarding = true
appSettings.analyticsConsentState = .optedOut
@@ -807,7 +829,7 @@ class MockScreen: Identifiable {
attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()),
stateEventStringBuilder: RoomStateEventStringBuilder(userID: "@alice:matrix.org")),
mediaProvider: MediaProviderMock(configuration: .init()),
appSettings: ServiceLocator.shared.settings)
appSettings: appSettings)
let flowCoordinator = ChatsTabFlowCoordinator(isNewLogin: false,
navigationSplitCoordinator: navigationSplitCoordinator,
@@ -820,7 +842,7 @@ class MockScreen: Identifiable {
appMediator: AppMediatorMock.default,
appSettings: appSettings,
appHooks: AppHooks(),
analytics: ServiceLocator.shared.analytics,
analytics: analytics,
userIndicatorController: UserIndicatorControllerMock(),
notificationManager: NotificationManagerMock(),
stateMachineFactory: StateMachineFactory()))
@@ -17,17 +17,10 @@ class UnitTestsAppCoordinator: AppCoordinatorProtocol {
init(appDelegate: AppDelegate) {
windowManager = WindowManager(appDelegate: appDelegate)
ServiceLocator.shared.register(userIndicatorController: UserIndicatorControllerMock.default)
AppSettings.configureWithSuiteName("io.element.elementx.unittests")
AppSettings.resetAllSettings()
ServiceLocator.shared.register(appSettings: AppSettings())
let analyticsClient = AnalyticsClientMock()
analyticsClient.isRunning = false
ServiceLocator.shared.register(analytics: AnalyticsService(client: analyticsClient,
appSettings: ServiceLocator.shared.settings))
// As the tests take advantage of Rust's ability to redirect the log files, there is
// often some debris left from the previous run, so we wipe the entire directory.
// This is an NOT an advised way to delete logs in production, `Tracing.deleteLogFiles`