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
+4 -4
View File
@@ -426,6 +426,7 @@
484202C5D50983442D24D061 /* AttributedString.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52BD6ED18E2EB61E28C340AD /* AttributedString.swift */; }; 484202C5D50983442D24D061 /* AttributedString.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52BD6ED18E2EB61E28C340AD /* AttributedString.swift */; };
4870F7F72CEBEFDAD1C973A6 /* VoiceMessageMediaEventsTimelineView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD3521DF92391551E02004D8 /* VoiceMessageMediaEventsTimelineView.swift */; }; 4870F7F72CEBEFDAD1C973A6 /* VoiceMessageMediaEventsTimelineView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD3521DF92391551E02004D8 /* VoiceMessageMediaEventsTimelineView.swift */; };
489BB6A733D3DA0FE7062650 /* IdentityConfirmationScreenViewModelProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C71B9802433F1B4252291BB /* IdentityConfirmationScreenViewModelProtocol.swift */; }; 489BB6A733D3DA0FE7062650 /* IdentityConfirmationScreenViewModelProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C71B9802433F1B4252291BB /* IdentityConfirmationScreenViewModelProtocol.swift */; };
48F2D00593F6D73434D3F893 /* AnalyticsService+Mock.swift in Sources */ = {isa = PBXBuildFile; fileRef = A384A5A9F8472A0DA76FDB27 /* AnalyticsService+Mock.swift */; };
491D62ACD19E6F134B1766AF /* RoomNotificationSettingsUserDefinedScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3203C6566DC17B7AECC1B7FD /* RoomNotificationSettingsUserDefinedScreen.swift */; }; 491D62ACD19E6F134B1766AF /* RoomNotificationSettingsUserDefinedScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3203C6566DC17B7AECC1B7FD /* RoomNotificationSettingsUserDefinedScreen.swift */; };
492274DA6691EE985C2FCCAA /* SnapshotTesting in Frameworks */ = {isa = PBXBuildFile; productRef = 21C83087604B154AA30E9A8F /* SnapshotTesting */; }; 492274DA6691EE985C2FCCAA /* SnapshotTesting in Frameworks */ = {isa = PBXBuildFile; productRef = 21C83087604B154AA30E9A8F /* SnapshotTesting */; };
4940B439681767BE9D78CFDB /* AppLockSetupBiometricsScreenViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52F5EE5DE3B55D59299DB5BC /* AppLockSetupBiometricsScreenViewModelTests.swift */; }; 4940B439681767BE9D78CFDB /* AppLockSetupBiometricsScreenViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52F5EE5DE3B55D59299DB5BC /* AppLockSetupBiometricsScreenViewModelTests.swift */; };
@@ -1120,7 +1121,6 @@
BCC864190651B3A3CF51E4DF /* MediaFileHandleProxy.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEC1D382565A4E9CAC2F14EA /* MediaFileHandleProxy.swift */; }; BCC864190651B3A3CF51E4DF /* MediaFileHandleProxy.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEC1D382565A4E9CAC2F14EA /* MediaFileHandleProxy.swift */; };
BD0BE20DBCE31253AE4490A1 /* RoomListFiltersEmptyStateView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC1DDB2293A51EA4C2739351 /* RoomListFiltersEmptyStateView.swift */; }; BD0BE20DBCE31253AE4490A1 /* RoomListFiltersEmptyStateView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC1DDB2293A51EA4C2739351 /* RoomListFiltersEmptyStateView.swift */; };
BD6685592716CA957D7BAAC4 /* RoomChangeRolesScreenSelectedItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D9B45D584D232CB9E5C7734 /* RoomChangeRolesScreenSelectedItem.swift */; }; BD6685592716CA957D7BAAC4 /* RoomChangeRolesScreenSelectedItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D9B45D584D232CB9E5C7734 /* RoomChangeRolesScreenSelectedItem.swift */; };
BD782053BE4C3D2F0BDE5699 /* ServiceLocator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57F95CADD0A5DBD76B990FCB /* ServiceLocator.swift */; };
BDA68E8D95B2B24B28825B8B /* LoginScreenViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C368CAB3063EF275357ECD4 /* LoginScreenViewModel.swift */; }; BDA68E8D95B2B24B28825B8B /* LoginScreenViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C368CAB3063EF275357ECD4 /* LoginScreenViewModel.swift */; };
BDC4EB54CC3036730475CB8B /* QRCodeLoginScreenViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 25E7E9B7FEAB6169D960C206 /* QRCodeLoginScreenViewModelTests.swift */; }; BDC4EB54CC3036730475CB8B /* QRCodeLoginScreenViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 25E7E9B7FEAB6169D960C206 /* QRCodeLoginScreenViewModelTests.swift */; };
BDCF42966007770A33D90E15 /* PreviewScrollView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5DB56ABD78E60920ACE43087 /* PreviewScrollView.swift */; }; BDCF42966007770A33D90E15 /* PreviewScrollView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5DB56ABD78E60920ACE43087 /* PreviewScrollView.swift */; };
@@ -2115,7 +2115,6 @@
57916A1578D8043BB0795441 /* GeneratedMocks.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GeneratedMocks.swift; sourceTree = "<group>"; }; 57916A1578D8043BB0795441 /* GeneratedMocks.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GeneratedMocks.swift; sourceTree = "<group>"; };
57AD14D3ADADE8F6A10F9E88 /* EncryptionSettingsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EncryptionSettingsTests.swift; sourceTree = "<group>"; }; 57AD14D3ADADE8F6A10F9E88 /* EncryptionSettingsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EncryptionSettingsTests.swift; sourceTree = "<group>"; };
57EAAF82432B0B53881CF826 /* AudioRoomTimelineItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AudioRoomTimelineItem.swift; sourceTree = "<group>"; }; 57EAAF82432B0B53881CF826 /* AudioRoomTimelineItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AudioRoomTimelineItem.swift; sourceTree = "<group>"; };
57F95CADD0A5DBD76B990FCB /* ServiceLocator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServiceLocator.swift; sourceTree = "<group>"; };
580BDCD23DD02481AB5FFB47 /* LeaveSpaceHandleSDKMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LeaveSpaceHandleSDKMock.swift; sourceTree = "<group>"; }; 580BDCD23DD02481AB5FFB47 /* LeaveSpaceHandleSDKMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LeaveSpaceHandleSDKMock.swift; sourceTree = "<group>"; };
584A61D9C459FAFEF038A7C0 /* Section.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Section.swift; sourceTree = "<group>"; }; 584A61D9C459FAFEF038A7C0 /* Section.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Section.swift; sourceTree = "<group>"; };
5875F7C0A2398E9F134B1284 /* EncryptionResetScreenViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EncryptionResetScreenViewModel.swift; sourceTree = "<group>"; }; 5875F7C0A2398E9F134B1284 /* EncryptionResetScreenViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EncryptionResetScreenViewModel.swift; sourceTree = "<group>"; };
@@ -2527,6 +2526,7 @@
A232D9156D225BD9FD1D0C43 /* PhotoLibraryPicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhotoLibraryPicker.swift; sourceTree = "<group>"; }; A232D9156D225BD9FD1D0C43 /* PhotoLibraryPicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhotoLibraryPicker.swift; sourceTree = "<group>"; };
A243A6E6207297123E60DE48 /* TimelineItemMacContextMenu.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimelineItemMacContextMenu.swift; sourceTree = "<group>"; }; A243A6E6207297123E60DE48 /* TimelineItemMacContextMenu.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimelineItemMacContextMenu.swift; sourceTree = "<group>"; };
A2723A4AF3AB9F5E18D26E49 /* hr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = hr; path = hr.lproj/InfoPlist.strings; sourceTree = "<group>"; }; A2723A4AF3AB9F5E18D26E49 /* hr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = hr; path = hr.lproj/InfoPlist.strings; sourceTree = "<group>"; };
A384A5A9F8472A0DA76FDB27 /* AnalyticsService+Mock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AnalyticsService+Mock.swift"; sourceTree = "<group>"; };
A3A4F56855188DAD23E59031 /* ja */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ja; path = ja.lproj/InfoPlist.strings; sourceTree = "<group>"; }; A3A4F56855188DAD23E59031 /* ja */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ja; path = ja.lproj/InfoPlist.strings; sourceTree = "<group>"; };
A3B4B58B79A6FA250B24A1EC /* HomeScreenContent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeScreenContent.swift; sourceTree = "<group>"; }; A3B4B58B79A6FA250B24A1EC /* HomeScreenContent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeScreenContent.swift; sourceTree = "<group>"; };
A3E3DE6616DCA81AD5F4791B /* vi */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = vi; path = vi.lproj/InfoPlist.strings; sourceTree = "<group>"; }; A3E3DE6616DCA81AD5F4791B /* vi */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = vi; path = vi.lproj/InfoPlist.strings; sourceTree = "<group>"; };
@@ -3766,6 +3766,7 @@
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
69CB8242D69B7E4D0B32E18D /* AggregatedReactionMock.swift */, 69CB8242D69B7E4D0B32E18D /* AggregatedReactionMock.swift */,
A384A5A9F8472A0DA76FDB27 /* AnalyticsService+Mock.swift */,
3BAC027034248429A438886B /* AppMediatorMock.swift */, 3BAC027034248429A438886B /* AppMediatorMock.swift */,
0554FEA301486A8CFA475D5A /* AuthenticationClientBuilderFactoryMock.swift */, 0554FEA301486A8CFA475D5A /* AuthenticationClientBuilderFactoryMock.swift */,
9FD7E851E2BA8C5A8D284B2A /* BannedRoomProxyMock.swift */, 9FD7E851E2BA8C5A8D284B2A /* BannedRoomProxyMock.swift */,
@@ -5911,7 +5912,6 @@
05AF58372CA884A789EB9C5A /* AppMediatorProtocol.swift */, 05AF58372CA884A789EB9C5A /* AppMediatorProtocol.swift */,
B251F5B4511D1CA0BA8361FE /* CoordinatorProtocol.swift */, B251F5B4511D1CA0BA8361FE /* CoordinatorProtocol.swift */,
7B9FCA1CFD07B8CF9BD21266 /* FlowCoordinatorProtocol.swift */, 7B9FCA1CFD07B8CF9BD21266 /* FlowCoordinatorProtocol.swift */,
57F95CADD0A5DBD76B990FCB /* ServiceLocator.swift */,
B5D829FD8958376614504B18 /* TargetConfiguration.swift */, B5D829FD8958376614504B18 /* TargetConfiguration.swift */,
780F74C73E826685A9DB289B /* Navigation */, 780F74C73E826685A9DB289B /* Navigation */,
D64E20C9E4C486D5C764D7F3 /* Settings */, D64E20C9E4C486D5C764D7F3 /* Settings */,
@@ -8079,6 +8079,7 @@
6DC8E43BA04AC2AC4EB2EB97 /* AnalyticsPromptScreenModels.swift in Sources */, 6DC8E43BA04AC2AC4EB2EB97 /* AnalyticsPromptScreenModels.swift in Sources */,
DB65401349C143DFF883E2B0 /* AnalyticsPromptScreenViewModel.swift in Sources */, DB65401349C143DFF883E2B0 /* AnalyticsPromptScreenViewModel.swift in Sources */,
05BAB510CBC2ED35C154ADD0 /* AnalyticsPromptScreenViewModelProtocol.swift in Sources */, 05BAB510CBC2ED35C154ADD0 /* AnalyticsPromptScreenViewModelProtocol.swift in Sources */,
48F2D00593F6D73434D3F893 /* AnalyticsService+Mock.swift in Sources */,
3C73442084BF8A6939F0F80B /* AnalyticsService.swift in Sources */, 3C73442084BF8A6939F0F80B /* AnalyticsService.swift in Sources */,
020F7E70167FB2833266F2F0 /* AnalyticsSettingsScreen.swift in Sources */, 020F7E70167FB2833266F2F0 /* AnalyticsSettingsScreen.swift in Sources */,
95690DDD9D547D3D842ACBE3 /* AnalyticsSettingsScreenCoordinator.swift in Sources */, 95690DDD9D547D3D842ACBE3 /* AnalyticsSettingsScreenCoordinator.swift in Sources */,
@@ -8880,7 +8881,6 @@
6530865EB9A8C0F0AF0216DA /* ServerSelectionScreenModels.swift in Sources */, 6530865EB9A8C0F0AF0216DA /* ServerSelectionScreenModels.swift in Sources */,
85F89F3F320F4FADCFFFE68B /* ServerSelectionScreenViewModel.swift in Sources */, 85F89F3F320F4FADCFFFE68B /* ServerSelectionScreenViewModel.swift in Sources */,
0C47AE2CA7929CB3B0E2D793 /* ServerSelectionScreenViewModelProtocol.swift in Sources */, 0C47AE2CA7929CB3B0E2D793 /* ServerSelectionScreenViewModelProtocol.swift in Sources */,
BD782053BE4C3D2F0BDE5699 /* ServiceLocator.swift in Sources */,
914BDF61447C723F104BCE33 /* SessionDirectories.swift in Sources */, 914BDF61447C723F104BCE33 /* SessionDirectories.swift in Sources */,
237FC70AA257B935F53316BA /* SessionVerificationControllerProxy.swift in Sources */, 237FC70AA257B935F53316BA /* SessionVerificationControllerProxy.swift in Sources */,
AE1A73B24D63DA3D63DC4EE3 /* SessionVerificationControllerProxyMock.swift in Sources */, AE1A73B24D63DA3D63DC4EE3 /* SessionVerificationControllerProxyMock.swift in Sources */,
@@ -40,16 +40,8 @@ class AccessibilityTestsAppCoordinator: AppCoordinatorProtocol {
MXLog.configure(currentTarget: "accessibility-tests") MXLog.configure(currentTarget: "accessibility-tests")
ServiceLocator.shared.register(userIndicatorController: UserIndicatorController())
AppSettings.configureWithSuiteName("io.element.elementx.accessibilitytests") AppSettings.configureWithSuiteName("io.element.elementx.accessibilitytests")
AppSettings.resetAllSettings() 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, guard let name = ProcessInfo.accessibilityViewID,
let previewType = TestablePreviewsDictionary.dictionary[name] else { let previewType = TestablePreviewsDictionary.dictionary[name] else {
@@ -22,6 +22,9 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
private let targetConfiguration: Target.ConfigurationResult private let targetConfiguration: Target.ConfigurationResult
private let appMediator: AppMediator private let appMediator: AppMediator
private let appSettings: AppSettings private let appSettings: AppSettings
private let analyticsService: AnalyticsService
private let userIndicatorController: UserIndicatorControllerProtocol
private let appDelegate: AppDelegate private let appDelegate: AppDelegate
private let appHooks: AppHooks private let appHooks: AppHooks
private let bugReportService: BugReportServiceProtocol private let bugReportService: BugReportServiceProtocol
@@ -76,7 +79,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
appMediator = AppMediator(windowManager: windowManager, networkMonitor: networkMonitor) appMediator = AppMediator(windowManager: windowManager, networkMonitor: networkMonitor)
let appSettings = appHooks.appSettingsHook.configure(AppSettings()) let appSettings = appHooks.appSettingsHook.configure(AppSettings())
ServiceLocator.shared.register(appSettings: appSettings) self.appSettings = appSettings
targetConfiguration = Target.mainApp.configure(logLevel: appSettings.logLevel, targetConfiguration = Target.mainApp.configure(logLevel: appSettings.logLevel,
traceLogPacks: appSettings.traceLogPacks, traceLogPacks: appSettings.traceLogPacks,
@@ -94,17 +97,15 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
} }
self.appDelegate = appDelegate self.appDelegate = appDelegate
self.appSettings = appSettings
self.appHooks = appHooks self.appHooks = appHooks
appRouteURLParser = AppRouteURLParser(appSettings: appSettings) appRouteURLParser = AppRouteURLParser(appSettings: appSettings)
ServiceLocator.shared.register(userIndicatorController: UserIndicatorController())
let posthogAnalyticsClient = PostHogAnalyticsClient() let posthogAnalyticsClient = PostHogAnalyticsClient()
posthogAnalyticsClient.updateSuperProperties(AnalyticsEvent.SuperProperties(appPlatform: .EXI, cryptoSDK: .Rust, cryptoSDKVersion: sdkGitSha())) posthogAnalyticsClient.updateSuperProperties(AnalyticsEvent.SuperProperties(appPlatform: .EXI, cryptoSDK: .Rust, cryptoSDKVersion: sdkGitSha()))
let analyticsService = AnalyticsService(client: posthogAnalyticsClient, appSettings: appSettings) analyticsService = AnalyticsService(client: posthogAnalyticsClient, appSettings: appSettings)
ServiceLocator.shared.register(analytics: analyticsService)
userIndicatorController = UserIndicatorController()
elementCallService = ElementCallService() elementCallService = ElementCallService()
@@ -136,7 +137,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
sdkGitSHA: sdkGitSha(), sdkGitSHA: sdkGitSha(),
appHooks: appHooks) appHooks: appHooks)
Self.setupSentry(bugReportService: bugReportService, appSettings: appSettings) Self.setupSentry(bugReportService: bugReportService, appSettings: appSettings, analytics: analyticsService)
analyticsService.startIfEnabled() analyticsService.startIfEnabled()
@@ -165,9 +166,9 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
registerBackgroundAppRefresh() registerBackgroundAppRefresh()
appSettings.$analyticsConsentState appSettings.$analyticsConsentState
.dropFirst() // Called above before configuring the ServiceLocator .dropFirst() // Sentry is configured during init; only reconfigure when consent state actually changes
.sink { [bugReportService] _ in .sink { [bugReportService, analyticsService, appSettings] _ in
Self.setupSentry(bugReportService: bugReportService, appSettings: appSettings) Self.setupSentry(bugReportService: bugReportService, appSettings: appSettings, analytics: analyticsService)
} }
.store(in: &cancellables) .store(in: &cancellables)
@@ -216,7 +217,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
func toPresentable() -> AnyView { func toPresentable() -> AnyView {
AnyView(navigationRootCoordinator.toPresentable() AnyView(navigationRootCoordinator.toPresentable()
.environment(\.analyticsService, ServiceLocator.shared.analytics) .environment(\.analyticsService, analyticsService)
.onReceive(appSettings.$appAppearance) { [weak self] appAppearance in .onReceive(appSettings.$appAppearance) { [weak self] appAppearance in
guard let self else { return } guard let self else { return }
@@ -370,7 +371,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
func windowManagerDidConfigureWindows(_ windowManager: SecureWindowManagerProtocol) { func windowManagerDidConfigureWindows(_ windowManager: SecureWindowManagerProtocol) {
windowManager.alternateWindow.rootViewController = UIHostingController(rootView: appLockFlowCoordinator.toPresentable()) windowManager.alternateWindow.rootViewController = UIHostingController(rootView: appLockFlowCoordinator.toPresentable())
ServiceLocator.shared.userIndicatorController.window = windowManager.overlayWindow userIndicatorController.window = windowManager.overlayWindow
} }
// MARK: - NotificationManagerDelegate // MARK: - NotificationManagerDelegate
@@ -414,7 +415,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
handleAppRoute(.thread(roomID: roomID, threadRootEventID: threadRootEventID, focusEventID: eventID), windowType: nil) handleAppRoute(.thread(roomID: roomID, threadRootEventID: threadRootEventID, focusEventID: eventID), windowType: nil)
} else if let eventID { } else if let eventID {
// Only track main timeline event deeplinking // 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) handleAppRoute(.event(eventID: eventID, roomID: roomID, via: []), windowType: nil)
} else { } else {
handleAppRoute(.room(roomID: roomID, via: []), windowType: nil) handleAppRoute(.room(roomID: roomID, via: []), windowType: nil)
@@ -665,8 +666,8 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
appMediator: appMediator, appMediator: appMediator,
appSettings: appSettings, appSettings: appSettings,
appHooks: appHooks, appHooks: appHooks,
analytics: ServiceLocator.shared.analytics, analytics: analyticsService,
userIndicatorController: ServiceLocator.shared.userIndicatorController) userIndicatorController: userIndicatorController)
coordinator.delegate = self coordinator.delegate = self
authenticationFlowCoordinator = coordinator authenticationFlowCoordinator = coordinator
@@ -721,7 +722,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
appMediator: appMediator, appMediator: appMediator,
appSettings: appSettings, appSettings: appSettings,
appHooks: appHooks, appHooks: appHooks,
userIndicatorController: ServiceLocator.shared.userIndicatorController) userIndicatorController: userIndicatorController)
let coordinator = SoftLogoutScreenCoordinator(parameters: parameters) let coordinator = SoftLogoutScreenCoordinator(parameters: parameters)
self.softLogoutCoordinator = coordinator self.softLogoutCoordinator = coordinator
coordinator.actions coordinator.actions
@@ -750,24 +751,24 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
} }
if let serverName = userSession.clientProxy.userIDServerName { if let serverName = userSession.clientProxy.userIDServerName {
ServiceLocator.shared.analytics.signpost.addGlobalTag(.homeserver, value: serverName) analyticsService.signpost.addGlobalTag(.homeserver, value: serverName)
} }
if !isNewLogin { if !isNewLogin {
ServiceLocator.shared.analytics.signpost.startTransaction(.cachedRoomList) analyticsService.signpost.startTransaction(.cachedRoomList)
} }
let flowParameters = CommonFlowParameters(userSession: userSession, let flowParameters = CommonFlowParameters(userSession: userSession,
bugReportService: bugReportService, bugReportService: bugReportService,
elementCallService: elementCallService, elementCallService: elementCallService,
timelineControllerFactory: TimelineControllerFactory(), timelineControllerFactory: TimelineControllerFactory(appSettings: appSettings),
emojiProvider: EmojiProvider(appSettings: appSettings), emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(), linkMetadataProvider: LinkMetadataProvider(),
appMediator: appMediator, appMediator: appMediator,
appSettings: appSettings, appSettings: appSettings,
appHooks: appHooks, appHooks: appHooks,
analytics: ServiceLocator.shared.analytics, analytics: analyticsService,
userIndicatorController: ServiceLocator.shared.userIndicatorController, userIndicatorController: userIndicatorController,
notificationManager: notificationManager, notificationManager: notificationManager,
stateMachineFactory: StateMachineFactory()) stateMachineFactory: StateMachineFactory())
@@ -837,8 +838,8 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
appHooks.remoteSettingsHook.reset(appSettings) appHooks.remoteSettingsHook.reset(appSettings)
// Reset analytics // Reset analytics
ServiceLocator.shared.analytics.optOut() analyticsService.optOut()
ServiceLocator.shared.analytics.resetConsentState() analyticsService.resetConsentState()
stateMachine.processEvent(.completedSigningOut) stateMachine.processEvent(.completedSigningOut)
@@ -847,7 +848,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
} }
private func tearDownUserSession() { private func tearDownUserSession() {
ServiceLocator.shared.userIndicatorController.retractAllIndicators() userIndicatorController.retractAllIndicators()
userSession = nil 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 } guard let bugReportSentryURL = appSettings.bugReportSentryURL else { return }
let options: Options = .init() 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 // 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. // 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 SentrySDK.start(options: options) // Swift
enableSentryLogging(enabled: options.enabled) // Rust enableSentryLogging(enabled: options.enabled) // Rust
@@ -1043,18 +1044,18 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
private static let loadingIndicatorIdentifier = "\(AppCoordinator.self)-Loading" private static let loadingIndicatorIdentifier = "\(AppCoordinator.self)-Loading"
private func showLoadingIndicator() { private func showLoadingIndicator() {
ServiceLocator.shared.userIndicatorController.submitIndicator(UserIndicator(id: Self.loadingIndicatorIdentifier, userIndicatorController.submitIndicator(UserIndicator(id: Self.loadingIndicatorIdentifier,
type: .modal, type: .modal,
title: L10n.commonLoading, title: L10n.commonLoading,
persistent: true)) persistent: true))
} }
private func hideLoadingIndicator() { private func hideLoadingIndicator() {
ServiceLocator.shared.userIndicatorController.retractIndicatorWithId(Self.loadingIndicatorIdentifier) userIndicatorController.retractIndicatorWithId(Self.loadingIndicatorIdentifier)
} }
private func showLoginErrorToast() { private func showLoginErrorToast() {
ServiceLocator.shared.userIndicatorController.submitIndicator(UserIndicator(title: "Failed logging in")) userIndicatorController.submitIndicator(UserIndicator(title: "Failed logging in"))
} }
// MARK: - Application State // MARK: - Application State
@@ -1074,7 +1075,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
private func startSync() { private func startSync() {
guard let userSession else { return } guard let userSession else { return }
ServiceLocator.shared.analytics.signpost.startTransaction(.upToDateRoomList) analyticsService.signpost.startTransaction(.upToDateRoomList)
userSession.clientProxy.startSync() userSession.clientProxy.startSync()
@@ -1089,16 +1090,17 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
.receive(on: DispatchQueue.main) .receive(on: DispatchQueue.main)
.sink { [weak self] state in .sink { [weak self] state in
let toastIdentifier = "StaleDataIndicator" let toastIdentifier = "StaleDataIndicator"
guard let self else { return }
switch state { switch state {
case .loading: case .loading:
if self?.userSession?.clientProxy.homeserverReachabilityPublisher.value == .reachable, if self.userSession?.clientProxy.homeserverReachabilityPublisher.value == .reachable,
self?.appMediator.networkMonitor.reachabilityPublisher.value == .reachable { self.appMediator.networkMonitor.reachabilityPublisher.value == .reachable {
ServiceLocator.shared.userIndicatorController.submitIndicator(.init(id: toastIdentifier, type: .toast(progress: .indeterminate), title: L10n.commonSyncing, persistent: true)) self.userIndicatorController.submitIndicator(.init(id: toastIdentifier, type: .toast(progress: .indeterminate), title: L10n.commonSyncing, persistent: true))
} }
case .notLoading: case .notLoading:
ServiceLocator.shared.analytics.signpost.finishTransaction(.upToDateRoomList) self.analyticsService.signpost.finishTransaction(.upToDateRoomList)
ServiceLocator.shared.userIndicatorController.retractIndicatorWithId(toastIdentifier) 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 { func body(content: Content) -> some View {
content content
.onAppear { .onAppear {
analyticsService.track(screen: screen) analyticsService?.track(screen: screen)
} }
} }
} }
@@ -56,7 +56,7 @@ private struct VisualListItemLabelStyle: LabelStyle {
// MARK: - Previews // MARK: - Previews
struct VisualListItem_Previews: PreviewProvider, TestablePreview { 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 { static var testImage1: some View {
Image(systemName: "circle") Image(systemName: "circle")
@@ -158,11 +158,14 @@ struct LoginScreen_Previews: PreviewProvider, TestablePreview {
Task { await authenticationService.configure(for: homeserverAddress, flow: .login) } Task { await authenticationService.configure(for: homeserverAddress, flow: .login) }
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
let viewModel = LoginScreenViewModel(authenticationService: authenticationService, let viewModel = LoginScreenViewModel(authenticationService: authenticationService,
loginHint: nil, loginHint: nil,
userIndicatorController: UserIndicatorControllerMock(), userIndicatorController: UserIndicatorControllerMock(),
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
analytics: ServiceLocator.shared.analytics) analytics: analytics)
if withCredentials { if withCredentials {
viewModel.context.username = "alice" viewModel.context.username = "alice"
@@ -163,7 +163,7 @@ struct ServerConfirmationScreen_Previews: PreviewProvider, TestablePreview {
ServerConfirmationScreenViewModel(authenticationService: AuthenticationService.mock, ServerConfirmationScreenViewModel(authenticationService: AuthenticationService.mock,
mode: mode, mode: mode,
authenticationFlow: flow, authenticationFlow: flow,
appSettings: ServiceLocator.shared.settings, appSettings: AppSettings(),
userIndicatorController: UserIndicatorControllerMock()) userIndicatorController: UserIndicatorControllerMock.default)
} }
} }
@@ -116,8 +116,8 @@ struct ServerSelection_Previews: PreviewProvider, TestablePreview {
let viewModel = ServerSelectionScreenViewModel(authenticationService: authenticationService, let viewModel = ServerSelectionScreenViewModel(authenticationService: authenticationService,
authenticationFlow: .login, authenticationFlow: .login,
appSettings: ServiceLocator.shared.settings, appSettings: AppSettings(),
userIndicatorController: UserIndicatorControllerMock()) userIndicatorController: UserIndicatorControllerMock.default)
viewModel.context.homeserverAddress = homeserverAddress viewModel.context.homeserverAddress = homeserverAddress
if homeserverAddress == "thisisbad" { if homeserverAddress == "thisisbad" {
viewModel.context.send(viewAction: .confirm) viewModel.context.send(viewAction: .confirm)
@@ -151,7 +151,7 @@ struct AuthenticationClassicAppAccountView_Previews: PreviewProvider { // Not Te
provisioningParameters: nil, provisioningParameters: nil,
isBugReportServiceEnabled: false, isBugReportServiceEnabled: false,
appMediator: AppMediatorMock(), appMediator: AppMediatorMock(),
appSettings: ServiceLocator.shared.settings, appSettings: AppSettings(),
mediaProvider: MediaProviderMock(configuration: .init()), mediaProvider: MediaProviderMock(configuration: .init()),
userIndicatorController: UserIndicatorControllerMock()) userIndicatorController: UserIndicatorControllerMock())
} }
@@ -195,7 +195,7 @@ struct AuthenticationStartScreen_Previews: PreviewProvider, TestablePreview {
provisioningParameters: provisionedServerName.map { .init(accountProvider: $0, loginHint: nil) }, provisioningParameters: provisionedServerName.map { .init(accountProvider: $0, loginHint: nil) },
isBugReportServiceEnabled: true, isBugReportServiceEnabled: true,
appMediator: AppMediatorMock(), appMediator: AppMediatorMock(),
appSettings: ServiceLocator.shared.settings, appSettings: AppSettings(),
mediaProvider: MediaProviderMock(configuration: .init()), mediaProvider: MediaProviderMock(configuration: .init()),
userIndicatorController: UserIndicatorControllerMock()) userIndicatorController: UserIndicatorControllerMock())
} }
@@ -364,6 +364,9 @@ struct CallScreen_Previews: PreviewProvider {
roomProxy.elementCallWidgetDriverDeviceIDReturnValue = widgetDriver roomProxy.elementCallWidgetDriverDeviceIDReturnValue = widgetDriver
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
return CallScreenViewModel(elementCallService: ElementCallServiceMock(.init()), return CallScreenViewModel(elementCallService: ElementCallServiceMock(.init()),
configuration: .init(roomProxy: roomProxy, configuration: .init(roomProxy: roomProxy,
clientProxy: clientProxy, clientProxy: clientProxy,
@@ -374,8 +377,8 @@ struct CallScreen_Previews: PreviewProvider {
colorScheme: .light), colorScheme: .light),
allowPictureInPicture: false, allowPictureInPicture: false,
appHooks: AppHooks(), appHooks: AppHooks(),
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
analyticsService: ServiceLocator.shared.analytics) analyticsService: analytics)
}() }()
static var previews: some View { static var previews: some View {
@@ -227,8 +227,8 @@ struct PollFormScreen_Previews: PreviewProvider, TestablePreview {
static func makeViewModel(mode: PollFormMode) -> PollFormScreenViewModel { static func makeViewModel(mode: PollFormMode) -> PollFormScreenViewModel {
PollFormScreenViewModel(mode: mode, PollFormScreenViewModel(mode: mode,
timelineController: MockTimelineController(), timelineController: MockTimelineController(),
analytics: ServiceLocator.shared.analytics, analytics: .mock(),
userIndicatorController: UserIndicatorControllerMock()) userIndicatorController: UserIndicatorControllerMock.default)
} }
} }
@@ -461,8 +461,8 @@ struct CreateRoom_Previews: PreviewProvider, TestablePreview {
spaceSelectionMode: selectionMode, spaceSelectionMode: selectionMode,
shouldShowCancelButton: isSpace, shouldShowCancelButton: isSpace,
userSession: userSession, userSession: userSession,
analytics: ServiceLocator.shared.analytics, analytics: .mock(settings: appSettings),
userIndicatorController: UserIndicatorControllerMock(), userIndicatorController: UserIndicatorControllerMock.default,
appSettings: appSettings) appSettings: appSettings)
} }
} }
@@ -67,13 +67,16 @@ struct CreateRoomSpaceSelectionSheet_Previews: PreviewProvider, TestablePreview
clientProxy.spaceService = SpaceServiceProxyMock(.init(editableSpaces: .mockJoinedSpaces2)) clientProxy.spaceService = SpaceServiceProxyMock(.init(editableSpaces: .mockJoinedSpaces2))
let userSession = UserSessionMock(.init(clientProxy: clientProxy)) let userSession = UserSessionMock(.init(clientProxy: clientProxy))
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
return CreateRoomScreenViewModel(isSpace: false, return CreateRoomScreenViewModel(isSpace: false,
spaceSelectionMode: .editableSpacesList(preSelectedSpace: nil), spaceSelectionMode: .editableSpacesList(preSelectedSpace: nil),
shouldShowCancelButton: false, shouldShowCancelButton: false,
userSession: userSession, userSession: userSession,
analytics: ServiceLocator.shared.analytics, analytics: analytics,
userIndicatorController: UserIndicatorControllerMock(), userIndicatorController: UserIndicatorControllerMock.default,
appSettings: ServiceLocator.shared.settings) appSettings: appSettings)
}() }()
static var previews: some View { static var previews: some View {
@@ -103,7 +103,7 @@ struct EmojiPickerScreen: View {
struct EmojiPickerScreen_Previews: PreviewProvider, TestablePreview { struct EmojiPickerScreen_Previews: PreviewProvider, TestablePreview {
static let viewModel = EmojiPickerScreenViewModel(itemID: .randomEvent, static let viewModel = EmojiPickerScreenViewModel(itemID: .randomEvent,
selectedEmojis: ["😀", "😄"], selectedEmojis: ["😀", "😄"],
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings), emojiProvider: EmojiProvider(appSettings: AppSettings()),
timelineController: MockTimelineController()) timelineController: MockTimelineController())
static var previews: some View { static var previews: some View {
@@ -116,7 +116,7 @@ struct EmojiPickerScreen_Previews: PreviewProvider, TestablePreview {
struct EmojiPickerScreenSheet_Previews: PreviewProvider { struct EmojiPickerScreenSheet_Previews: PreviewProvider {
static let viewModel = EmojiPickerScreenViewModel(itemID: .randomEvent, static let viewModel = EmojiPickerScreenViewModel(itemID: .randomEvent,
selectedEmojis: ["😀", "😄"], selectedEmojis: ["😀", "😄"],
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings), emojiProvider: EmojiProvider(appSettings: AppSettings()),
timelineController: MockTimelineController()) timelineController: MockTimelineController())
static var previews: some View { static var previews: some View {
@@ -59,10 +59,10 @@ struct RoomListFiltersEmptyStateView_Previews: PreviewProvider, TestablePreview
VStack(spacing: 24) { VStack(spacing: 24) {
ForEach(RoomListFilter.allCases) { filter in ForEach(RoomListFilter.allCases) { filter in
RoomListFiltersEmptyStateView(state: .init(activeFilters: [filter], RoomListFiltersEmptyStateView(state: .init(activeFilters: [filter],
appSettings: ServiceLocator.shared.settings)) appSettings: AppSettings()))
} }
RoomListFiltersEmptyStateView(state: .init(activeFilters: [.people, .favourites], RoomListFiltersEmptyStateView(state: .init(activeFilters: [.people, .favourites],
appSettings: ServiceLocator.shared.settings)) appSettings: AppSettings()))
} }
.padding(.bottom) .padding(.bottom)
.previewLayout(.sizeThatFits) .previewLayout(.sizeThatFits)
@@ -90,10 +90,10 @@ struct RoomListFiltersView: View {
struct RoomListFiltersView_Previews: PreviewProvider, TestablePreview { struct RoomListFiltersView_Previews: PreviewProvider, TestablePreview {
static var previews: some View { 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], RoomListFiltersView(state: .constant(.init(activeFilters: [.rooms, .favourites],
appSettings: ServiceLocator.shared.settings))) appSettings: AppSettings())))
RoomListFiltersView(state: .constant(.init(activeFilters: [.lowPriority], RoomListFiltersView(state: .constant(.init(activeFilters: [.lowPriority],
appSettings: ServiceLocator.shared.settings))) appSettings: AppSettings())))
} }
} }
@@ -222,11 +222,14 @@ struct HomeScreen_Previews: PreviewProvider, TestablePreview {
let userSession = UserSessionMock(.init(clientProxy: clientProxy)) let userSession = UserSessionMock(.init(clientProxy: clientProxy))
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
return HomeScreenViewModel(userSession: userSession, return HomeScreenViewModel(userSession: userSession,
selectedRoomPublisher: CurrentValueSubject<String?, Never>(nil).asCurrentValuePublisher(), selectedRoomPublisher: CurrentValueSubject<String?, Never>(nil).asCurrentValuePublisher(),
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
analyticsService: ServiceLocator.shared.analytics, analyticsService: analytics,
notificationManager: NotificationManagerMock(), notificationManager: NotificationManagerMock(),
userIndicatorController: ServiceLocator.shared.userIndicatorController) userIndicatorController: UserIndicatorControllerMock.default)
} }
} }
@@ -143,12 +143,14 @@ struct HomeScreenEmptyStateView_Previews: PreviewProvider, TestablePreview {
static let viewModel = { static let viewModel = {
let userSession = UserSessionMock(.init(clientProxy: ClientProxyMock(.init(userID: "@user:example.com", let userSession = UserSessionMock(.init(clientProxy: ClientProxyMock(.init(userID: "@user:example.com",
roomSummaryProvider: RoomSummaryProviderMock(.init(state: .loaded([]))))))) roomSummaryProvider: RoomSummaryProviderMock(.init(state: .loaded([])))))))
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
return HomeScreenViewModel(userSession: userSession, return HomeScreenViewModel(userSession: userSession,
selectedRoomPublisher: CurrentValueSubject<String?, Never>(nil).asCurrentValuePublisher(), selectedRoomPublisher: CurrentValueSubject<String?, Never>(nil).asCurrentValuePublisher(),
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
analyticsService: ServiceLocator.shared.analytics, analyticsService: analytics,
notificationManager: NotificationManagerMock(), notificationManager: NotificationManagerMock(),
userIndicatorController: ServiceLocator.shared.userIndicatorController) userIndicatorController: UserIndicatorControllerMock.default)
}() }()
} }
@@ -200,12 +200,15 @@ struct HomeScreenInviteCell_Previews: PreviewProvider, TestablePreview {
let userSession = UserSessionMock(.init(clientProxy: clientProxy)) let userSession = UserSessionMock(.init(clientProxy: clientProxy))
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
return HomeScreenViewModel(userSession: userSession, return HomeScreenViewModel(userSession: userSession,
selectedRoomPublisher: CurrentValueSubject<String?, Never>(nil).asCurrentValuePublisher(), selectedRoomPublisher: CurrentValueSubject<String?, Never>(nil).asCurrentValuePublisher(),
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
analyticsService: ServiceLocator.shared.analytics, analyticsService: analytics,
notificationManager: NotificationManagerMock(), notificationManager: NotificationManagerMock(),
userIndicatorController: ServiceLocator.shared.userIndicatorController) userIndicatorController: UserIndicatorControllerMock.default)
} }
} }
@@ -132,12 +132,15 @@ struct HomeScreenKnockedCell_Previews: PreviewProvider, TestablePreview {
let userSession = UserSessionMock(.init(clientProxy: clientProxy)) let userSession = UserSessionMock(.init(clientProxy: clientProxy))
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
return HomeScreenViewModel(userSession: userSession, return HomeScreenViewModel(userSession: userSession,
selectedRoomPublisher: CurrentValueSubject<String?, Never>(nil).asCurrentValuePublisher(), selectedRoomPublisher: CurrentValueSubject<String?, Never>(nil).asCurrentValuePublisher(),
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
analyticsService: ServiceLocator.shared.analytics, analyticsService: analytics,
notificationManager: NotificationManagerMock(), notificationManager: NotificationManagerMock(),
userIndicatorController: ServiceLocator.shared.userIndicatorController) userIndicatorController: UserIndicatorControllerMock.default)
} }
} }
@@ -121,11 +121,14 @@ struct HomeScreenRecoveryKeyConfirmationBanner_Previews: PreviewProvider, Testab
let userSession = UserSessionMock(.init(clientProxy: clientProxy)) let userSession = UserSessionMock(.init(clientProxy: clientProxy))
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
return HomeScreenViewModel(userSession: userSession, return HomeScreenViewModel(userSession: userSession,
selectedRoomPublisher: CurrentValueSubject<String?, Never>(nil).asCurrentValuePublisher(), selectedRoomPublisher: CurrentValueSubject<String?, Never>(nil).asCurrentValuePublisher(),
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
analyticsService: ServiceLocator.shared.analytics, analyticsService: analytics,
notificationManager: NotificationManagerMock(), notificationManager: NotificationManagerMock(),
userIndicatorController: ServiceLocator.shared.userIndicatorController) userIndicatorController: UserIndicatorControllerMock.default)
} }
} }
@@ -253,12 +253,15 @@ struct HomeScreenRoomCell_Previews: PreviewProvider, TestablePreview {
static func makeViewModel(roomSummaryProvider: RoomSummaryProviderProtocol) -> HomeScreenViewModel { static func makeViewModel(roomSummaryProvider: RoomSummaryProviderProtocol) -> HomeScreenViewModel {
let userSession = UserSessionMock(.init(clientProxy: ClientProxyMock(.init(userID: "John Doe", roomSummaryProvider: roomSummaryProvider)))) 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, return HomeScreenViewModel(userSession: userSession,
selectedRoomPublisher: CurrentValueSubject<String?, Never>(nil).asCurrentValuePublisher(), selectedRoomPublisher: CurrentValueSubject<String?, Never>(nil).asCurrentValuePublisher(),
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
analyticsService: ServiceLocator.shared.analytics, analyticsService: analytics,
notificationManager: NotificationManagerMock(), notificationManager: NotificationManagerMock(),
userIndicatorController: ServiceLocator.shared.userIndicatorController) userIndicatorController: UserIndicatorControllerMock.default)
} }
static func makeRoom(lastMessageState: RoomSummary.LastMessageState) -> HomeScreenRoom { static func makeRoom(lastMessageState: RoomSummary.LastMessageState) -> HomeScreenRoom {
@@ -65,7 +65,7 @@ struct InviteUsersConfirmationSheetView_Previews: PreviewProvider, TestablePrevi
isSkippable: true, isSkippable: true,
userDiscoveryService: UserDiscoveryServiceMock(), userDiscoveryService: UserDiscoveryServiceMock(),
userIndicatorController: UserIndicatorControllerMock(), userIndicatorController: UserIndicatorControllerMock(),
appSettings: ServiceLocator.shared.settings) appSettings: AppSettings())
viewModel.state.usersToConfirm = [.mockAlice, .mockCharlie, .mockBob, .mockDan] viewModel.state.usersToConfirm = [.mockAlice, .mockCharlie, .mockBob, .mockDan]
@@ -193,7 +193,7 @@ struct InviteUsersScreen_Previews: PreviewProvider, TestablePreview {
isSkippable: true, isSkippable: true,
userDiscoveryService: userDiscoveryService, userDiscoveryService: userDiscoveryService,
userIndicatorController: UserIndicatorControllerMock(), userIndicatorController: UserIndicatorControllerMock(),
appSettings: ServiceLocator.shared.settings) appSettings: AppSettings())
if let searchQuery { if let searchQuery {
viewModel.context.searchQuery = searchQuery viewModel.context.searchQuery = searchQuery
@@ -458,7 +458,7 @@ struct JoinRoomScreenPreviewWrapper: Identifiable {
viewModel = JoinRoomScreenViewModel(source: source, viewModel = JoinRoomScreenViewModel(source: source,
appSettings: appSettings, appSettings: appSettings,
userSession: UserSessionMock(.init(clientProxy: clientProxy)), userSession: UserSessionMock(.init(clientProxy: clientProxy)),
userIndicatorController: ServiceLocator.shared.userIndicatorController) userIndicatorController: UserIndicatorControllerMock.default)
} }
var previewDisplayName: String { var previewDisplayName: String {
@@ -389,12 +389,15 @@ extension LocationSharingScreenViewModel {
let roomProxy = JoinedRoomProxyMock(.init(members: .allMembers, ownUserID: RoomMemberProxyMock.mockMe.userID)) let roomProxy = JoinedRoomProxyMock(.init(members: .allMembers, ownUserID: RoomMemberProxyMock.mockMe.userID))
roomProxy.makeLiveLocationServiceReturnValue = liveLocationServiceMock roomProxy.makeLiveLocationServiceReturnValue = liveLocationServiceMock
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
return LocationSharingScreenViewModel(interactionMode: interactionMode, return LocationSharingScreenViewModel(interactionMode: interactionMode,
mapURLBuilder: ServiceLocator.shared.settings.mapTilerConfiguration, mapURLBuilder: appSettings.mapTilerConfiguration,
roomProxy: roomProxy, roomProxy: roomProxy,
timelineController: MockTimelineController(), timelineController: MockTimelineController(),
liveLocationManager: LiveLocationManagerMock(), liveLocationManager: LiveLocationManagerMock(),
analytics: ServiceLocator.shared.analytics, analytics: analytics,
userIndicatorController: UserIndicatorControllerMock(), userIndicatorController: UserIndicatorControllerMock(),
mediaProvider: MediaProviderMock(configuration: .init())) mediaProvider: MediaProviderMock(configuration: .init()))
} }
@@ -120,7 +120,7 @@ private extension ManageRoomMemberSheetViewModel {
ownPowerLevel: powerLevel), ownPowerLevel: powerLevel),
roomProxy: JoinedRoomProxyMock(.init()), roomProxy: JoinedRoomProxyMock(.init()),
userIndicatorController: UserIndicatorControllerMock(), userIndicatorController: UserIndicatorControllerMock(),
analyticsService: ServiceLocator.shared.analytics, analyticsService: .mock(),
mediaProvider: MediaProviderMock(configuration: .init())) mediaProvider: MediaProviderMock(configuration: .init()))
} }
} }
@@ -310,15 +310,18 @@ struct MediaEventsTimelineScreen_Previews: PreviewProvider, TestablePreview {
MockTimelineController.mediaGallery MockTimelineController.mediaGallery
} }
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
return TimelineViewModel(roomProxy: JoinedRoomProxyMock(.init(name: "Preview room")), return TimelineViewModel(roomProxy: JoinedRoomProxyMock(.init(name: "Preview room")),
timelineController: timelineController, timelineController: timelineController,
userSession: UserSessionMock(.init()), userSession: UserSessionMock(.init()),
mediaPlayerProvider: MediaPlayerProviderMock(), mediaPlayerProvider: MediaPlayerProviderMock(),
userIndicatorController: UserIndicatorControllerMock(), userIndicatorController: UserIndicatorControllerMock(),
appMediator: AppMediatorMock.default, appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
analyticsService: ServiceLocator.shared.analytics, analyticsService: analytics,
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings), emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(), linkMetadataProvider: LinkMetadataProvider(),
timelineControllerFactory: TimelineControllerFactoryMock(.init())) timelineControllerFactory: TimelineControllerFactoryMock(.init()))
} }
@@ -370,7 +370,7 @@ struct MediaUploadPreviewScreen_Previews: PreviewProvider, TestablePreview {
title: "App Icon.png", title: "App Icon.png",
isRoomEncrypted: true, isRoomEncrypted: true,
shouldShowCaptionWarning: true, shouldShowCaptionWarning: true,
mediaUploadingPreprocessor: MediaUploadingPreprocessor(appSettings: ServiceLocator.shared.settings), mediaUploadingPreprocessor: MediaUploadingPreprocessor(appSettings: AppSettings()),
timelineController: MockTimelineController(), timelineController: MockTimelineController(),
clientProxy: ClientProxyMock(.init()), clientProxy: ClientProxyMock(.init()),
userIndicatorController: UserIndicatorControllerMock.default) userIndicatorController: UserIndicatorControllerMock.default)
@@ -102,6 +102,6 @@ struct AnalyticsPromptScreen_Previews: PreviewProvider, TestablePreview {
} }
static func makeViewModel(showTerms: Bool = true) -> AnalyticsPromptScreenViewModel { 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)) userSession.sessionSecurityStatePublisher = CurrentValuePublisher<SessionSecurityState, Never>(.init(verificationState: .unverified, recoveryState: recoveryState))
return IdentityConfirmationScreenViewModel(userSession: userSession, return IdentityConfirmationScreenViewModel(userSession: userSession,
appSettings: ServiceLocator.shared.settings, appSettings: AppSettings(),
userIndicatorController: ServiceLocator.shared.userIndicatorController) userIndicatorController: UserIndicatorControllerMock.default)
} }
} }
@@ -69,20 +69,24 @@ struct PinnedEventsTimelineScreen_Previews: PreviewProvider, TestablePreview {
static let viewModel = PinnedEventsTimelineScreenViewModel(roomProxy: JoinedRoomProxyMock(.init()), static let viewModel = PinnedEventsTimelineScreenViewModel(roomProxy: JoinedRoomProxyMock(.init()),
userIndicatorController: UserIndicatorControllerMock(), userIndicatorController: UserIndicatorControllerMock(),
appSettings: AppSettings(), appSettings: AppSettings(),
analyticsService: ServiceLocator.shared.analytics) analyticsService: .mock())
static let emptyTimelineViewModel: TimelineViewModel = { static let emptyTimelineViewModel: TimelineViewModel = {
let timelineController = MockTimelineController(timelineKind: .pinned) let timelineController = MockTimelineController(timelineKind: .pinned)
timelineController.timelineItems = [] timelineController.timelineItems = []
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
return TimelineViewModel(roomProxy: JoinedRoomProxyMock(.init(name: "Preview room")), return TimelineViewModel(roomProxy: JoinedRoomProxyMock(.init(name: "Preview room")),
timelineController: timelineController, timelineController: timelineController,
userSession: UserSessionMock(.init()), userSession: UserSessionMock(.init()),
mediaPlayerProvider: MediaPlayerProviderMock(), mediaPlayerProvider: MediaPlayerProviderMock(),
userIndicatorController: UserIndicatorControllerMock(), userIndicatorController: UserIndicatorControllerMock(),
appMediator: AppMediatorMock.default, appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
analyticsService: ServiceLocator.shared.analytics, analyticsService: analytics,
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings), emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(), linkMetadataProvider: LinkMetadataProvider(),
timelineControllerFactory: TimelineControllerFactoryMock(.init())) timelineControllerFactory: TimelineControllerFactoryMock(.init()))
}() }()
@@ -91,6 +91,6 @@ struct RoomChangePermissionsScreen_Previews: PreviewProvider, TestablePreview {
ownPowerLevel: ownPowerLevel, ownPowerLevel: ownPowerLevel,
roomProxy: JoinedRoomProxyMock(.init(isSpace: isSpace)), roomProxy: JoinedRoomProxyMock(.init(isSpace: isSpace)),
userIndicatorController: UserIndicatorControllerMock(), userIndicatorController: UserIndicatorControllerMock(),
analytics: ServiceLocator.shared.analytics) analytics: .mock())
} }
} }
@@ -151,6 +151,6 @@ struct RoomChangeRolesScreen_Previews: PreviewProvider, TestablePreview {
roomProxy: JoinedRoomProxyMock(.init(members: members)), roomProxy: JoinedRoomProxyMock(.init(members: members)),
mediaProvider: MediaProviderMock(configuration: .init()), mediaProvider: MediaProviderMock(configuration: .init()),
userIndicatorController: UserIndicatorControllerMock(), userIndicatorController: UserIndicatorControllerMock(),
analytics: ServiceLocator.shared.analytics) analytics: .mock())
} }
} }
@@ -177,7 +177,7 @@ struct RoomDetailsEditScreen_Previews: PreviewProvider, TestablePreview {
return RoomDetailsEditScreenViewModel(roomProxy: roomProxy, return RoomDetailsEditScreenViewModel(roomProxy: roomProxy,
userSession: UserSessionMock(.init()), userSession: UserSessionMock(.init()),
mediaUploadingPreprocessor: MediaUploadingPreprocessor(appSettings: ServiceLocator.shared.settings), mediaUploadingPreprocessor: MediaUploadingPreprocessor(appSettings: AppSettings()),
userIndicatorController: UserIndicatorControllerMock.default) userIndicatorController: UserIndicatorControllerMock.default)
} }
} }
@@ -406,13 +406,16 @@ struct RoomDetailsScreen_Previews: PreviewProvider, TestablePreview {
let notificationSettingsProxy = NotificationSettingsProxyMock(with: notificationSettingsProxyMockConfiguration) let notificationSettingsProxy = NotificationSettingsProxyMock(with: notificationSettingsProxyMockConfiguration)
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
return .init(roomProxy: roomProxy, return .init(roomProxy: roomProxy,
userSession: UserSessionMock(.init()), userSession: UserSessionMock(.init()),
analyticsService: ServiceLocator.shared.analytics, analyticsService: analytics,
userIndicatorController: ServiceLocator.shared.userIndicatorController, userIndicatorController: UserIndicatorControllerMock.default,
notificationSettingsProxy: notificationSettingsProxy, notificationSettingsProxy: notificationSettingsProxy,
attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()), attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()),
appSettings: ServiceLocator.shared.settings) appSettings: appSettings)
} }
private static func makeSimpleRoomViewModel() -> RoomDetailsScreenViewModel { private static func makeSimpleRoomViewModel() -> RoomDetailsScreenViewModel {
@@ -434,13 +437,16 @@ struct RoomDetailsScreen_Previews: PreviewProvider, TestablePreview {
let notificationSettingsProxy = NotificationSettingsProxyMock(with: .init()) let notificationSettingsProxy = NotificationSettingsProxyMock(with: .init())
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
return .init(roomProxy: roomProxy, return .init(roomProxy: roomProxy,
userSession: UserSessionMock(.init()), userSession: UserSessionMock(.init()),
analyticsService: ServiceLocator.shared.analytics, analyticsService: analytics,
userIndicatorController: ServiceLocator.shared.userIndicatorController, userIndicatorController: UserIndicatorControllerMock.default,
notificationSettingsProxy: notificationSettingsProxy, notificationSettingsProxy: notificationSettingsProxy,
attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()), attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()),
appSettings: ServiceLocator.shared.settings) appSettings: appSettings)
} }
private static func makeDMViewModel(verificationState: UserIdentityVerificationState) -> RoomDetailsScreenViewModel { private static func makeDMViewModel(verificationState: UserIdentityVerificationState) -> RoomDetailsScreenViewModel {
@@ -472,12 +478,15 @@ struct RoomDetailsScreen_Previews: PreviewProvider, TestablePreview {
let notificationSettingsProxy = NotificationSettingsProxyMock(with: .init()) let notificationSettingsProxy = NotificationSettingsProxyMock(with: .init())
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
return .init(roomProxy: roomProxy, return .init(roomProxy: roomProxy,
userSession: UserSessionMock(.init(clientProxy: clientProxyMock)), userSession: UserSessionMock(.init(clientProxy: clientProxyMock)),
analyticsService: ServiceLocator.shared.analytics, analyticsService: analytics,
userIndicatorController: ServiceLocator.shared.userIndicatorController, userIndicatorController: UserIndicatorControllerMock.default,
notificationSettingsProxy: notificationSettingsProxy, notificationSettingsProxy: notificationSettingsProxy,
attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()), attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()),
appSettings: ServiceLocator.shared.settings) appSettings: appSettings)
} }
} }
@@ -236,11 +236,14 @@ struct RoomMemberDetailsScreen_Previews: PreviewProvider, TestablePreview {
clientProxyMock.directRoomForUserIDReturnValue = .success("roomID") clientProxyMock.directRoomForUserIDReturnValue = .success("roomID")
} }
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
return RoomMemberDetailsScreenViewModel(userID: member.userID, return RoomMemberDetailsScreenViewModel(userID: member.userID,
roomProxy: roomProxyMock, roomProxy: roomProxyMock,
userSession: UserSessionMock(.init(clientProxy: clientProxyMock)), userSession: UserSessionMock(.init(clientProxy: clientProxyMock)),
userIndicatorController: ServiceLocator.shared.userIndicatorController, userIndicatorController: UserIndicatorControllerMock.default,
analytics: ServiceLocator.shared.analytics, analytics: analytics,
appSettings: ServiceLocator.shared.settings) appSettings: appSettings)
} }
} }
@@ -261,7 +261,7 @@ struct RoomMembersListScreen_Previews: PreviewProvider, TestablePreview {
members: members, members: members,
ownUserID: ownUserID, ownUserID: ownUserID,
powerLevelsConfiguration: .init(canUserInvite: false))), powerLevelsConfiguration: .init(canUserInvite: false))),
userIndicatorController: ServiceLocator.shared.userIndicatorController, userIndicatorController: UserIndicatorControllerMock.default,
analytics: ServiceLocator.shared.analytics) analytics: .mock())
} }
} }
@@ -131,8 +131,8 @@ struct RoomMembersListMemberCell_Previews: PreviewProvider, TestablePreview {
static let viewModel = RoomMembersListScreenViewModel(userSession: UserSessionMock(.init()), static let viewModel = RoomMembersListScreenViewModel(userSession: UserSessionMock(.init()),
roomProxy: JoinedRoomProxyMock(.init(name: "Some room", members: [])), roomProxy: JoinedRoomProxyMock(.init(name: "Some room", members: [])),
userIndicatorController: ServiceLocator.shared.userIndicatorController, userIndicatorController: UserIndicatorControllerMock.default,
analytics: ServiceLocator.shared.analytics) analytics: .mock())
static var previews: some View { static var previews: some View {
VStack(spacing: 0) { VStack(spacing: 0) {
Section("Invited/Joined") { Section("Invited/Joined") {
@@ -121,12 +121,12 @@ struct RoomRolesAndPermissionsScreen_Previews: PreviewProvider, TestablePreview
static let viewModel = RoomRolesAndPermissionsScreenViewModel(initialPermissions: RoomPermissions(powerLevels: .mock), static let viewModel = RoomRolesAndPermissionsScreenViewModel(initialPermissions: RoomPermissions(powerLevels: .mock),
roomProxy: JoinedRoomProxyMock(.init(members: .allMembersAsAdmin)), roomProxy: JoinedRoomProxyMock(.init(members: .allMembersAsAdmin)),
userIndicatorController: UserIndicatorControllerMock(), userIndicatorController: UserIndicatorControllerMock(),
analytics: ServiceLocator.shared.analytics) analytics: .mock())
static let creatorViewModel = RoomRolesAndPermissionsScreenViewModel(initialPermissions: RoomPermissions(powerLevels: .mock), static let creatorViewModel = RoomRolesAndPermissionsScreenViewModel(initialPermissions: RoomPermissions(powerLevels: .mock),
roomProxy: JoinedRoomProxyMock(.init(members: .allMembersAsCreator)), roomProxy: JoinedRoomProxyMock(.init(members: .allMembersAsCreator)),
userIndicatorController: UserIndicatorControllerMock(), userIndicatorController: UserIndicatorControllerMock(),
analytics: ServiceLocator.shared.analytics) analytics: .mock())
static var previews: some View { static var previews: some View {
ElementNavigationStack { ElementNavigationStack {
RoomRolesAndPermissionsScreen(context: viewModel.context) RoomRolesAndPermissionsScreen(context: viewModel.context)
@@ -820,14 +820,17 @@ extension ComposerToolbarViewModel {
roomProxy.identityStatusChangesPublisher = .init([.init(userId: RoomMemberProxyMock.mockAlice.userID, changedTo: .verificationViolation)]) roomProxy.identityStatusChangesPublisher = .init([.init(userId: RoomMemberProxyMock.mockAlice.userID, changedTo: .verificationViolation)])
} }
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
let wysiwygViewModel = WysiwygComposerViewModel() let wysiwygViewModel = WysiwygComposerViewModel()
let viewModel = ComposerToolbarViewModel(roomProxy: roomProxy, let viewModel = ComposerToolbarViewModel(roomProxy: roomProxy,
wysiwygViewModel: wysiwygViewModel, wysiwygViewModel: wysiwygViewModel,
completionSuggestionService: CompletionSuggestionServiceMock(configuration: .init(suggestions: suggestions)), completionSuggestionService: CompletionSuggestionServiceMock(configuration: .init(suggestions: suggestions)),
mediaProvider: MediaProviderMock(configuration: .init()), mediaProvider: MediaProviderMock(configuration: .init()),
mentionDisplayHelper: ComposerMentionDisplayHelper.mock, mentionDisplayHelper: ComposerMentionDisplayHelper.mock,
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
analyticsService: ServiceLocator.shared.analytics, analyticsService: analytics,
composerDraftService: ComposerDraftServiceMock(.init())) composerDraftService: ComposerDraftServiceMock(.init()))
viewModel.state.bindings.composerFocused = focused viewModel.state.bindings.composerFocused = focused
viewModel.state.bindings.plainComposerText = NSAttributedString(string: message) viewModel.state.bindings.plainComposerText = NSAttributedString(string: message)
@@ -78,14 +78,20 @@ struct RoomAttachmentPicker: View {
} }
struct RoomAttachmentPicker_Previews: PreviewProvider, TestablePreview { struct RoomAttachmentPicker_Previews: PreviewProvider, TestablePreview {
static let viewModel = ComposerToolbarViewModel(roomProxy: JoinedRoomProxyMock(.init()), static let viewModel = makeViewModel()
wysiwygViewModel: WysiwygComposerViewModel(),
completionSuggestionService: CompletionSuggestionServiceMock(configuration: .init()), static func makeViewModel() -> ComposerToolbarViewModel {
mediaProvider: MediaProviderMock(configuration: .init()), let appSettings = AppSettings()
mentionDisplayHelper: ComposerMentionDisplayHelper.mock,
appSettings: ServiceLocator.shared.settings, return ComposerToolbarViewModel(roomProxy: JoinedRoomProxyMock(.init()),
analyticsService: ServiceLocator.shared.analytics, wysiwygViewModel: WysiwygComposerViewModel(),
composerDraftService: ComposerDraftServiceMock(.init())) 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 { static var previews: some View {
RoomAttachmentPicker(context: viewModel.context) RoomAttachmentPicker(context: viewModel.context)
@@ -456,14 +456,17 @@ extension RoomScreenViewModel {
static func mock(roomProxyMock: JoinedRoomProxyMock, static func mock(roomProxyMock: JoinedRoomProxyMock,
clientProxyMock: ClientProxyMock = ClientProxyMock(.init()), clientProxyMock: ClientProxyMock = ClientProxyMock(.init()),
appHooks: AppHooks = AppHooks()) -> RoomScreenViewModel { appHooks: AppHooks = AppHooks()) -> RoomScreenViewModel {
RoomScreenViewModel(userSession: UserSessionMock(.init(clientProxy: clientProxyMock)), let appSettings = AppSettings()
roomProxy: roomProxyMock, let analytics = AnalyticsService.mock(settings: appSettings)
initialSelectedPinnedEventID: nil,
ongoingCallRoomIDPublisher: .init(.init(nil)), return RoomScreenViewModel(userSession: UserSessionMock(.init(clientProxy: clientProxyMock)),
appSettings: ServiceLocator.shared.settings, roomProxy: roomProxyMock,
appHooks: appHooks, initialSelectedPinnedEventID: nil,
analyticsService: ServiceLocator.shared.analytics, ongoingCallRoomIDPublisher: .init(.init(nil)),
userIndicatorController: ServiceLocator.shared.userIndicatorController) 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, successor: hasSuccessor ? .init(roomId: UUID().uuidString, reason: nil) : nil,
powerLevelsConfiguration: .init(canUserSendMessage: canSendMessage))) powerLevelsConfiguration: .init(canUserSendMessage: canSendMessage)))
let roomViewModel = RoomScreenViewModel.mock(roomProxyMock: roomProxyMock) let roomViewModel = RoomScreenViewModel.mock(roomProxyMock: roomProxyMock)
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
let timelineViewModel = TimelineViewModel(roomProxy: roomProxyMock, let timelineViewModel = TimelineViewModel(roomProxy: roomProxyMock,
timelineController: MockTimelineController(), timelineController: MockTimelineController(),
userSession: UserSessionMock(.init()), userSession: UserSessionMock(.init()),
mediaPlayerProvider: MediaPlayerProviderMock(), mediaPlayerProvider: MediaPlayerProviderMock(),
userIndicatorController: ServiceLocator.shared.userIndicatorController, userIndicatorController: UserIndicatorControllerMock.default,
appMediator: AppMediatorMock.default, appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
analyticsService: ServiceLocator.shared.analytics, analyticsService: analytics,
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings), emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(), linkMetadataProvider: LinkMetadataProvider(),
timelineControllerFactory: TimelineControllerFactoryMock(.init())) timelineControllerFactory: TimelineControllerFactoryMock(.init()))
@@ -162,10 +162,11 @@ private extension AppAppearance {
struct AdvancedSettingsScreen_Previews: PreviewProvider, TestablePreview { struct AdvancedSettingsScreen_Previews: PreviewProvider, TestablePreview {
static let viewModel = { static let viewModel = {
AppSettings.resetAllSettings() AppSettings.resetAllSettings()
return AdvancedSettingsScreenViewModel(advancedSettings: AppSettings(), let appSettings = AppSettings()
analytics: ServiceLocator.shared.analytics, return AdvancedSettingsScreenViewModel(advancedSettings: appSettings,
analytics: .mock(settings: appSettings),
clientProxy: ClientProxyMock(.init()), clientProxy: ClientProxyMock(.init()),
userIndicatorController: UserIndicatorControllerMock()) userIndicatorController: UserIndicatorControllerMock.default)
}() }()
static var previews: some View { static var previews: some View {
@@ -40,8 +40,9 @@ struct AnalyticsSettingsScreen: View {
struct AnalyticsSettingsScreen_Previews: PreviewProvider, TestablePreview { struct AnalyticsSettingsScreen_Previews: PreviewProvider, TestablePreview {
static var previews: some View { static var previews: some View {
let appSettings = AppSettings() let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
let viewModel = AnalyticsSettingsScreenViewModel(appSettings: appSettings, let viewModel = AnalyticsSettingsScreenViewModel(appSettings: appSettings,
analytics: ServiceLocator.shared.analytics) analytics: analytics)
AnalyticsSettingsScreen(context: viewModel.context) AnalyticsSettingsScreen(context: viewModel.context)
} }
} }
@@ -244,10 +244,11 @@ private extension Set<TraceLogPack> {
// MARK: - Previews // MARK: - Previews
struct DeveloperOptionsScreen_Previews: PreviewProvider { struct DeveloperOptionsScreen_Previews: PreviewProvider {
static let viewModel = DeveloperOptionsScreenViewModel(developerOptions: ServiceLocator.shared.settings, static let viewModel = DeveloperOptionsScreenViewModel(developerOptions: AppSettings(),
elementCallBaseURL: ServiceLocator.shared.settings.elementCallBaseURL, elementCallBaseURL: AppSettings().elementCallBaseURL,
appHooks: AppHooks(), appHooks: AppHooks(),
clientProxy: ClientProxyMock(.init())) clientProxy: ClientProxyMock(.init()))
static var previews: some View { static var previews: some View {
ElementNavigationStack { ElementNavigationStack {
DeveloperOptionsScreen(context: viewModel.context) DeveloperOptionsScreen(context: viewModel.context)
@@ -277,7 +277,7 @@ struct SettingsScreen_Previews: PreviewProvider, TestablePreview {
let userSession = UserSessionMock(.init(clientProxy: ClientProxyMock(.init(userID: "@userid:example.com", let userSession = UserSessionMock(.init(clientProxy: ClientProxyMock(.init(userID: "@userid:example.com",
deviceID: "AAAAAAAAAAA")))) deviceID: "AAAAAAAAAAA"))))
return SettingsScreenViewModel(userSession: userSession, return SettingsScreenViewModel(userSession: userSession,
appSettings: ServiceLocator.shared.settings, appSettings: AppSettings(),
isBugReportServiceEnabled: isBugReportServiceEnabled, isBugReportServiceEnabled: isBugReportServiceEnabled,
isInSecondaryWindow: false) isInSecondaryWindow: false)
} }
@@ -141,7 +141,7 @@ struct UserDetailsEditScreen_Previews: PreviewProvider, TestablePreview {
UserDetailsEditScreenViewModel(userSession: UserSessionMock(.init(clientProxy: ClientProxyMock(.init(userID: "@stefan:matrix.org", UserDetailsEditScreenViewModel(userSession: UserSessionMock(.init(clientProxy: ClientProxyMock(.init(userID: "@stefan:matrix.org",
canChangeAvatar: canChangeProfile, canChangeAvatar: canChangeProfile,
canChangeDisplayName: canChangeProfile)))), canChangeDisplayName: canChangeProfile)))),
mediaUploadingPreprocessor: .init(appSettings: ServiceLocator.shared.settings), mediaUploadingPreprocessor: .init(appSettings: AppSettings()),
userIndicatorController: UserIndicatorControllerMock.default) userIndicatorController: UserIndicatorControllerMock.default)
} }
} }
@@ -121,29 +121,26 @@ struct SpaceSettingsScreen: View {
// MARK: - Previews // MARK: - Previews
struct SpaceSettingsScreen_Previews: PreviewProvider, TestablePreview { struct SpaceSettingsScreen_Previews: PreviewProvider, TestablePreview {
static let ownerViewModel = RoomDetailsScreenViewModel(roomProxy: JoinedRoomProxyMock(.init(name: "Space", static let ownerViewModel = makeViewModel(members: .allMembersAsCreator)
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 userViewModel = RoomDetailsScreenViewModel(roomProxy: JoinedRoomProxyMock(.init(name: "Space", static let userViewModel = makeViewModel(members: .allMembers)
avatarURL: .mockMXCAvatar,
isSpace: true, static func makeViewModel(members: [RoomMemberProxyMock]) -> RoomDetailsScreenViewModel {
canonicalAlias: "#space:matrix.org", let appSettings = AppSettings()
members: .allMembers)), let analytics = AnalyticsService.mock(settings: appSettings)
userSession: UserSessionMock(.init()),
analyticsService: ServiceLocator.shared.analytics, return RoomDetailsScreenViewModel(roomProxy: JoinedRoomProxyMock(.init(name: "Space",
userIndicatorController: ServiceLocator.shared.userIndicatorController, avatarURL: .mockMXCAvatar,
notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()), isSpace: true,
attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()), canonicalAlias: "#space:matrix.org",
appSettings: ServiceLocator.shared.settings) 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 { static var previews: some View {
ElementNavigationStack { ElementNavigationStack {
@@ -82,11 +82,15 @@ struct JoinRoomByAddressView_Previews: PreviewProvider, TestablePreview {
let userSession = UserSessionMock(.init(clientProxy: ClientProxyMock(.init(userID: "@userid:example.com")))) let userSession = UserSessionMock(.init(clientProxy: ClientProxyMock(.init(userID: "@userid:example.com"))))
let userDiscoveryService = UserDiscoveryServiceMock() let userDiscoveryService = UserDiscoveryServiceMock()
userDiscoveryService.searchProfilesWithReturnValue = .success([.mockAlice]) userDiscoveryService.searchProfilesWithReturnValue = .success([.mockAlice])
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
return StartChatScreenViewModel(userSession: userSession, return StartChatScreenViewModel(userSession: userSession,
analytics: ServiceLocator.shared.analytics, analytics: analytics,
userIndicatorController: UserIndicatorControllerMock(), userIndicatorController: UserIndicatorControllerMock(),
userDiscoveryService: userDiscoveryService, userDiscoveryService: userDiscoveryService,
appSettings: ServiceLocator.shared.settings) appSettings: appSettings)
}() }()
static var previews: some View { static var previews: some View {
@@ -159,7 +159,7 @@ struct StartChatScreen_Previews: PreviewProvider, TestablePreview {
let userDiscoveryService = UserDiscoveryServiceMock() let userDiscoveryService = UserDiscoveryServiceMock()
userDiscoveryService.searchProfilesWithReturnValue = .success([.mockAlice]) userDiscoveryService.searchProfilesWithReturnValue = .success([.mockAlice])
return StartChatScreenViewModel(userSession: userSession, return StartChatScreenViewModel(userSession: userSession,
analytics: ServiceLocator.shared.analytics, analytics: .mock(settings: appSettings),
userIndicatorController: UserIndicatorControllerMock(), userIndicatorController: UserIndicatorControllerMock(),
userDiscoveryService: userDiscoveryService, userDiscoveryService: userDiscoveryService,
appSettings: appSettings) appSettings: appSettings)
@@ -1056,16 +1056,20 @@ extension TimelineViewModel {
clientProxyMock.roomSummaryForAliasReturnValue = .mock(id: "!room:matrix.org", name: "Room") clientProxyMock.roomSummaryForAliasReturnValue = .mock(id: "!room:matrix.org", name: "Room")
clientProxyMock.roomSummaryForIdentifierReturnValue = .mock(id: "!room:matrix.org", name: "Room", canonicalAlias: "#room:matrix.org") 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 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, return TimelineViewModel(roomProxy: roomProxy,
focussedEventID: nil, focussedEventID: nil,
timelineController: timelineController ?? MockTimelineController(timelineKind: timelineKind), timelineController: timelineController ?? MockTimelineController(timelineKind: timelineKind),
userSession: UserSessionMock(.init(clientProxy: clientProxyMock)), userSession: UserSessionMock(.init(clientProxy: clientProxyMock)),
mediaPlayerProvider: MediaPlayerProviderMock(), mediaPlayerProvider: MediaPlayerProviderMock(),
userIndicatorController: ServiceLocator.shared.userIndicatorController, userIndicatorController: UserIndicatorControllerMock.default,
appMediator: AppMediatorMock.default, appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
analyticsService: ServiceLocator.shared.analytics, analyticsService: analytics,
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings), emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(), linkMetadataProvider: LinkMetadataProvider(),
timelineControllerFactory: TimelineControllerFactoryMock(.init())) timelineControllerFactory: TimelineControllerFactoryMock(.init()))
} }
@@ -342,7 +342,7 @@ struct TimelineItemMenu_Previews: PreviewProvider, TestablePreview {
isViewSourceEnabled: true, isViewSourceEnabled: true,
areThreadsEnabled: true, areThreadsEnabled: true,
timelineKind: .live, timelineKind: .live,
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings)) emojiProvider: EmojiProvider(appSettings: AppSettings()))
guard let actions = provider.makeActions() else { return nil } guard let actions = provider.makeActions() else { return nil }
if var textItem = item as? TextRoomTimelineItem { if var textItem = item as? TextRoomTimelineItem {
@@ -44,15 +44,19 @@ struct ReadReceiptsSummaryView_Previews: PreviewProvider, TestablePreview {
.mockDan .mockDan
] ]
let roomProxyMock = JoinedRoomProxyMock(.init(name: "Room", members: members)) let roomProxyMock = JoinedRoomProxyMock(.init(name: "Room", members: members))
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
return TimelineViewModel(roomProxy: roomProxyMock, return TimelineViewModel(roomProxy: roomProxyMock,
timelineController: MockTimelineController(), timelineController: MockTimelineController(),
userSession: UserSessionMock(.init()), userSession: UserSessionMock(.init()),
mediaPlayerProvider: MediaPlayerProviderMock(), mediaPlayerProvider: MediaPlayerProviderMock(),
userIndicatorController: UserIndicatorControllerMock(), userIndicatorController: UserIndicatorControllerMock(),
appMediator: AppMediatorMock.default, appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
analyticsService: ServiceLocator.shared.analytics, analyticsService: analytics,
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings), emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(), linkMetadataProvider: LinkMetadataProvider(),
timelineControllerFactory: TimelineControllerFactoryMock(.init())) timelineControllerFactory: TimelineControllerFactoryMock(.init()))
}() }()
@@ -343,11 +343,11 @@ struct TimelineItemBubbledStylerView_Previews: PreviewProvider, TestablePreview
timelineController: MockTimelineController(), timelineController: MockTimelineController(),
userSession: UserSessionMock(.init()), userSession: UserSessionMock(.init()),
mediaPlayerProvider: MediaPlayerProviderMock(), mediaPlayerProvider: MediaPlayerProviderMock(),
userIndicatorController: ServiceLocator.shared.userIndicatorController, userIndicatorController: UserIndicatorControllerMock.default,
appMediator: AppMediatorMock.default, appMediator: AppMediatorMock.default,
appSettings: appSettings, appSettings: appSettings,
analyticsService: ServiceLocator.shared.analytics, analyticsService: .mock(settings: appSettings),
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings), emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(), linkMetadataProvider: LinkMetadataProvider(),
timelineControllerFactory: TimelineControllerFactoryMock(.init())) timelineControllerFactory: TimelineControllerFactoryMock(.init()))
}() }()
@@ -362,11 +362,11 @@ struct TimelineItemBubbledStylerView_Previews: PreviewProvider, TestablePreview
timelineController: MockTimelineController(), timelineController: MockTimelineController(),
userSession: UserSessionMock(.init()), userSession: UserSessionMock(.init()),
mediaPlayerProvider: MediaPlayerProviderMock(), mediaPlayerProvider: MediaPlayerProviderMock(),
userIndicatorController: ServiceLocator.shared.userIndicatorController, userIndicatorController: UserIndicatorControllerMock.default,
appMediator: AppMediatorMock.default, appMediator: AppMediatorMock.default,
appSettings: appSettings, appSettings: appSettings,
analyticsService: ServiceLocator.shared.analytics, analyticsService: .mock(settings: appSettings),
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings), emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(), linkMetadataProvider: LinkMetadataProvider(),
timelineControllerFactory: TimelineControllerFactoryMock(.init())) timelineControllerFactory: TimelineControllerFactoryMock(.init()))
}() }()
@@ -79,17 +79,22 @@ struct TimelineReadReceiptsView_Previews: PreviewProvider, TestablePreview {
.mockMe .mockMe
] ]
static let viewModel = TimelineViewModel(roomProxy: JoinedRoomProxyMock(.init(name: "Test", members: members)), static let viewModel = {
timelineController: MockTimelineController(), let appSettings = AppSettings()
userSession: UserSessionMock(.init()), let analytics = AnalyticsService.mock(settings: appSettings)
mediaPlayerProvider: MediaPlayerProviderMock(),
userIndicatorController: ServiceLocator.shared.userIndicatorController, return TimelineViewModel(roomProxy: JoinedRoomProxyMock(.init(name: "Test", members: members)),
appMediator: AppMediatorMock.default, timelineController: MockTimelineController(),
appSettings: ServiceLocator.shared.settings, userSession: UserSessionMock(.init()),
analyticsService: ServiceLocator.shared.analytics, mediaPlayerProvider: MediaPlayerProviderMock(),
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings), userIndicatorController: UserIndicatorControllerMock.default,
linkMetadataProvider: LinkMetadataProvider(), appMediator: AppMediatorMock.default,
timelineControllerFactory: TimelineControllerFactoryMock(.init())) 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 singleReceipt = [ReadReceipt(userID: RoomMemberProxyMock.mockAlice.userID, formattedTimestamp: "Now")]
static let doubleReceipt = [ReadReceipt(userID: RoomMemberProxyMock.mockAlice.userID, formattedTimestamp: "Now"), static let doubleReceipt = [ReadReceipt(userID: RoomMemberProxyMock.mockAlice.userID, formattedTimestamp: "Now"),
@@ -89,18 +89,23 @@ struct HighlightedTimelineItemTimeline_Previews: PreviewProvider {
static let roomViewModel = RoomScreenViewModel.mock(roomProxyMock: roomProxyMock) static let roomViewModel = RoomScreenViewModel.mock(roomProxyMock: roomProxyMock)
static let focussedEventID = "RoomTimelineItemFixtures.default.5" static let focussedEventID = "RoomTimelineItemFixtures.default.5"
static let composerViewModel = ComposerToolbarViewModel.mock() static let composerViewModel = ComposerToolbarViewModel.mock()
static let timelineViewModel = TimelineViewModel(roomProxy: roomProxyMock, static let timelineViewModel = {
focussedEventID: focussedEventID, let appSettings = AppSettings()
timelineController: MockTimelineController(), let analytics = AnalyticsService.mock(settings: appSettings)
userSession: UserSessionMock(.init()),
mediaPlayerProvider: MediaPlayerProviderMock(), return TimelineViewModel(roomProxy: roomProxyMock,
userIndicatorController: ServiceLocator.shared.userIndicatorController, focussedEventID: focussedEventID,
appMediator: AppMediatorMock.default, timelineController: MockTimelineController(),
appSettings: ServiceLocator.shared.settings, userSession: UserSessionMock(.init()),
analyticsService: ServiceLocator.shared.analytics, mediaPlayerProvider: MediaPlayerProviderMock(),
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings), userIndicatorController: UserIndicatorControllerMock.default,
linkMetadataProvider: LinkMetadataProvider(), appMediator: AppMediatorMock.default,
timelineControllerFactory: TimelineControllerFactoryMock(.init())) appSettings: appSettings,
analyticsService: analytics,
emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(),
timelineControllerFactory: TimelineControllerFactoryMock(.init()))
}()
static var previews: some View { static var previews: some View {
ElementNavigationStack { ElementNavigationStack {
@@ -146,17 +146,22 @@ struct TimelineView_Previews: PreviewProvider { // Not testable as this preview
name: "Preview room")) name: "Preview room"))
static let roomViewModel = RoomScreenViewModel.mock(roomProxyMock: roomProxyMock) static let roomViewModel = RoomScreenViewModel.mock(roomProxyMock: roomProxyMock)
static let composerViewModel = ComposerToolbarViewModel.mock() static let composerViewModel = ComposerToolbarViewModel.mock()
static let timelineViewModel = TimelineViewModel(roomProxy: roomProxyMock, static let timelineViewModel = {
timelineController: MockTimelineController(), let appSettings = AppSettings()
userSession: UserSessionMock(.init()), let analytics = AnalyticsService.mock(settings: appSettings)
mediaPlayerProvider: MediaPlayerProviderMock(),
userIndicatorController: ServiceLocator.shared.userIndicatorController, return TimelineViewModel(roomProxy: roomProxyMock,
appMediator: AppMediatorMock.default, timelineController: MockTimelineController(),
appSettings: ServiceLocator.shared.settings, userSession: UserSessionMock(.init()),
analyticsService: ServiceLocator.shared.analytics, mediaPlayerProvider: MediaPlayerProviderMock(),
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings), userIndicatorController: UserIndicatorControllerMock.default,
linkMetadataProvider: LinkMetadataProvider(), appMediator: AppMediatorMock.default,
timelineControllerFactory: TimelineControllerFactoryMock(.init())) appSettings: appSettings,
analyticsService: analytics,
emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(),
timelineControllerFactory: TimelineControllerFactoryMock(.init()))
}()
static var previews: some View { static var previews: some View {
ElementNavigationStack { ElementNavigationStack {
@@ -143,11 +143,14 @@ struct UserProfileScreen_Previews: PreviewProvider, TestablePreview {
clientProxyMock.directRoomForUserIDReturnValue = .success("roomID") clientProxyMock.directRoomForUserIDReturnValue = .success("roomID")
} }
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
return UserProfileScreenViewModel(userID: userID, return UserProfileScreenViewModel(userID: userID,
isPresentedModally: false, isPresentedModally: false,
userSession: UserSessionMock(.init(clientProxy: clientProxyMock)), userSession: UserSessionMock(.init(clientProxy: clientProxyMock)),
userIndicatorController: ServiceLocator.shared.userIndicatorController, userIndicatorController: UserIndicatorControllerMock.default,
analytics: ServiceLocator.shared.analytics, analytics: analytics,
appSettings: ServiceLocator.shared.settings) appSettings: appSettings)
} }
} }
@@ -9,5 +9,5 @@
import SwiftUI import SwiftUI
extension EnvironmentValues { extension EnvironmentValues {
@Entry var analyticsService: AnalyticsService = ServiceLocator.shared.analytics @Entry var analyticsService: AnalyticsService?
} }
@@ -388,7 +388,7 @@ extension AuthenticationService {
encryptionKeyProvider: EncryptionKeyProvider(), encryptionKeyProvider: EncryptionKeyProvider(),
classicAppManager: classicAppManager, classicAppManager: classicAppManager,
clientFactory: AuthenticationClientFactoryMock(configuration: .init()), clientFactory: AuthenticationClientFactoryMock(configuration: .init()),
appSettings: ServiceLocator.shared.settings, appSettings: AppSettings(),
appHooks: AppHooks()) appHooks: AppHooks())
} }
} }
@@ -10,6 +10,8 @@ import Foundation
import MatrixRustSDK import MatrixRustSDK
struct TimelineControllerFactory: TimelineControllerFactoryProtocol { struct TimelineControllerFactory: TimelineControllerFactoryProtocol {
let appSettings: AppSettings
func buildTimelineController(roomProxy: JoinedRoomProxyProtocol, func buildTimelineController(roomProxy: JoinedRoomProxyProtocol,
initialFocussedEventID: String?, initialFocussedEventID: String?,
timelineItemFactory: RoomTimelineItemFactoryProtocol, timelineItemFactory: RoomTimelineItemFactoryProtocol,
@@ -19,7 +21,7 @@ struct TimelineControllerFactory: TimelineControllerFactoryProtocol {
initialFocussedEventID: initialFocussedEventID, initialFocussedEventID: initialFocussedEventID,
timelineItemFactory: timelineItemFactory, timelineItemFactory: timelineItemFactory,
mediaProvider: mediaProvider, mediaProvider: mediaProvider,
appSettings: ServiceLocator.shared.settings) appSettings: appSettings)
} }
func buildThreadTimelineController(threadRootEventID: String, func buildThreadTimelineController(threadRootEventID: String,
@@ -34,7 +36,7 @@ struct TimelineControllerFactory: TimelineControllerFactoryProtocol {
initialFocussedEventID: initialFocussedEventID, initialFocussedEventID: initialFocussedEventID,
timelineItemFactory: timelineItemFactory, timelineItemFactory: timelineItemFactory,
mediaProvider: mediaProvider, mediaProvider: mediaProvider,
appSettings: ServiceLocator.shared.settings)) appSettings: appSettings))
case .failure(let error): case .failure(let error):
return .failure(.roomProxyError(error)) return .failure(.roomProxyError(error))
} }
@@ -50,7 +52,7 @@ struct TimelineControllerFactory: TimelineControllerFactoryProtocol {
initialFocussedEventID: nil, initialFocussedEventID: nil,
timelineItemFactory: timelineItemFactory, timelineItemFactory: timelineItemFactory,
mediaProvider: mediaProvider, mediaProvider: mediaProvider,
appSettings: ServiceLocator.shared.settings)) appSettings: appSettings))
case .failure(let error): case .failure(let error):
return .failure(.roomProxyError(error)) return .failure(.roomProxyError(error))
} }
@@ -69,7 +71,7 @@ struct TimelineControllerFactory: TimelineControllerFactoryProtocol {
initialFocussedEventID: nil, initialFocussedEventID: nil,
timelineItemFactory: timelineItemFactory, timelineItemFactory: timelineItemFactory,
mediaProvider: mediaProvider, mediaProvider: mediaProvider,
appSettings: ServiceLocator.shared.settings)) appSettings: appSettings))
case .failure(let error): case .failure(let error):
return .failure(.roomProxyError(error)) return .failure(.roomProxyError(error))
} }
@@ -12,6 +12,10 @@ import SwiftUI
import UIKit import UIKit
class UITestsAppCoordinator: AppCoordinatorProtocol, SecureWindowManagerDelegate { class UITestsAppCoordinator: AppCoordinatorProtocol, SecureWindowManagerDelegate {
private let appSettings: AppSettings
private let analytics: AnalyticsService
private let userIndicatorController: UserIndicatorControllerProtocol
private let navigationRootCoordinator: NavigationRootCoordinator private let navigationRootCoordinator: NavigationRootCoordinator
// periphery:ignore - retaining purpose // periphery:ignore - retaining purpose
@@ -29,26 +33,30 @@ class UITestsAppCoordinator: AppCoordinatorProtocol, SecureWindowManagerDelegate
navigationRootCoordinator = NavigationRootCoordinator() navigationRootCoordinator = NavigationRootCoordinator()
windowManager.delegate = self
MXLog.configure(currentTarget: "uitests") MXLog.configure(currentTarget: "uitests")
ServiceLocator.shared.register(userIndicatorController: UserIndicatorController())
AppSettings.configureWithSuiteName("io.element.elementx.uitests") AppSettings.configureWithSuiteName("io.element.elementx.uitests")
AppSettings.resetAllSettings() AppSettings.resetAllSettings()
ServiceLocator.shared.register(appSettings: AppSettings()) appSettings = AppSettings()
let analyticsClient = AnalyticsClientMock() let analyticsClient = AnalyticsClientMock()
analyticsClient.isRunning = false 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() { func start() {
guard let screenID = ProcessInfo.testScreenID else { fatalError("Unable to launch with unknown screen.") } 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 { if let coordinator = mockScreen.coordinator {
navigationRootCoordinator.setRootCoordinator(coordinator) navigationRootCoordinator.setRootCoordinator(coordinator)
@@ -58,7 +66,8 @@ class UITestsAppCoordinator: AppCoordinatorProtocol, SecureWindowManagerDelegate
} }
func toPresentable() -> AnyView { func toPresentable() -> AnyView {
navigationRootCoordinator.toPresentable() AnyView(navigationRootCoordinator.toPresentable()
.environment(\.analyticsService, analytics))
} }
func handlePotentialPhishingAttempt(url: URL, openURLAction: @escaping (URL) -> Void) -> Bool { func handlePotentialPhishingAttempt(url: URL, openURLAction: @escaping (URL) -> Void) -> Bool {
@@ -78,13 +87,16 @@ class UITestsAppCoordinator: AppCoordinatorProtocol, SecureWindowManagerDelegate
} }
func windowManagerDidConfigureWindows(_ windowManager: SecureWindowManagerProtocol) { 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. // Set up the alternate window for the App Lock flow coordinator tests.
guard let screenID = ProcessInfo.testScreenID, screenID == .appLockFlow || screenID == .appLockFlowDisabled else { return } guard let screenID = ProcessInfo.testScreenID, screenID == .appLockFlow || screenID == .appLockFlowDisabled else { return }
let screen = MockScreen(id: screenID == .appLockFlow ? .appLockFlowAlternateWindow : .appLockFlowDisabledAlternateWindow, let screen = MockScreen(id: screenID == .appLockFlow ? .appLockFlowAlternateWindow : .appLockFlowDisabledAlternateWindow,
windowManager: windowManager, windowManager: windowManager,
navigationRootCoordinator: navigationRootCoordinator) navigationRootCoordinator: navigationRootCoordinator,
appSettings: appSettings,
analytics: analytics,
userIndicatorController: userIndicatorController)
guard let coordinator = screen.coordinator else { guard let coordinator = screen.coordinator else {
fatalError() fatalError()
@@ -102,6 +114,10 @@ class MockScreen: Identifiable {
let windowManager: SecureWindowManagerProtocol let windowManager: SecureWindowManagerProtocol
let navigationRootCoordinator: NavigationRootCoordinator let navigationRootCoordinator: NavigationRootCoordinator
private let appSettings: AppSettings
private let analytics: AnalyticsService
private let userIndicatorController: UserIndicatorControllerProtocol
private var client: UITestsSignalling.Client? private var client: UITestsSignalling.Client?
private var retainedState = [Any]() private var retainedState = [Any]()
@@ -109,10 +125,16 @@ class MockScreen: Identifiable {
init(id: UITestsScreenIdentifier, init(id: UITestsScreenIdentifier,
windowManager: SecureWindowManagerProtocol, windowManager: SecureWindowManagerProtocol,
navigationRootCoordinator: NavigationRootCoordinator) { navigationRootCoordinator: NavigationRootCoordinator,
appSettings: AppSettings,
analytics: AnalyticsService,
userIndicatorController: UserIndicatorControllerProtocol) {
self.id = id self.id = id
self.windowManager = windowManager self.windowManager = windowManager
self.navigationRootCoordinator = navigationRootCoordinator self.navigationRootCoordinator = navigationRootCoordinator
self.appSettings = appSettings
self.analytics = analytics
self.userIndicatorController = userIndicatorController
} }
lazy var coordinator: CoordinatorProtocol? = { lazy var coordinator: CoordinatorProtocol? = {
@@ -121,12 +143,12 @@ class MockScreen: Identifiable {
let navigationStackCoordinator = NavigationStackCoordinator() let navigationStackCoordinator = NavigationStackCoordinator()
let coordinator = ServerSelectionScreenCoordinator(parameters: .init(authenticationService: AuthenticationService.mock, let coordinator = ServerSelectionScreenCoordinator(parameters: .init(authenticationService: AuthenticationService.mock,
authenticationFlow: .login, authenticationFlow: .login,
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
userIndicatorController: ServiceLocator.shared.userIndicatorController)) userIndicatorController: userIndicatorController))
navigationStackCoordinator.setRootCoordinator(coordinator) navigationStackCoordinator.setRootCoordinator(coordinator)
return navigationStackCoordinator return navigationStackCoordinator
case .authenticationFlow, .provisionedAuthenticationFlow, .singleProviderAuthenticationFlow, .multipleProvidersAuthenticationFlow: case .authenticationFlow, .provisionedAuthenticationFlow, .singleProviderAuthenticationFlow, .multipleProvidersAuthenticationFlow:
let appSettings: AppSettings! = ServiceLocator.shared.settings let appSettings: AppSettings! = appSettings
if id == .singleProviderAuthenticationFlow || id == .multipleProvidersAuthenticationFlow { if id == .singleProviderAuthenticationFlow || id == .multipleProvidersAuthenticationFlow {
let accountProviders = id == .singleProviderAuthenticationFlow ? ["example.com"] : ["guest.example.com", "example.com"] let accountProviders = id == .singleProviderAuthenticationFlow ? ["example.com"] : ["guest.example.com", "example.com"]
@@ -158,8 +180,8 @@ class MockScreen: Identifiable {
appMediator: AppMediatorMock.default, appMediator: AppMediatorMock.default,
appSettings: appSettings, appSettings: appSettings,
appHooks: AppHooks(), appHooks: AppHooks(),
analytics: ServiceLocator.shared.analytics, analytics: analytics,
userIndicatorController: ServiceLocator.shared.userIndicatorController) userIndicatorController: userIndicatorController)
flowCoordinator.start() flowCoordinator.start()
retainedState.append(flowCoordinator) retainedState.append(flowCoordinator)
@@ -184,7 +206,7 @@ class MockScreen: Identifiable {
context.evaluatedPolicyDomainStateValue = Data("😎".utf8) context.evaluatedPolicyDomainStateValue = Data("😎".utf8)
let appLockService = AppLockService(keychainController: keychainController, let appLockService = AppLockService(keychainController: keychainController,
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
context: context) context: context)
if id == .appLockFlowAlternateWindow { if id == .appLockFlowAlternateWindow {
@@ -206,7 +228,7 @@ class MockScreen: Identifiable {
appLockService: appLockService, appLockService: appLockService,
navigationCoordinator: navigationCoordinator, navigationCoordinator: navigationCoordinator,
notificationCenter: notificationCenter, notificationCenter: notificationCenter,
appSettings: ServiceLocator.shared.settings) appSettings: appSettings)
flowCoordinator.actions flowCoordinator.actions
.sink { [weak self] action in .sink { [weak self] action in
@@ -240,7 +262,7 @@ class MockScreen: Identifiable {
context.evaluatedPolicyDomainStateValue = Data("😎".utf8) context.evaluatedPolicyDomainStateValue = Data("😎".utf8)
let appLockService = AppLockService(keychainController: keychainController, let appLockService = AppLockService(keychainController: keychainController,
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
context: context) context: context)
if id == .appLockSetupFlowUnlock, case .failure = appLockService.setupPINCode("2023") { if id == .appLockSetupFlowUnlock, case .failure = appLockService.setupPINCode("2023") {
fatalError("Failed to pre-set the PIN code") fatalError("Failed to pre-set the PIN code")
@@ -272,14 +294,14 @@ class MockScreen: Identifiable {
roomProxy: JoinedRoomProxyMock(.init(name: "Some room name", avatarURL: nil)), roomProxy: JoinedRoomProxyMock(.init(name: "Some room name", avatarURL: nil)),
timelineController: MockTimelineController(), timelineController: MockTimelineController(),
mediaPlayerProvider: MediaPlayerProviderMock(), mediaPlayerProvider: MediaPlayerProviderMock(),
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings), emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(), linkMetadataProvider: LinkMetadataProvider(),
completionSuggestionService: CompletionSuggestionServiceMock(configuration: .init()), completionSuggestionService: CompletionSuggestionServiceMock(configuration: .init()),
ongoingCallRoomIDPublisher: .init(.init(nil)), ongoingCallRoomIDPublisher: .init(.init(nil)),
appMediator: AppMediatorMock.default, appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
appHooks: AppHooks(), appHooks: AppHooks(),
analytics: ServiceLocator.shared.analytics, analytics: analytics,
composerDraftService: ComposerDraftServiceMock(.init()), composerDraftService: ComposerDraftServiceMock(.init()),
timelineControllerFactory: TimelineControllerFactoryMock(.init()), timelineControllerFactory: TimelineControllerFactoryMock(.init()),
userIndicatorController: UserIndicatorControllerMock()) userIndicatorController: UserIndicatorControllerMock())
@@ -294,14 +316,14 @@ class MockScreen: Identifiable {
roomProxy: JoinedRoomProxyMock(.init(name: "New room", avatarURL: .mockMXCAvatar)), roomProxy: JoinedRoomProxyMock(.init(name: "New room", avatarURL: .mockMXCAvatar)),
timelineController: timelineController, timelineController: timelineController,
mediaPlayerProvider: MediaPlayerProviderMock(), mediaPlayerProvider: MediaPlayerProviderMock(),
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings), emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(), linkMetadataProvider: LinkMetadataProvider(),
completionSuggestionService: CompletionSuggestionServiceMock(configuration: .init()), completionSuggestionService: CompletionSuggestionServiceMock(configuration: .init()),
ongoingCallRoomIDPublisher: .init(.init(nil)), ongoingCallRoomIDPublisher: .init(.init(nil)),
appMediator: AppMediatorMock.default, appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
appHooks: AppHooks(), appHooks: AppHooks(),
analytics: ServiceLocator.shared.analytics, analytics: analytics,
composerDraftService: ComposerDraftServiceMock(.init()), composerDraftService: ComposerDraftServiceMock(.init()),
timelineControllerFactory: TimelineControllerFactoryMock(.init()), timelineControllerFactory: TimelineControllerFactoryMock(.init()),
userIndicatorController: UserIndicatorControllerMock()) userIndicatorController: UserIndicatorControllerMock())
@@ -316,14 +338,14 @@ class MockScreen: Identifiable {
roomProxy: JoinedRoomProxyMock(.init(name: "New room", avatarURL: .mockMXCAvatar)), roomProxy: JoinedRoomProxyMock(.init(name: "New room", avatarURL: .mockMXCAvatar)),
timelineController: timelineController, timelineController: timelineController,
mediaPlayerProvider: MediaPlayerProviderMock(), mediaPlayerProvider: MediaPlayerProviderMock(),
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings), emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(), linkMetadataProvider: LinkMetadataProvider(),
completionSuggestionService: CompletionSuggestionServiceMock(configuration: .init()), completionSuggestionService: CompletionSuggestionServiceMock(configuration: .init()),
ongoingCallRoomIDPublisher: .init(.init(nil)), ongoingCallRoomIDPublisher: .init(.init(nil)),
appMediator: AppMediatorMock.default, appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
appHooks: AppHooks(), appHooks: AppHooks(),
analytics: ServiceLocator.shared.analytics, analytics: analytics,
composerDraftService: ComposerDraftServiceMock(.init()), composerDraftService: ComposerDraftServiceMock(.init()),
timelineControllerFactory: TimelineControllerFactoryMock(.init()), userIndicatorController: UserIndicatorControllerMock()) timelineControllerFactory: TimelineControllerFactoryMock(.init()), userIndicatorController: UserIndicatorControllerMock())
let coordinator = RoomScreenCoordinator(parameters: parameters) let coordinator = RoomScreenCoordinator(parameters: parameters)
@@ -337,14 +359,14 @@ class MockScreen: Identifiable {
roomProxy: JoinedRoomProxyMock(.init(name: "New room", avatarURL: .mockMXCAvatar)), roomProxy: JoinedRoomProxyMock(.init(name: "New room", avatarURL: .mockMXCAvatar)),
timelineController: timelineController, timelineController: timelineController,
mediaPlayerProvider: MediaPlayerProviderMock(), mediaPlayerProvider: MediaPlayerProviderMock(),
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings), emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(), linkMetadataProvider: LinkMetadataProvider(),
completionSuggestionService: CompletionSuggestionServiceMock(configuration: .init()), completionSuggestionService: CompletionSuggestionServiceMock(configuration: .init()),
ongoingCallRoomIDPublisher: .init(.init(nil)), ongoingCallRoomIDPublisher: .init(.init(nil)),
appMediator: AppMediatorMock.default, appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
appHooks: AppHooks(), appHooks: AppHooks(),
analytics: ServiceLocator.shared.analytics, analytics: analytics,
composerDraftService: ComposerDraftServiceMock(.init()), composerDraftService: ComposerDraftServiceMock(.init()),
timelineControllerFactory: TimelineControllerFactoryMock(.init()), userIndicatorController: UserIndicatorControllerMock()) timelineControllerFactory: TimelineControllerFactoryMock(.init()), userIndicatorController: UserIndicatorControllerMock())
let coordinator = RoomScreenCoordinator(parameters: parameters) let coordinator = RoomScreenCoordinator(parameters: parameters)
@@ -361,14 +383,14 @@ class MockScreen: Identifiable {
roomProxy: JoinedRoomProxyMock(.init(name: "Small timeline", avatarURL: .mockMXCAvatar)), roomProxy: JoinedRoomProxyMock(.init(name: "Small timeline", avatarURL: .mockMXCAvatar)),
timelineController: timelineController, timelineController: timelineController,
mediaPlayerProvider: MediaPlayerProviderMock(), mediaPlayerProvider: MediaPlayerProviderMock(),
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings), emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(), linkMetadataProvider: LinkMetadataProvider(),
completionSuggestionService: CompletionSuggestionServiceMock(configuration: .init()), completionSuggestionService: CompletionSuggestionServiceMock(configuration: .init()),
ongoingCallRoomIDPublisher: .init(.init(nil)), ongoingCallRoomIDPublisher: .init(.init(nil)),
appMediator: AppMediatorMock.default, appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
appHooks: AppHooks(), appHooks: AppHooks(),
analytics: ServiceLocator.shared.analytics, analytics: analytics,
composerDraftService: ComposerDraftServiceMock(.init()), composerDraftService: ComposerDraftServiceMock(.init()),
timelineControllerFactory: TimelineControllerFactoryMock(.init()), userIndicatorController: UserIndicatorControllerMock()) timelineControllerFactory: TimelineControllerFactoryMock(.init()), userIndicatorController: UserIndicatorControllerMock())
let coordinator = RoomScreenCoordinator(parameters: parameters) let coordinator = RoomScreenCoordinator(parameters: parameters)
@@ -385,14 +407,14 @@ class MockScreen: Identifiable {
roomProxy: JoinedRoomProxyMock(.init(name: "Small timeline, paginating", avatarURL: .mockMXCAvatar)), roomProxy: JoinedRoomProxyMock(.init(name: "Small timeline, paginating", avatarURL: .mockMXCAvatar)),
timelineController: timelineController, timelineController: timelineController,
mediaPlayerProvider: MediaPlayerProviderMock(), mediaPlayerProvider: MediaPlayerProviderMock(),
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings), emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(), linkMetadataProvider: LinkMetadataProvider(),
completionSuggestionService: CompletionSuggestionServiceMock(configuration: .init()), completionSuggestionService: CompletionSuggestionServiceMock(configuration: .init()),
ongoingCallRoomIDPublisher: .init(.init(nil)), ongoingCallRoomIDPublisher: .init(.init(nil)),
appMediator: AppMediatorMock.default, appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
appHooks: AppHooks(), appHooks: AppHooks(),
analytics: ServiceLocator.shared.analytics, analytics: analytics,
composerDraftService: ComposerDraftServiceMock(.init()), timelineControllerFactory: TimelineControllerFactoryMock(.init()), userIndicatorController: UserIndicatorControllerMock()) composerDraftService: ComposerDraftServiceMock(.init()), timelineControllerFactory: TimelineControllerFactoryMock(.init()), userIndicatorController: UserIndicatorControllerMock())
let coordinator = RoomScreenCoordinator(parameters: parameters) let coordinator = RoomScreenCoordinator(parameters: parameters)
@@ -408,14 +430,14 @@ class MockScreen: Identifiable {
roomProxy: JoinedRoomProxyMock(.init(name: "Large timeline", avatarURL: .mockMXCAvatar)), roomProxy: JoinedRoomProxyMock(.init(name: "Large timeline", avatarURL: .mockMXCAvatar)),
timelineController: timelineController, timelineController: timelineController,
mediaPlayerProvider: MediaPlayerProviderMock(), mediaPlayerProvider: MediaPlayerProviderMock(),
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings), emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(), linkMetadataProvider: LinkMetadataProvider(),
completionSuggestionService: CompletionSuggestionServiceMock(configuration: .init()), completionSuggestionService: CompletionSuggestionServiceMock(configuration: .init()),
ongoingCallRoomIDPublisher: .init(.init(nil)), ongoingCallRoomIDPublisher: .init(.init(nil)),
appMediator: AppMediatorMock.default, appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
appHooks: AppHooks(), appHooks: AppHooks(),
analytics: ServiceLocator.shared.analytics, analytics: analytics,
composerDraftService: ComposerDraftServiceMock(.init()), composerDraftService: ComposerDraftServiceMock(.init()),
timelineControllerFactory: TimelineControllerFactoryMock(.init()), userIndicatorController: UserIndicatorControllerMock()) timelineControllerFactory: TimelineControllerFactoryMock(.init()), userIndicatorController: UserIndicatorControllerMock())
let coordinator = RoomScreenCoordinator(parameters: parameters) let coordinator = RoomScreenCoordinator(parameters: parameters)
@@ -433,14 +455,14 @@ class MockScreen: Identifiable {
roomProxy: JoinedRoomProxyMock(.init(name: "Large timeline", avatarURL: .mockMXCAvatar)), roomProxy: JoinedRoomProxyMock(.init(name: "Large timeline", avatarURL: .mockMXCAvatar)),
timelineController: timelineController, timelineController: timelineController,
mediaPlayerProvider: MediaPlayerProviderMock(), mediaPlayerProvider: MediaPlayerProviderMock(),
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings), emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(), linkMetadataProvider: LinkMetadataProvider(),
completionSuggestionService: CompletionSuggestionServiceMock(configuration: .init()), completionSuggestionService: CompletionSuggestionServiceMock(configuration: .init()),
ongoingCallRoomIDPublisher: .init(.init(nil)), ongoingCallRoomIDPublisher: .init(.init(nil)),
appMediator: AppMediatorMock.default, appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
appHooks: AppHooks(), appHooks: AppHooks(),
analytics: ServiceLocator.shared.analytics, analytics: analytics,
composerDraftService: ComposerDraftServiceMock(.init()), composerDraftService: ComposerDraftServiceMock(.init()),
timelineControllerFactory: TimelineControllerFactoryMock(.init()), userIndicatorController: UserIndicatorControllerMock()) timelineControllerFactory: TimelineControllerFactoryMock(.init()), userIndicatorController: UserIndicatorControllerMock())
let coordinator = RoomScreenCoordinator(parameters: parameters) let coordinator = RoomScreenCoordinator(parameters: parameters)
@@ -457,14 +479,14 @@ class MockScreen: Identifiable {
roomProxy: JoinedRoomProxyMock(.init(name: "Large timeline", avatarURL: .mockMXCAvatar)), roomProxy: JoinedRoomProxyMock(.init(name: "Large timeline", avatarURL: .mockMXCAvatar)),
timelineController: timelineController, timelineController: timelineController,
mediaPlayerProvider: MediaPlayerProviderMock(), mediaPlayerProvider: MediaPlayerProviderMock(),
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings), emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(), linkMetadataProvider: LinkMetadataProvider(),
completionSuggestionService: CompletionSuggestionServiceMock(configuration: .init()), completionSuggestionService: CompletionSuggestionServiceMock(configuration: .init()),
ongoingCallRoomIDPublisher: .init(.init(nil)), ongoingCallRoomIDPublisher: .init(.init(nil)),
appMediator: AppMediatorMock.default, appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
appHooks: AppHooks(), appHooks: AppHooks(),
analytics: ServiceLocator.shared.analytics, analytics: analytics,
composerDraftService: ComposerDraftServiceMock(.init()), composerDraftService: ComposerDraftServiceMock(.init()),
timelineControllerFactory: TimelineControllerFactoryMock(.init()), userIndicatorController: UserIndicatorControllerMock()) timelineControllerFactory: TimelineControllerFactoryMock(.init()), userIndicatorController: UserIndicatorControllerMock())
let coordinator = RoomScreenCoordinator(parameters: parameters) let coordinator = RoomScreenCoordinator(parameters: parameters)
@@ -480,14 +502,14 @@ class MockScreen: Identifiable {
roomProxy: JoinedRoomProxyMock(.init(name: "Timeline highlight", avatarURL: .mockMXCAvatar)), roomProxy: JoinedRoomProxyMock(.init(name: "Timeline highlight", avatarURL: .mockMXCAvatar)),
timelineController: timelineController, timelineController: timelineController,
mediaPlayerProvider: MediaPlayerProviderMock(), mediaPlayerProvider: MediaPlayerProviderMock(),
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings), emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(), linkMetadataProvider: LinkMetadataProvider(),
completionSuggestionService: CompletionSuggestionServiceMock(configuration: .init()), completionSuggestionService: CompletionSuggestionServiceMock(configuration: .init()),
ongoingCallRoomIDPublisher: .init(.init(nil)), ongoingCallRoomIDPublisher: .init(.init(nil)),
appMediator: AppMediatorMock.default, appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
appHooks: AppHooks(), appHooks: AppHooks(),
analytics: ServiceLocator.shared.analytics, analytics: analytics,
composerDraftService: ComposerDraftServiceMock(.init()), composerDraftService: ComposerDraftServiceMock(.init()),
timelineControllerFactory: TimelineControllerFactoryMock(.init()), userIndicatorController: UserIndicatorControllerMock()) timelineControllerFactory: TimelineControllerFactoryMock(.init()), userIndicatorController: UserIndicatorControllerMock())
let coordinator = RoomScreenCoordinator(parameters: parameters) let coordinator = RoomScreenCoordinator(parameters: parameters)
@@ -517,14 +539,14 @@ class MockScreen: Identifiable {
roomProxy: JoinedRoomProxyMock(.init(name: "Polls timeline", avatarURL: .mockMXCAvatar)), roomProxy: JoinedRoomProxyMock(.init(name: "Polls timeline", avatarURL: .mockMXCAvatar)),
timelineController: timelineController, timelineController: timelineController,
mediaPlayerProvider: MediaPlayerProviderMock(), mediaPlayerProvider: MediaPlayerProviderMock(),
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings), emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(), linkMetadataProvider: LinkMetadataProvider(),
completionSuggestionService: CompletionSuggestionServiceMock(configuration: .init()), completionSuggestionService: CompletionSuggestionServiceMock(configuration: .init()),
ongoingCallRoomIDPublisher: .init(.init(nil)), ongoingCallRoomIDPublisher: .init(.init(nil)),
appMediator: AppMediatorMock.default, appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
appHooks: AppHooks(), appHooks: AppHooks(),
analytics: ServiceLocator.shared.analytics, analytics: analytics,
composerDraftService: ComposerDraftServiceMock(.init()), composerDraftService: ComposerDraftServiceMock(.init()),
timelineControllerFactory: TimelineControllerFactoryMock(.init()), userIndicatorController: UserIndicatorControllerMock()) timelineControllerFactory: TimelineControllerFactoryMock(.init()), userIndicatorController: UserIndicatorControllerMock())
let coordinator = RoomScreenCoordinator(parameters: parameters) let coordinator = RoomScreenCoordinator(parameters: parameters)
@@ -541,14 +563,14 @@ class MockScreen: Identifiable {
roomProxy: JoinedRoomProxyMock(.init(name: "Polls timeline", avatarURL: .mockMXCAvatar)), roomProxy: JoinedRoomProxyMock(.init(name: "Polls timeline", avatarURL: .mockMXCAvatar)),
timelineController: timelineController, timelineController: timelineController,
mediaPlayerProvider: MediaPlayerProviderMock(), mediaPlayerProvider: MediaPlayerProviderMock(),
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings), emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(), linkMetadataProvider: LinkMetadataProvider(),
completionSuggestionService: CompletionSuggestionServiceMock(configuration: .init()), completionSuggestionService: CompletionSuggestionServiceMock(configuration: .init()),
ongoingCallRoomIDPublisher: .init(.init(nil)), ongoingCallRoomIDPublisher: .init(.init(nil)),
appMediator: AppMediatorMock.default, appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
appHooks: AppHooks(), appHooks: AppHooks(),
analytics: ServiceLocator.shared.analytics, analytics: analytics,
composerDraftService: ComposerDraftServiceMock(.init()), composerDraftService: ComposerDraftServiceMock(.init()),
timelineControllerFactory: TimelineControllerFactoryMock(.init()), userIndicatorController: UserIndicatorControllerMock()) timelineControllerFactory: TimelineControllerFactoryMock(.init()), userIndicatorController: UserIndicatorControllerMock())
let coordinator = RoomScreenCoordinator(parameters: parameters) let coordinator = RoomScreenCoordinator(parameters: parameters)
@@ -565,14 +587,14 @@ class MockScreen: Identifiable {
roomProxy: JoinedRoomProxyMock(.init(name: "Polls timeline", avatarURL: .mockMXCAvatar)), roomProxy: JoinedRoomProxyMock(.init(name: "Polls timeline", avatarURL: .mockMXCAvatar)),
timelineController: timelineController, timelineController: timelineController,
mediaPlayerProvider: MediaPlayerProviderMock(), mediaPlayerProvider: MediaPlayerProviderMock(),
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings), emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(), linkMetadataProvider: LinkMetadataProvider(),
completionSuggestionService: CompletionSuggestionServiceMock(configuration: .init()), completionSuggestionService: CompletionSuggestionServiceMock(configuration: .init()),
ongoingCallRoomIDPublisher: .init(.init(nil)), ongoingCallRoomIDPublisher: .init(.init(nil)),
appMediator: AppMediatorMock.default, appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
appHooks: AppHooks(), appHooks: AppHooks(),
analytics: ServiceLocator.shared.analytics, analytics: analytics,
composerDraftService: ComposerDraftServiceMock(.init()), composerDraftService: ComposerDraftServiceMock(.init()),
timelineControllerFactory: TimelineControllerFactoryMock(.init()), userIndicatorController: UserIndicatorControllerMock()) timelineControllerFactory: TimelineControllerFactoryMock(.init()), userIndicatorController: UserIndicatorControllerMock())
let coordinator = RoomScreenCoordinator(parameters: parameters) let coordinator = RoomScreenCoordinator(parameters: parameters)
@@ -584,11 +606,11 @@ class MockScreen: Identifiable {
requestDelay: .seconds(5)) requestDelay: .seconds(5))
let parameters = SessionVerificationScreenCoordinatorParameters(sessionVerificationControllerProxy: sessionVerificationControllerProxy, let parameters = SessionVerificationScreenCoordinatorParameters(sessionVerificationControllerProxy: sessionVerificationControllerProxy,
flow: .deviceInitiator, flow: .deviceInitiator,
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
mediaProvider: MediaProviderMock(configuration: .init())) mediaProvider: MediaProviderMock(configuration: .init()))
return SessionVerificationScreenCoordinator(parameters: parameters) return SessionVerificationScreenCoordinator(parameters: parameters)
case .userSessionScreen, .userSessionScreenReply, .userSessionSpacesFlow: case .userSessionScreen, .userSessionScreenReply, .userSessionSpacesFlow:
let appSettings: AppSettings = ServiceLocator.shared.settings let appSettings: AppSettings = appSettings
appSettings.hasRunIdentityConfirmationOnboarding = true appSettings.hasRunIdentityConfirmationOnboarding = true
appSettings.hasRunNotificationPermissionsOnboarding = true appSettings.hasRunNotificationPermissionsOnboarding = true
appSettings.analyticsConsentState = .optedOut appSettings.analyticsConsentState = .optedOut
@@ -616,7 +638,7 @@ class MockScreen: Identifiable {
let flowCoordinator = UserSessionFlowCoordinator(isNewLogin: false, let flowCoordinator = UserSessionFlowCoordinator(isNewLogin: false,
navigationRootCoordinator: navigationRootCoordinator, navigationRootCoordinator: navigationRootCoordinator,
appLockService: AppLockService(keychainController: KeychainControllerMock(), appLockService: AppLockService(keychainController: KeychainControllerMock(),
appSettings: ServiceLocator.shared.settings), appSettings: appSettings),
flowParameters: CommonFlowParameters(userSession: UserSessionMock(.init(clientProxy: clientProxy)), flowParameters: CommonFlowParameters(userSession: UserSessionMock(.init(clientProxy: clientProxy)),
bugReportService: BugReportServiceMock(.init()), bugReportService: BugReportServiceMock(.init()),
elementCallService: ElementCallServiceMock(.init()), elementCallService: ElementCallServiceMock(.init()),
@@ -626,7 +648,7 @@ class MockScreen: Identifiable {
appMediator: appMediator, appMediator: appMediator,
appSettings: appSettings, appSettings: appSettings,
appHooks: AppHooks(), appHooks: AppHooks(),
analytics: ServiceLocator.shared.analytics, analytics: analytics,
userIndicatorController: UserIndicatorControllerMock(), userIndicatorController: UserIndicatorControllerMock(),
notificationManager: NotificationManagerMock(), notificationManager: NotificationManagerMock(),
stateMachineFactory: StateMachineFactory())) stateMachineFactory: StateMachineFactory()))
@@ -641,8 +663,8 @@ class MockScreen: Identifiable {
let members: [RoomMemberProxyMock] = [.mockInvitedAlice, .mockBob, .mockCharlie] let members: [RoomMemberProxyMock] = [.mockInvitedAlice, .mockBob, .mockCharlie]
let coordinator = RoomMembersListScreenCoordinator(parameters: .init(userSession: UserSessionMock(.init()), let coordinator = RoomMembersListScreenCoordinator(parameters: .init(userSession: UserSessionMock(.init()),
roomProxy: JoinedRoomProxyMock(.init(name: "test", members: members)), roomProxy: JoinedRoomProxyMock(.init(name: "test", members: members)),
userIndicatorController: ServiceLocator.shared.userIndicatorController, userIndicatorController: userIndicatorController,
analytics: ServiceLocator.shared.analytics)) analytics: analytics))
navigationStackCoordinator.setRootCoordinator(coordinator) navigationStackCoordinator.setRootCoordinator(coordinator)
return navigationStackCoordinator return navigationStackCoordinator
case .roomRolesAndPermissionsFlow: case .roomRolesAndPermissionsFlow:
@@ -651,8 +673,8 @@ class MockScreen: Identifiable {
let coordinator = RoomRolesAndPermissionsFlowCoordinator(parameters: .init(roomProxy: JoinedRoomProxyMock(.init(members: .allMembersAsAdmin)), let coordinator = RoomRolesAndPermissionsFlowCoordinator(parameters: .init(roomProxy: JoinedRoomProxyMock(.init(members: .allMembersAsAdmin)),
mediaProvider: MediaProviderMock(configuration: .init()), mediaProvider: MediaProviderMock(configuration: .init()),
navigationStackCoordinator: navigationStackCoordinator, navigationStackCoordinator: navigationStackCoordinator,
userIndicatorController: ServiceLocator.shared.userIndicatorController, userIndicatorController: userIndicatorController,
analytics: ServiceLocator.shared.analytics)) analytics: analytics))
retainedState.append(coordinator) retainedState.append(coordinator)
coordinator.start() coordinator.start()
return navigationStackCoordinator return navigationStackCoordinator
@@ -673,12 +695,12 @@ class MockScreen: Identifiable {
bugReportService: BugReportServiceMock(.init()), bugReportService: BugReportServiceMock(.init()),
elementCallService: ElementCallServiceMock(.init()), elementCallService: ElementCallServiceMock(.init()),
timelineControllerFactory: TimelineControllerFactoryMock(.init()), timelineControllerFactory: TimelineControllerFactoryMock(.init()),
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings), emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(), linkMetadataProvider: LinkMetadataProvider(),
appMediator: AppMediatorMock.default, appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
appHooks: AppHooks(), appHooks: AppHooks(),
analytics: ServiceLocator.shared.analytics, analytics: analytics,
userIndicatorController: UserIndicatorControllerMock(), userIndicatorController: UserIndicatorControllerMock(),
notificationManager: NotificationManagerMock(), notificationManager: NotificationManagerMock(),
stateMachineFactory: StateMachineFactory())) stateMachineFactory: StateMachineFactory()))
@@ -705,7 +727,7 @@ class MockScreen: Identifiable {
let coordinator = PollFormScreenCoordinator(parameters: .init(mode: .new, let coordinator = PollFormScreenCoordinator(parameters: .init(mode: .new,
maxNumberOfOptions: 10, maxNumberOfOptions: 10,
timelineController: MockTimelineController(), timelineController: MockTimelineController(),
analytics: ServiceLocator.shared.analytics, analytics: analytics,
userIndicatorController: UserIndicatorControllerMock())) userIndicatorController: UserIndicatorControllerMock()))
navigationStackCoordinator.setRootCoordinator(coordinator) navigationStackCoordinator.setRootCoordinator(coordinator)
return navigationStackCoordinator return navigationStackCoordinator
@@ -718,7 +740,7 @@ class MockScreen: Identifiable {
navigationStackCoordinator.setRootCoordinator(BlankFormCoordinator()) navigationStackCoordinator.setRootCoordinator(BlankFormCoordinator())
let coordinator = EncryptionSettingsFlowCoordinator(parameters: .init(userSession: userSession, let coordinator = EncryptionSettingsFlowCoordinator(parameters: .init(userSession: userSession,
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
userIndicatorController: UserIndicatorControllerMock(), userIndicatorController: UserIndicatorControllerMock(),
navigationStackCoordinator: navigationStackCoordinator)) navigationStackCoordinator: navigationStackCoordinator))
retainedState.append(coordinator) retainedState.append(coordinator)
@@ -736,7 +758,7 @@ class MockScreen: Identifiable {
let coordinator = EncryptionResetFlowCoordinator(parameters: .init(userSession: userSession, let coordinator = EncryptionResetFlowCoordinator(parameters: .init(userSession: userSession,
appMediator: AppMediatorMock.default, appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
appHooks: AppHooks(), appHooks: AppHooks(),
userIndicatorController: userIndicatorController, userIndicatorController: userIndicatorController,
navigationStackCoordinator: navigationStackCoordinator, navigationStackCoordinator: navigationStackCoordinator,
@@ -759,12 +781,12 @@ class MockScreen: Identifiable {
bugReportService: BugReportServiceMock(.init()), bugReportService: BugReportServiceMock(.init()),
elementCallService: ElementCallServiceMock(.init()), elementCallService: ElementCallServiceMock(.init()),
timelineControllerFactory: TimelineControllerFactoryMock(.init()), timelineControllerFactory: TimelineControllerFactoryMock(.init()),
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings), emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(), linkMetadataProvider: LinkMetadataProvider(),
appMediator: AppMediatorMock.default, appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
appHooks: AppHooks(), appHooks: AppHooks(),
analytics: ServiceLocator.shared.analytics, analytics: analytics,
userIndicatorController: UserIndicatorControllerMock(), userIndicatorController: UserIndicatorControllerMock(),
notificationManager: NotificationManagerMock(), notificationManager: NotificationManagerMock(),
stateMachineFactory: StateMachineFactory())) stateMachineFactory: StateMachineFactory()))
@@ -787,7 +809,7 @@ class MockScreen: Identifiable {
navigationRootCoordinator.setSheetCoordinator(navigationStackCoordinator) navigationRootCoordinator.setSheetCoordinator(navigationStackCoordinator)
return PlaceholderScreenCoordinator(hideBrandChrome: false) return PlaceholderScreenCoordinator(hideBrandChrome: false)
case .autoUpdatingTimeline: case .autoUpdatingTimeline:
let appSettings: AppSettings = ServiceLocator.shared.settings let appSettings: AppSettings = appSettings
appSettings.hasRunIdentityConfirmationOnboarding = true appSettings.hasRunIdentityConfirmationOnboarding = true
appSettings.hasRunNotificationPermissionsOnboarding = true appSettings.hasRunNotificationPermissionsOnboarding = true
appSettings.analyticsConsentState = .optedOut appSettings.analyticsConsentState = .optedOut
@@ -807,7 +829,7 @@ class MockScreen: Identifiable {
attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()), attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()),
stateEventStringBuilder: RoomStateEventStringBuilder(userID: "@alice:matrix.org")), stateEventStringBuilder: RoomStateEventStringBuilder(userID: "@alice:matrix.org")),
mediaProvider: MediaProviderMock(configuration: .init()), mediaProvider: MediaProviderMock(configuration: .init()),
appSettings: ServiceLocator.shared.settings) appSettings: appSettings)
let flowCoordinator = ChatsTabFlowCoordinator(isNewLogin: false, let flowCoordinator = ChatsTabFlowCoordinator(isNewLogin: false,
navigationSplitCoordinator: navigationSplitCoordinator, navigationSplitCoordinator: navigationSplitCoordinator,
@@ -820,7 +842,7 @@ class MockScreen: Identifiable {
appMediator: AppMediatorMock.default, appMediator: AppMediatorMock.default,
appSettings: appSettings, appSettings: appSettings,
appHooks: AppHooks(), appHooks: AppHooks(),
analytics: ServiceLocator.shared.analytics, analytics: analytics,
userIndicatorController: UserIndicatorControllerMock(), userIndicatorController: UserIndicatorControllerMock(),
notificationManager: NotificationManagerMock(), notificationManager: NotificationManagerMock(),
stateMachineFactory: StateMachineFactory())) stateMachineFactory: StateMachineFactory()))
@@ -17,16 +17,9 @@ class UnitTestsAppCoordinator: AppCoordinatorProtocol {
init(appDelegate: AppDelegate) { init(appDelegate: AppDelegate) {
windowManager = WindowManager(appDelegate: appDelegate) windowManager = WindowManager(appDelegate: appDelegate)
ServiceLocator.shared.register(userIndicatorController: UserIndicatorControllerMock.default)
AppSettings.configureWithSuiteName("io.element.elementx.unittests") AppSettings.configureWithSuiteName("io.element.elementx.unittests")
AppSettings.resetAllSettings() 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 // 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. // often some debris left from the previous run, so we wipe the entire directory.
@@ -11,20 +11,19 @@ import Testing
@MainActor @MainActor
final class AnalyticsSettingsScreenViewModelTests { final class AnalyticsSettingsScreenViewModelTests {
private var appSettings: AppSettings! private let appSettings: AppSettings
private let analytics: AnalyticsService
private var viewModel: AnalyticsSettingsScreenViewModelProtocol! private var viewModel: AnalyticsSettingsScreenViewModelProtocol!
private var context: AnalyticsSettingsScreenViewModelType.Context! private var context: AnalyticsSettingsScreenViewModelType.Context!
init() { init() {
AppSettings.resetAllSettings() AppSettings.resetAllSettings()
appSettings = AppSettings() appSettings = AppSettings()
let analyticsClient = AnalyticsClientMock() analytics = .mock(settings: appSettings)
analyticsClient.isRunning = false
ServiceLocator.shared.register(analytics: AnalyticsService(client: analyticsClient,
appSettings: appSettings))
viewModel = AnalyticsSettingsScreenViewModel(appSettings: appSettings, viewModel = AnalyticsSettingsScreenViewModel(appSettings: appSettings,
analytics: ServiceLocator.shared.analytics) analytics: analytics)
context = viewModel.context context = viewModel.context
} }
+20 -19
View File
@@ -12,18 +12,19 @@ import PostHog
import Testing import Testing
final class AnalyticsTests { final class AnalyticsTests {
private var appSettings: AppSettings private let appSettings: AppSettings
private var analyticsClient: AnalyticsClientMock private let analytics: AnalyticsService
private let analyticsClient: AnalyticsClientMock
private var posthogMock: PHGPostHogMock private var posthogMock: PHGPostHogMock
@MainActor
init() { init() {
AppSettings.resetAllSettings() AppSettings.resetAllSettings()
appSettings = AppSettings() appSettings = AppSettings()
analyticsClient = AnalyticsClientMock() analyticsClient = AnalyticsClientMock()
analyticsClient.isRunning = false analyticsClient.isRunning = false
ServiceLocator.shared.register(analytics: AnalyticsService(client: analyticsClient, analytics = .mock(analyticsClient, settings: appSettings)
appSettings: appSettings))
posthogMock = PHGPostHogMock() posthogMock = PHGPostHogMock()
posthogMock.configureMockBehavior() posthogMock.configureMockBehavior()
@@ -37,7 +38,7 @@ final class AnalyticsTests {
func analyticsPromptNewUser() { func analyticsPromptNewUser() {
// Given a fresh install of the app (without PostHog analytics having been set). // Given a fresh install of the app (without PostHog analytics having been set).
// When the user is prompted for analytics. // When the user is prompted for analytics.
let showPrompt = ServiceLocator.shared.analytics.shouldShowAnalyticsPrompt let showPrompt = analytics.shouldShowAnalyticsPrompt
// Then the prompt should be shown. // Then the prompt should be shown.
#expect(showPrompt, "A prompt should be shown for a new user.") #expect(showPrompt, "A prompt should be shown for a new user.")
@@ -49,7 +50,7 @@ final class AnalyticsTests {
appSettings.analyticsConsentState = .optedOut appSettings.analyticsConsentState = .optedOut
// When the user is prompted for analytics // When the user is prompted for analytics
let showPrompt = ServiceLocator.shared.analytics.shouldShowAnalyticsPrompt let showPrompt = analytics.shouldShowAnalyticsPrompt
// Then no prompt should be shown. // Then no prompt should be shown.
#expect(!showPrompt, "A prompt should not be shown any more.") #expect(!showPrompt, "A prompt should not be shown any more.")
@@ -61,7 +62,7 @@ final class AnalyticsTests {
appSettings.analyticsConsentState = .optedIn appSettings.analyticsConsentState = .optedIn
// When the user is prompted for analytics // When the user is prompted for analytics
let showPrompt = ServiceLocator.shared.analytics.shouldShowAnalyticsPrompt let showPrompt = analytics.shouldShowAnalyticsPrompt
// Then no prompt should be shown. // Then no prompt should be shown.
#expect(!showPrompt, "A prompt should not be shown any more.") #expect(!showPrompt, "A prompt should not be shown any more.")
@@ -71,7 +72,7 @@ final class AnalyticsTests {
func analyticsPromptNotDisplayed() { func analyticsPromptNotDisplayed() {
// Given a fresh install of the app Analytics should be disabled // Given a fresh install of the app Analytics should be disabled
#expect(appSettings.analyticsConsentState == .unknown) #expect(appSettings.analyticsConsentState == .unknown)
#expect(!ServiceLocator.shared.analytics.isEnabled) #expect(!analytics.isEnabled)
#expect(!analyticsClient.startAnalyticsConfigurationCalled) #expect(!analyticsClient.startAnalyticsConfigurationCalled)
} }
@@ -79,10 +80,10 @@ final class AnalyticsTests {
func analyticsOptOut() { func analyticsOptOut() {
// Given a fresh install of the app (without PostHog analytics having been set). // Given a fresh install of the app (without PostHog analytics having been set).
// When analytics is opt-out // When analytics is opt-out
ServiceLocator.shared.analytics.optOut() analytics.optOut()
// Then analytics should be disabled // Then analytics should be disabled
#expect(appSettings.analyticsConsentState == .optedOut) #expect(appSettings.analyticsConsentState == .optedOut)
#expect(!ServiceLocator.shared.analytics.isEnabled) #expect(!analytics.isEnabled)
#expect(!analyticsClient.isRunning) #expect(!analyticsClient.isRunning)
// Analytics client should have been stopped // Analytics client should have been stopped
#expect(analyticsClient.stopCalled) #expect(analyticsClient.stopCalled)
@@ -92,10 +93,10 @@ final class AnalyticsTests {
func analyticsOptIn() { func analyticsOptIn() {
// Given a fresh install of the app (without PostHog analytics having been set). // Given a fresh install of the app (without PostHog analytics having been set).
// When analytics is opt-in // When analytics is opt-in
ServiceLocator.shared.analytics.optIn() analytics.optIn()
// The analytics should be enabled // The analytics should be enabled
#expect(appSettings.analyticsConsentState == .optedIn) #expect(appSettings.analyticsConsentState == .optedIn)
#expect(ServiceLocator.shared.analytics.isEnabled) #expect(analytics.isEnabled)
// Analytics client should have been started // Analytics client should have been started
#expect(analyticsClient.startAnalyticsConfigurationCalled) #expect(analyticsClient.startAnalyticsConfigurationCalled)
} }
@@ -105,8 +106,8 @@ final class AnalyticsTests {
// Given an existing install of the app where the user previously declined the tracking // Given an existing install of the app where the user previously declined the tracking
appSettings.analyticsConsentState = .optedOut appSettings.analyticsConsentState = .optedOut
// Analytics should not start // Analytics should not start
#expect(!ServiceLocator.shared.analytics.isEnabled) #expect(!analytics.isEnabled)
ServiceLocator.shared.analytics.startIfEnabled() analytics.startIfEnabled()
#expect(!analyticsClient.startAnalyticsConfigurationCalled) #expect(!analyticsClient.startAnalyticsConfigurationCalled)
} }
@@ -115,8 +116,8 @@ final class AnalyticsTests {
// Given an existing install of the app where the user previously accepted the tracking // Given an existing install of the app where the user previously accepted the tracking
appSettings.analyticsConsentState = .optedIn appSettings.analyticsConsentState = .optedIn
// Analytics should start // Analytics should start
#expect(ServiceLocator.shared.analytics.isEnabled) #expect(analytics.isEnabled)
ServiceLocator.shared.analytics.startIfEnabled() analytics.startIfEnabled()
#expect(analyticsClient.startAnalyticsConfigurationCalled) #expect(analyticsClient.startAnalyticsConfigurationCalled)
} }
@@ -214,14 +215,14 @@ final class AnalyticsTests {
func resetConsentState() { func resetConsentState() {
// Given an existing install of the app where the user previously accpeted the tracking // Given an existing install of the app where the user previously accpeted the tracking
appSettings.analyticsConsentState = .optedIn appSettings.analyticsConsentState = .optedIn
#expect(!ServiceLocator.shared.analytics.shouldShowAnalyticsPrompt) #expect(!analytics.shouldShowAnalyticsPrompt)
// When forgetting analytics consents // When forgetting analytics consents
ServiceLocator.shared.analytics.resetConsentState() analytics.resetConsentState()
// Then the analytics prompt should be presented again // Then the analytics prompt should be presented again
#expect(appSettings.analyticsConsentState == .unknown) #expect(appSettings.analyticsConsentState == .unknown)
#expect(ServiceLocator.shared.analytics.shouldShowAnalyticsPrompt) #expect(analytics.shouldShowAnalyticsPrompt)
} }
@Test @Test
@@ -153,7 +153,7 @@ struct AuthenticationServiceTests {
encryptionKeyProvider: encryptionKeyProvider, encryptionKeyProvider: encryptionKeyProvider,
classicAppManager: classicAppManager, classicAppManager: classicAppManager,
clientFactory: clientFactory, clientFactory: clientFactory,
appSettings: ServiceLocator.shared.settings, appSettings: AppSettings(),
appHooks: AppHooks()) appHooks: AppHooks())
if let classicAppAccount = service.classicAppAccount { if let classicAppAccount = service.classicAppAccount {
@@ -28,8 +28,6 @@ final class AuthenticationStartScreenViewModelTests {
init() { init() {
AppSettings.resetAllSettings() AppSettings.resetAllSettings()
appSettings = AppSettings() appSettings = AppSettings()
// These app settings are kept local to the tests on purpose as if they are registered in the
// ServiceLocator, the providers override that we apply will break other tests in the suite.
} }
deinit { deinit {
@@ -19,7 +19,7 @@ struct BlockedUsersScreenViewModelTests {
let viewModel = BlockedUsersScreenViewModel(hideProfiles: true, let viewModel = BlockedUsersScreenViewModel(hideProfiles: true,
userSession: UserSessionMock(.init(clientProxy: clientProxy)), userSession: UserSessionMock(.init(clientProxy: clientProxy)),
userIndicatorController: ServiceLocator.shared.userIndicatorController) userIndicatorController: UserIndicatorControllerMock.default)
let deferred = deferFailure(viewModel.context.observe(\.viewState.blockedUsers), timeout: .seconds(1)) { $0.contains { $0.displayName != nil } } let deferred = deferFailure(viewModel.context.observe(\.viewState.blockedUsers), timeout: .seconds(1)) { $0.contains { $0.displayName != nil } }
try await deferred.fulfill() try await deferred.fulfill()
@@ -34,7 +34,7 @@ struct BlockedUsersScreenViewModelTests {
let viewModel = BlockedUsersScreenViewModel(hideProfiles: false, let viewModel = BlockedUsersScreenViewModel(hideProfiles: false,
userSession: UserSessionMock(.init(clientProxy: clientProxy)), userSession: UserSessionMock(.init(clientProxy: clientProxy)),
userIndicatorController: ServiceLocator.shared.userIndicatorController) userIndicatorController: UserIndicatorControllerMock.default)
let deferred = deferFulfillment(viewModel.context.observe(\.viewState.blockedUsers)) { $0.contains { $0.displayName != nil } } let deferred = deferFulfillment(viewModel.context.observe(\.viewState.blockedUsers)) { $0.contains { $0.displayName != nil } }
try await deferred.fulfill() try await deferred.fulfill()
@@ -31,6 +31,9 @@ struct ChatsTabFlowCoordinatorTests {
} }
init() async throws { init() async throws {
let appSettings = AppSettings()
let analytics: AnalyticsService = .mock(settings: appSettings)
clientProxy = ClientProxyMock(.init(userID: "hi@bob", roomSummaryProvider: RoomSummaryProviderMock(.init(state: .loaded(.mockRooms))))) clientProxy = ClientProxyMock(.init(userID: "hi@bob", roomSummaryProvider: RoomSummaryProviderMock(.init(state: .loaded(.mockRooms)))))
timelineControllerFactory = TimelineControllerFactoryMock(.init()) timelineControllerFactory = TimelineControllerFactoryMock(.init())
@@ -42,12 +45,12 @@ struct ChatsTabFlowCoordinatorTests {
bugReportService: BugReportServiceMock(.init()), bugReportService: BugReportServiceMock(.init()),
elementCallService: ElementCallServiceMock(.init()), elementCallService: ElementCallServiceMock(.init()),
timelineControllerFactory: timelineControllerFactory, timelineControllerFactory: timelineControllerFactory,
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings), emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(), linkMetadataProvider: LinkMetadataProvider(),
appMediator: AppMediatorMock.default, appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
appHooks: AppHooks(), appHooks: AppHooks(),
analytics: ServiceLocator.shared.analytics, analytics: analytics,
userIndicatorController: UserIndicatorControllerMock(), userIndicatorController: UserIndicatorControllerMock(),
notificationManager: notificationManager, notificationManager: notificationManager,
stateMachineFactory: stateMachineFactory) stateMachineFactory: stateMachineFactory)
@@ -15,7 +15,6 @@ import WysiwygComposer
@MainActor @MainActor
final class ComposerToolbarViewModelTests { final class ComposerToolbarViewModelTests {
private var appSettings: AppSettings!
private var wysiwygViewModel: WysiwygComposerViewModel! private var wysiwygViewModel: WysiwygComposerViewModel!
private var viewModel: ComposerToolbarViewModel! private var viewModel: ComposerToolbarViewModel!
private var completionSuggestionServiceMock: CompletionSuggestionServiceMock! private var completionSuggestionServiceMock: CompletionSuggestionServiceMock!
@@ -23,8 +22,7 @@ final class ComposerToolbarViewModelTests {
init() { init() {
AppSettings.resetAllSettings() AppSettings.resetAllSettings()
appSettings = AppSettings()
ServiceLocator.shared.register(appSettings: appSettings)
setUpViewModel() setUpViewModel()
} }
@@ -91,13 +89,15 @@ final class ComposerToolbarViewModelTests {
.init(suggestionType: .user(.init(id: "@user_mention_2:matrix.org", displayName: "User 2", avatarURL: nil)), range: .init(), rawSuggestionText: "")] .init(suggestionType: .user(.init(id: "@user_mention_2:matrix.org", displayName: "User 2", avatarURL: nil)), range: .init(), rawSuggestionText: "")]
let mockCompletionSuggestionService = CompletionSuggestionServiceMock(configuration: .init(suggestions: suggestions)) let mockCompletionSuggestionService = CompletionSuggestionServiceMock(configuration: .init(suggestions: suggestions))
let appSettings = AppSettings()
viewModel = ComposerToolbarViewModel(roomProxy: JoinedRoomProxyMock(.init()), viewModel = ComposerToolbarViewModel(roomProxy: JoinedRoomProxyMock(.init()),
wysiwygViewModel: wysiwygViewModel, wysiwygViewModel: wysiwygViewModel,
completionSuggestionService: mockCompletionSuggestionService, completionSuggestionService: mockCompletionSuggestionService,
mediaProvider: MediaProviderMock(configuration: .init()), mediaProvider: MediaProviderMock(configuration: .init()),
mentionDisplayHelper: ComposerMentionDisplayHelper.mock, mentionDisplayHelper: ComposerMentionDisplayHelper.mock,
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
analyticsService: ServiceLocator.shared.analytics, analyticsService: .mock(settings: appSettings),
composerDraftService: draftServiceMock) composerDraftService: draftServiceMock)
#expect(viewModel.state.suggestions == suggestions) #expect(viewModel.state.suggestions == suggestions)
@@ -708,13 +708,15 @@ final class ComposerToolbarViewModelTests {
let mockSubject = CurrentValueSubject<[IdentityStatusChange], Never>([]) let mockSubject = CurrentValueSubject<[IdentityStatusChange], Never>([])
roomProxyMock.underlyingIdentityStatusChangesPublisher = mockSubject.asCurrentValuePublisher() roomProxyMock.underlyingIdentityStatusChangesPublisher = mockSubject.asCurrentValuePublisher()
let appSettings = AppSettings()
viewModel = ComposerToolbarViewModel(roomProxy: roomProxyMock, viewModel = ComposerToolbarViewModel(roomProxy: roomProxyMock,
wysiwygViewModel: wysiwygViewModel, wysiwygViewModel: wysiwygViewModel,
completionSuggestionService: mockCompletionSuggestionService, completionSuggestionService: mockCompletionSuggestionService,
mediaProvider: MediaProviderMock(configuration: .init()), mediaProvider: MediaProviderMock(configuration: .init()),
mentionDisplayHelper: ComposerMentionDisplayHelper.mock, mentionDisplayHelper: ComposerMentionDisplayHelper.mock,
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
analyticsService: ServiceLocator.shared.analytics, analyticsService: .mock(settings: appSettings),
composerDraftService: draftServiceMock) composerDraftService: draftServiceMock)
var fulfillment = deferFulfillment(viewModel.context.$viewState, message: "Composer is disabled") { $0.canSend == false } var fulfillment = deferFulfillment(viewModel.context.$viewState, message: "Composer is disabled") { $0.canSend == false }
@@ -753,13 +755,15 @@ final class ComposerToolbarViewModelTests {
roomProxyMock.underlyingIdentityStatusChangesPublisher = mockSubject.asCurrentValuePublisher() roomProxyMock.underlyingIdentityStatusChangesPublisher = mockSubject.asCurrentValuePublisher()
let appSettings = AppSettings()
viewModel = ComposerToolbarViewModel(roomProxy: roomProxyMock, viewModel = ComposerToolbarViewModel(roomProxy: roomProxyMock,
wysiwygViewModel: wysiwygViewModel, wysiwygViewModel: wysiwygViewModel,
completionSuggestionService: mockCompletionSuggestionService, completionSuggestionService: mockCompletionSuggestionService,
mediaProvider: MediaProviderMock(configuration: .init()), mediaProvider: MediaProviderMock(configuration: .init()),
mentionDisplayHelper: ComposerMentionDisplayHelper.mock, mentionDisplayHelper: ComposerMentionDisplayHelper.mock,
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
analyticsService: ServiceLocator.shared.analytics, analyticsService: .mock(settings: appSettings),
composerDraftService: draftServiceMock) composerDraftService: draftServiceMock)
var fulfillment = deferFulfillment(viewModel.context.$viewState, message: "Composer is disabled") { $0.canSend == false } var fulfillment = deferFulfillment(viewModel.context.$viewState, message: "Composer is disabled") { $0.canSend == false }
@@ -787,14 +791,15 @@ final class ComposerToolbarViewModelTests {
} }
roomProxyMock.underlyingIdentityStatusChangesPublisher = CurrentValueSubject([IdentityStatusChange(userId: "@alice:localhost", changedTo: .pinViolation)]).asCurrentValuePublisher() roomProxyMock.underlyingIdentityStatusChangesPublisher = CurrentValueSubject([IdentityStatusChange(userId: "@alice:localhost", changedTo: .pinViolation)]).asCurrentValuePublisher()
let appSettings = AppSettings()
viewModel = ComposerToolbarViewModel(roomProxy: roomProxyMock, viewModel = ComposerToolbarViewModel(roomProxy: roomProxyMock,
wysiwygViewModel: wysiwygViewModel, wysiwygViewModel: wysiwygViewModel,
completionSuggestionService: mockCompletionSuggestionService, completionSuggestionService: mockCompletionSuggestionService,
mediaProvider: MediaProviderMock(configuration: .init()), mediaProvider: MediaProviderMock(configuration: .init()),
mentionDisplayHelper: ComposerMentionDisplayHelper.mock, mentionDisplayHelper: ComposerMentionDisplayHelper.mock,
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
analyticsService: ServiceLocator.shared.analytics, analyticsService: .mock(settings: appSettings),
composerDraftService: draftServiceMock) composerDraftService: draftServiceMock)
let deferred = deferFulfillment(viewModel.context.$viewState, message: "Composer should be enabled") { $0.canSend == true } let deferred = deferFulfillment(viewModel.context.$viewState, message: "Composer should be enabled") { $0.canSend == true }
@@ -811,14 +816,16 @@ final class ComposerToolbarViewModelTests {
draftServiceMock.loadDraftClosure = loadDraftClosure draftServiceMock.loadDraftClosure = loadDraftClosure
} }
let appSettings = AppSettings()
viewModel = ComposerToolbarViewModel(initialText: initialText, viewModel = ComposerToolbarViewModel(initialText: initialText,
roomProxy: JoinedRoomProxyMock(.init()), roomProxy: JoinedRoomProxyMock(.init()),
wysiwygViewModel: wysiwygViewModel, wysiwygViewModel: wysiwygViewModel,
completionSuggestionService: completionSuggestionServiceMock, completionSuggestionService: completionSuggestionServiceMock,
mediaProvider: MediaProviderMock(configuration: .init()), mediaProvider: MediaProviderMock(configuration: .init()),
mentionDisplayHelper: ComposerMentionDisplayHelper.mock, mentionDisplayHelper: ComposerMentionDisplayHelper.mock,
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
analyticsService: ServiceLocator.shared.analytics, analyticsService: .mock(settings: appSettings),
composerDraftService: draftServiceMock) composerDraftService: draftServiceMock)
viewModel.context.composerFormattingEnabled = true viewModel.context.composerFormattingEnabled = true
} }
@@ -17,12 +17,20 @@ final class CreateRoomScreenViewModelTests {
var spaceService: SpaceServiceProxyMock! var spaceService: SpaceServiceProxyMock!
var userSession: UserSessionMock! var userSession: UserSessionMock!
private let appSettings: AppSettings
private let analytics: AnalyticsService
private let usersSubject = CurrentValueSubject<[UserProfileProxy], Never>([]) private let usersSubject = CurrentValueSubject<[UserProfileProxy], Never>([])
var context: CreateRoomScreenViewModel.Context { var context: CreateRoomScreenViewModel.Context {
viewModel.context viewModel.context
} }
init() {
appSettings = AppSettings()
analytics = .mock(settings: appSettings)
}
deinit { deinit {
AppSettings.resetAllSettings() AppSettings.resetAllSettings()
viewModel = nil viewModel = nil
@@ -82,14 +90,14 @@ final class CreateRoomScreenViewModelTests {
spaceServiceConfiguration: .init(spaceRoomLists: ["1": .init()]))) spaceServiceConfiguration: .init(spaceRoomLists: ["1": .init()])))
clientProxy.roomForIdentifierClosure = { roomID in .joined(JoinedRoomProxyMock(.init(id: roomID))) } clientProxy.roomForIdentifierClosure = { roomID in .joined(JoinedRoomProxyMock(.init(id: roomID))) }
userSession = UserSessionMock(.init(clientProxy: clientProxy)) userSession = UserSessionMock(.init(clientProxy: clientProxy))
ServiceLocator.shared.settings.knockingEnabled = true appSettings.knockingEnabled = true
let viewModel = CreateRoomScreenViewModel(isSpace: true, let viewModel = CreateRoomScreenViewModel(isSpace: true,
spaceSelectionMode: .none, spaceSelectionMode: .none,
shouldShowCancelButton: false, shouldShowCancelButton: false,
userSession: userSession, userSession: userSession,
analytics: ServiceLocator.shared.analytics, analytics: analytics,
userIndicatorController: UserIndicatorControllerMock(), userIndicatorController: UserIndicatorControllerMock(),
appSettings: ServiceLocator.shared.settings) appSettings: appSettings)
self.viewModel = viewModel self.viewModel = viewModel
// Given a form with a blank topic. // Given a form with a blank topic.
@@ -332,14 +340,14 @@ final class CreateRoomScreenViewModelTests {
clientProxy.spaceService = spaceService clientProxy.spaceService = spaceService
clientProxy.roomForIdentifierClosure = { roomID in .joined(JoinedRoomProxyMock(.init(id: roomID))) } clientProxy.roomForIdentifierClosure = { roomID in .joined(JoinedRoomProxyMock(.init(id: roomID))) }
userSession = UserSessionMock(.init(clientProxy: clientProxy)) userSession = UserSessionMock(.init(clientProxy: clientProxy))
ServiceLocator.shared.settings.knockingEnabled = true appSettings.knockingEnabled = true
let viewModel = CreateRoomScreenViewModel(isSpace: isSpace, let viewModel = CreateRoomScreenViewModel(isSpace: isSpace,
spaceSelectionMode: spacesSelectionMode, spaceSelectionMode: spacesSelectionMode,
shouldShowCancelButton: false, shouldShowCancelButton: false,
userSession: userSession, userSession: userSession,
analytics: ServiceLocator.shared.analytics, analytics: analytics,
userIndicatorController: UserIndicatorControllerMock(), userIndicatorController: UserIndicatorControllerMock(),
appSettings: ServiceLocator.shared.settings) appSettings: appSettings)
self.viewModel = viewModel self.viewModel = viewModel
} }
} }
@@ -45,7 +45,7 @@ struct EmojiPickerScreenViewModelTests {
viewModel = EmojiPickerScreenViewModel(itemID: .randomEvent, viewModel = EmojiPickerScreenViewModel(itemID: .randomEvent,
selectedEmojis: selectedEmojis, selectedEmojis: selectedEmojis,
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings), emojiProvider: EmojiProvider(appSettings: AppSettings()),
timelineController: MockTimelineController(timelineProxy: timelineProxy)) timelineController: MockTimelineController(timelineProxy: timelineProxy))
} }
} }
+4 -4
View File
@@ -19,7 +19,7 @@ struct EmojiProviderTests {
let emojiLoaderMock = EmojiLoaderMock() let emojiLoaderMock = EmojiLoaderMock()
emojiLoaderMock.categories = [category] emojiLoaderMock.categories = [category]
let emojiProvider = EmojiProvider(loader: emojiLoaderMock, appSettings: ServiceLocator.shared.settings) let emojiProvider = EmojiProvider(loader: emojiLoaderMock, appSettings: AppSettings())
let categories = await emojiProvider.categories() let categories = await emojiProvider.categories()
#expect(emojiLoaderMock.categories == categories) #expect(emojiLoaderMock.categories == categories)
@@ -33,7 +33,7 @@ struct EmojiProviderTests {
let emojiLoaderMock = EmojiLoaderMock() let emojiLoaderMock = EmojiLoaderMock()
emojiLoaderMock.categories = [category] emojiLoaderMock.categories = [category]
let emojiProvider = EmojiProvider(loader: emojiLoaderMock, appSettings: ServiceLocator.shared.settings) let emojiProvider = EmojiProvider(loader: emojiLoaderMock, appSettings: AppSettings())
let categories = await emojiProvider.categories(searchString: "") let categories = await emojiProvider.categories(searchString: "")
#expect(emojiLoaderMock.categories == categories) #expect(emojiLoaderMock.categories == categories)
@@ -51,7 +51,7 @@ struct EmojiProviderTests {
let emojiLoaderMock = EmojiLoaderMock() let emojiLoaderMock = EmojiLoaderMock()
emojiLoaderMock.categories = categoriesForFirstLoad emojiLoaderMock.categories = categoriesForFirstLoad
let emojiProvider = EmojiProvider(loader: emojiLoaderMock, appSettings: ServiceLocator.shared.settings) let emojiProvider = EmojiProvider(loader: emojiLoaderMock, appSettings: AppSettings())
_ = await emojiProvider.categories() _ = await emojiProvider.categories()
emojiLoaderMock.categories = categoriesForSecondLoad emojiLoaderMock.categories = categoriesForSecondLoad
@@ -82,7 +82,7 @@ struct EmojiProviderTests {
let emojiLoaderMock = EmojiLoaderMock() let emojiLoaderMock = EmojiLoaderMock()
emojiLoaderMock.categories = categories emojiLoaderMock.categories = categories
let emojiProvider = EmojiProvider(loader: emojiLoaderMock, appSettings: ServiceLocator.shared.settings) let emojiProvider = EmojiProvider(loader: emojiLoaderMock, appSettings: AppSettings())
_ = await emojiProvider.categories() _ = await emojiProvider.categories()
let result = await emojiProvider.categories(searchString: searchString) let result = await emojiProvider.categories(searchString: searchString)
@@ -19,15 +19,18 @@ final class HomeScreenViewModelTests {
var clientProxy: ClientProxyMock! var clientProxy: ClientProxyMock!
var roomSummaryProvider: RoomSummaryProviderMock! var roomSummaryProvider: RoomSummaryProviderMock!
var appSettings: AppSettings!
var notificationManager: NotificationManagerMock! var notificationManager: NotificationManagerMock!
private let appSettings: AppSettings
private let analytics: AnalyticsService
private let userIndicatorController: UserIndicatorControllerProtocol
var cancellables = Set<AnyCancellable>() var cancellables = Set<AnyCancellable>()
init() { init() {
AppSettings.resetAllSettings() AppSettings.resetAllSettings()
appSettings = AppSettings() appSettings = AppSettings()
ServiceLocator.shared.register(appSettings: appSettings) analytics = .mock(settings: appSettings)
userIndicatorController = UserIndicatorControllerMock.default
} }
deinit { deinit {
@@ -441,9 +444,9 @@ final class HomeScreenViewModelTests {
viewModel = HomeScreenViewModel(userSession: userSession, viewModel = HomeScreenViewModel(userSession: userSession,
selectedRoomPublisher: CurrentValueSubject<String?, Never>(nil).asCurrentValuePublisher(), selectedRoomPublisher: CurrentValueSubject<String?, Never>(nil).asCurrentValuePublisher(),
appSettings: appSettings, appSettings: appSettings,
analyticsService: ServiceLocator.shared.analytics, analyticsService: analytics,
notificationManager: notificationManager, notificationManager: notificationManager,
userIndicatorController: ServiceLocator.shared.userIndicatorController) userIndicatorController: userIndicatorController)
} }
} }
@@ -15,12 +15,9 @@ final class InviteUsersScreenViewModelTests {
var viewModel: InviteUsersScreenViewModelProtocol! var viewModel: InviteUsersScreenViewModelProtocol!
var userDiscoveryService: UserDiscoveryServiceMock! var userDiscoveryService: UserDiscoveryServiceMock!
var clientProxy: ClientProxyMock! var clientProxy: ClientProxyMock!
var appSettings: AppSettings!
init() { init() {
AppSettings.resetAllSettings() AppSettings.resetAllSettings()
appSettings = AppSettings()
ServiceLocator.shared.register(appSettings: appSettings)
} }
deinit { deinit {
@@ -175,7 +172,7 @@ final class InviteUsersScreenViewModelTests {
isSkippable: isSkippable, isSkippable: isSkippable,
userDiscoveryService: userDiscoveryService, userDiscoveryService: userDiscoveryService,
userIndicatorController: UserIndicatorControllerMock(), userIndicatorController: UserIndicatorControllerMock(),
appSettings: ServiceLocator.shared.settings) appSettings: AppSettings())
viewModel.state.usersSection = .init(type: .suggestions, users: [.mockAlice, .mockBob, .mockCharlie]) viewModel.state.usersSection = .init(type: .suggestions, users: [.mockAlice, .mockBob, .mockCharlie])
self.viewModel = viewModel self.viewModel = viewModel
} }
@@ -21,16 +21,16 @@ final class JoinRoomScreenViewModelTests {
var viewModel: JoinRoomScreenViewModelProtocol! var viewModel: JoinRoomScreenViewModelProtocol!
var clientProxy: ClientProxyMock! var clientProxy: ClientProxyMock!
var appSettings: AppSettings!
var context: JoinRoomScreenViewModelType.Context { var context: JoinRoomScreenViewModelType.Context {
viewModel.context viewModel.context
} }
private let appSettings: AppSettings
init() { init() {
AppSettings.resetAllSettings() AppSettings.resetAllSettings()
appSettings = AppSettings() appSettings = AppSettings()
ServiceLocator.shared.register(appSettings: appSettings)
} }
deinit { deinit {
@@ -205,7 +205,7 @@ final class JoinRoomScreenViewModelTests {
viewModel = JoinRoomScreenViewModel(source: .generic(roomID: "1", via: []), viewModel = JoinRoomScreenViewModel(source: .generic(roomID: "1", via: []),
appSettings: appSettings, appSettings: appSettings,
userSession: UserSessionMock(.init(clientProxy: clientProxy)), userSession: UserSessionMock(.init(clientProxy: clientProxy)),
userIndicatorController: ServiceLocator.shared.userIndicatorController) userIndicatorController: UserIndicatorControllerMock.default)
} }
} }
@@ -394,12 +394,14 @@ struct LocationSharingScreenViewModelTests {
let roomProxyMock = JoinedRoomProxyMock(.init(members: .allMembers)) let roomProxyMock = JoinedRoomProxyMock(.init(members: .allMembers))
roomProxyMock.makeLiveLocationServiceReturnValue = liveLocationServiceMock roomProxyMock.makeLiveLocationServiceReturnValue = liveLocationServiceMock
let appSettings = AppSettings()
viewModel = LocationSharingScreenViewModel(interactionMode: .viewLive(sender: nil, initialLiveLocationShare: nil), viewModel = LocationSharingScreenViewModel(interactionMode: .viewLive(sender: nil, initialLiveLocationShare: nil),
mapURLBuilder: ServiceLocator.shared.settings.mapTilerConfiguration, mapURLBuilder: appSettings.mapTilerConfiguration,
roomProxy: roomProxyMock, roomProxy: roomProxyMock,
timelineController: MockTimelineController(timelineProxy: TimelineProxyMock(.init())), timelineController: MockTimelineController(timelineProxy: TimelineProxyMock(.init())),
liveLocationManager: LiveLocationManagerMock(.init()), liveLocationManager: LiveLocationManagerMock(.init()),
analytics: ServiceLocator.shared.analytics, analytics: .mock(settings: appSettings),
userIndicatorController: UserIndicatorControllerMock(), userIndicatorController: UserIndicatorControllerMock(),
mediaProvider: MediaProviderMock(configuration: .init())) mediaProvider: MediaProviderMock(configuration: .init()))
@@ -427,13 +429,14 @@ struct LocationSharingScreenViewModelTests {
private mutating func setupViewModel(liveLocationManagerConfiguration: LiveLocationManagerMock.Configuration = .init(), private mutating func setupViewModel(liveLocationManagerConfiguration: LiveLocationManagerMock.Configuration = .init(),
members: [RoomMemberProxyMock] = .allMembersAsAdmin) { members: [RoomMemberProxyMock] = .allMembersAsAdmin) {
let appSettings = AppSettings()
timelineProxy = TimelineProxyMock(.init()) timelineProxy = TimelineProxyMock(.init())
viewModel = LocationSharingScreenViewModel(interactionMode: .picker(shouldShowLiveLocationOption: true), viewModel = LocationSharingScreenViewModel(interactionMode: .picker(shouldShowLiveLocationOption: true),
mapURLBuilder: ServiceLocator.shared.settings.mapTilerConfiguration, mapURLBuilder: appSettings.mapTilerConfiguration,
roomProxy: JoinedRoomProxyMock(.init(members: members)), roomProxy: JoinedRoomProxyMock(.init(members: members)),
timelineController: MockTimelineController(timelineProxy: timelineProxy), timelineController: MockTimelineController(timelineProxy: timelineProxy),
liveLocationManager: LiveLocationManagerMock(liveLocationManagerConfiguration), liveLocationManager: LiveLocationManagerMock(liveLocationManagerConfiguration),
analytics: ServiceLocator.shared.analytics, analytics: .mock(settings: appSettings),
userIndicatorController: UserIndicatorControllerMock(), userIndicatorController: UserIndicatorControllerMock(),
mediaProvider: MediaProviderMock(configuration: .init())) mediaProvider: MediaProviderMock(configuration: .init()))
viewModel.state.bindings.isLocationAuthorized = true viewModel.state.bindings.isLocationAuthorized = true
@@ -441,13 +444,14 @@ struct LocationSharingScreenViewModelTests {
private mutating func setupViewModel(liveLocationManagerMock: LiveLocationManagerMock, private mutating func setupViewModel(liveLocationManagerMock: LiveLocationManagerMock,
members: [RoomMemberProxyMock] = .allMembersAsAdmin) { members: [RoomMemberProxyMock] = .allMembersAsAdmin) {
let appSettings = AppSettings()
timelineProxy = TimelineProxyMock(.init()) timelineProxy = TimelineProxyMock(.init())
viewModel = LocationSharingScreenViewModel(interactionMode: .picker(shouldShowLiveLocationOption: true), viewModel = LocationSharingScreenViewModel(interactionMode: .picker(shouldShowLiveLocationOption: true),
mapURLBuilder: ServiceLocator.shared.settings.mapTilerConfiguration, mapURLBuilder: appSettings.mapTilerConfiguration,
roomProxy: JoinedRoomProxyMock(.init(members: members)), roomProxy: JoinedRoomProxyMock(.init(members: members)),
timelineController: MockTimelineController(timelineProxy: timelineProxy), timelineController: MockTimelineController(timelineProxy: timelineProxy),
liveLocationManager: liveLocationManagerMock, liveLocationManager: liveLocationManagerMock,
analytics: ServiceLocator.shared.analytics, analytics: .mock(settings: appSettings),
userIndicatorController: UserIndicatorControllerMock(), userIndicatorController: UserIndicatorControllerMock(),
mediaProvider: MediaProviderMock(configuration: .init())) mediaProvider: MediaProviderMock(configuration: .init()))
viewModel.state.bindings.isLocationAuthorized = true viewModel.state.bindings.isLocationAuthorized = true
@@ -457,6 +461,7 @@ struct LocationSharingScreenViewModelTests {
initialShare: LiveLocationShare, initialShare: LiveLocationShare,
liveLocationsSubject: CurrentValueSubject<[LiveLocationShare], Never>, liveLocationsSubject: CurrentValueSubject<[LiveLocationShare], Never>,
members: [RoomMemberProxyMock] = .allMembers) { members: [RoomMemberProxyMock] = .allMembers) {
let appSettings = AppSettings()
let liveLocationServiceMock = RoomLiveLocationServiceMock() let liveLocationServiceMock = RoomLiveLocationServiceMock()
liveLocationServiceMock.liveLocationsPublisher = liveLocationsSubject.asCurrentValuePublisher() liveLocationServiceMock.liveLocationsPublisher = liveLocationsSubject.asCurrentValuePublisher()
@@ -464,11 +469,11 @@ struct LocationSharingScreenViewModelTests {
roomProxyMock.makeLiveLocationServiceReturnValue = liveLocationServiceMock roomProxyMock.makeLiveLocationServiceReturnValue = liveLocationServiceMock
viewModel = LocationSharingScreenViewModel(interactionMode: .viewLive(sender: sender, initialLiveLocationShare: initialShare), viewModel = LocationSharingScreenViewModel(interactionMode: .viewLive(sender: sender, initialLiveLocationShare: initialShare),
mapURLBuilder: ServiceLocator.shared.settings.mapTilerConfiguration, mapURLBuilder: appSettings.mapTilerConfiguration,
roomProxy: roomProxyMock, roomProxy: roomProxyMock,
timelineController: MockTimelineController(timelineProxy: TimelineProxyMock(.init())), timelineController: MockTimelineController(timelineProxy: TimelineProxyMock(.init())),
liveLocationManager: LiveLocationManagerMock(.init()), liveLocationManager: LiveLocationManagerMock(.init()),
analytics: ServiceLocator.shared.analytics, analytics: .mock(settings: appSettings),
userIndicatorController: UserIndicatorControllerMock(), userIndicatorController: UserIndicatorControllerMock(),
mediaProvider: MediaProviderMock(configuration: .init())) mediaProvider: MediaProviderMock(configuration: .init()))
} }
@@ -227,12 +227,14 @@ struct LoginScreenViewModelTests {
// MARK: - Helpers // MARK: - Helpers
private mutating func setupViewModel(homeserverAddress: String = "example.com", loginHint: String? = nil) async { private mutating func setupViewModel(homeserverAddress: String = "example.com", loginHint: String? = nil) async {
let appSettings = AppSettings()
clientFactory = AuthenticationClientFactoryMock(configuration: .init()) clientFactory = AuthenticationClientFactoryMock(configuration: .init())
service = AuthenticationService(userSessionStore: UserSessionStoreMock(configuration: .init()), service = AuthenticationService(userSessionStore: UserSessionStoreMock(configuration: .init()),
encryptionKeyProvider: EncryptionKeyProvider(), encryptionKeyProvider: EncryptionKeyProvider(),
classicAppManager: nil, classicAppManager: nil,
clientFactory: clientFactory, clientFactory: clientFactory,
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
appHooks: AppHooks()) appHooks: AppHooks())
guard case .success = await service guard case .success = await service
@@ -244,7 +246,7 @@ struct LoginScreenViewModelTests {
viewModel = LoginScreenViewModel(authenticationService: service, viewModel = LoginScreenViewModel(authenticationService: service,
loginHint: loginHint, loginHint: loginHint,
userIndicatorController: UserIndicatorControllerMock(), userIndicatorController: UserIndicatorControllerMock(),
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
analytics: ServiceLocator.shared.analytics) analytics: .mock(settings: appSettings))
} }
} }
@@ -32,7 +32,7 @@ struct ManageRoomMemberSheetViewModelTests {
permissions: .init(canKick: true, canBan: true, ownPowerLevel: RoomMemberProxyMock.mockAdmin.powerLevel), permissions: .init(canKick: true, canBan: true, ownPowerLevel: RoomMemberProxyMock.mockAdmin.powerLevel),
roomProxy: roomProxy, roomProxy: roomProxy,
userIndicatorController: UserIndicatorControllerMock(), userIndicatorController: UserIndicatorControllerMock(),
analyticsService: ServiceLocator.shared.analytics, analyticsService: .mock(),
mediaProvider: MediaProviderMock(configuration: .init())) mediaProvider: MediaProviderMock(configuration: .init()))
let deferred = deferFulfillment(context.observe(\.viewState.bindings.alertInfo)) { $0 != nil } let deferred = deferFulfillment(context.observe(\.viewState.bindings.alertInfo)) { $0 != nil }
@@ -64,7 +64,7 @@ struct ManageRoomMemberSheetViewModelTests {
permissions: .init(canKick: true, canBan: true, ownPowerLevel: RoomMemberProxyMock.mockAdmin.powerLevel), permissions: .init(canKick: true, canBan: true, ownPowerLevel: RoomMemberProxyMock.mockAdmin.powerLevel),
roomProxy: roomProxy, roomProxy: roomProxy,
userIndicatorController: UserIndicatorControllerMock(), userIndicatorController: UserIndicatorControllerMock(),
analyticsService: ServiceLocator.shared.analytics, analyticsService: .mock(),
mediaProvider: MediaProviderMock(configuration: .init())) mediaProvider: MediaProviderMock(configuration: .init()))
let deferred = deferFulfillment(context.observe(\.viewState.bindings.alertInfo)) { $0 != nil } let deferred = deferFulfillment(context.observe(\.viewState.bindings.alertInfo)) { $0 != nil }
@@ -87,7 +87,7 @@ struct ManageRoomMemberSheetViewModelTests {
permissions: .init(canKick: true, canBan: true, ownPowerLevel: RoomMemberProxyMock.mockAdmin.powerLevel), permissions: .init(canKick: true, canBan: true, ownPowerLevel: RoomMemberProxyMock.mockAdmin.powerLevel),
roomProxy: roomProxy, roomProxy: roomProxy,
userIndicatorController: UserIndicatorControllerMock(), userIndicatorController: UserIndicatorControllerMock(),
analyticsService: ServiceLocator.shared.analytics, analyticsService: .mock(),
mediaProvider: MediaProviderMock(configuration: .init())) mediaProvider: MediaProviderMock(configuration: .init()))
let deferredAction = deferFulfillment(viewModel.actions) { action in let deferredAction = deferFulfillment(viewModel.actions) { action in
@@ -14,7 +14,8 @@ import Testing
final class MediaUploadPreviewScreenViewModelTests { final class MediaUploadPreviewScreenViewModelTests {
var timelineProxy: TimelineProxyMock! var timelineProxy: TimelineProxyMock!
var clientProxy: ClientProxyMock! var clientProxy: ClientProxyMock!
var userIndicatorController: UserIndicatorControllerMock! var userIndicatorController: UserIndicatorControllerMock
private let appSettings: AppSettings
var viewModel: MediaUploadPreviewScreenViewModel! var viewModel: MediaUploadPreviewScreenViewModel!
var context: MediaUploadPreviewScreenViewModel.Context { var context: MediaUploadPreviewScreenViewModel.Context {
@@ -28,9 +29,10 @@ final class MediaUploadPreviewScreenViewModelTests {
init() { init() {
AppSettings.resetAllSettings() AppSettings.resetAllSettings()
let appSettings = AppSettings() appSettings = AppSettings()
appSettings.optimizeMediaUploads = false appSettings.optimizeMediaUploads = false
ServiceLocator.shared.register(appSettings: appSettings)
userIndicatorController = UserIndicatorControllerMock.default
} }
deinit { deinit {
@@ -290,13 +292,11 @@ final class MediaUploadPreviewScreenViewModelTests {
clientProxy.underlyingMaxMediaUploadSize = maxUploadSizeResult clientProxy.underlyingMaxMediaUploadSize = maxUploadSizeResult
} }
userIndicatorController = UserIndicatorControllerMock()
viewModel = MediaUploadPreviewScreenViewModel(mediaURLs: urls, viewModel = MediaUploadPreviewScreenViewModel(mediaURLs: urls,
title: "Some File", title: "Some File",
isRoomEncrypted: true, isRoomEncrypted: true,
shouldShowCaptionWarning: true, shouldShowCaptionWarning: true,
mediaUploadingPreprocessor: MediaUploadingPreprocessor(appSettings: ServiceLocator.shared.settings), mediaUploadingPreprocessor: MediaUploadingPreprocessor(appSettings: appSettings),
timelineController: MockTimelineController(timelineProxy: timelineProxy), timelineController: MockTimelineController(timelineProxy: timelineProxy),
clientProxy: clientProxy, clientProxy: clientProxy,
userIndicatorController: userIndicatorController) userIndicatorController: userIndicatorController)
@@ -20,7 +20,6 @@ final class MediaUploadingPreprocessorTests {
AppSettings.resetAllSettings() AppSettings.resetAllSettings()
appSettings = AppSettings() appSettings = AppSettings()
appSettings.optimizeMediaUploads = false appSettings.optimizeMediaUploads = false
ServiceLocator.shared.register(appSettings: appSettings)
mediaUploadingPreprocessor = MediaUploadingPreprocessor(appSettings: appSettings) mediaUploadingPreprocessor = MediaUploadingPreprocessor(appSettings: appSettings)
} }
@@ -22,13 +22,11 @@ final class NotificationManagerTests {
private var handleInlineReplyDelegateCalled = false private var handleInlineReplyDelegateCalled = false
private var notificationTappedDelegateCalled = false private var notificationTappedDelegateCalled = false
private var registerForRemoteNotificationsDelegateCalled: (() -> Void)? private var registerForRemoteNotificationsDelegateCalled: (() -> Void)?
private let appSettings: AppSettings
private var appSettings: AppSettings {
ServiceLocator.shared.settings
}
init() { init() {
AppSettings.resetAllSettings() AppSettings.resetAllSettings()
appSettings = AppSettings()
notificationCenter = UserNotificationCenterMock() notificationCenter = UserNotificationCenterMock()
notificationCenter.requestAuthorizationOptionsReturnValue = true notificationCenter.requestAuthorizationOptionsReturnValue = true
notificationCenter.authorizationStatusReturnValue = .authorized notificationCenter.authorizationStatusReturnValue = .authorized
+88 -44
View File
@@ -15,6 +15,10 @@ import Testing
struct PillContextTests { struct PillContextTests {
@Test @Test
func user() async { func user() async {
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
let userIndicatorController = UserIndicatorControllerMock.default
let id = "@test:matrix.org" let id = "@test:matrix.org"
let proxyMock = JoinedRoomProxyMock(.init(name: "Test")) let proxyMock = JoinedRoomProxyMock(.init(name: "Test"))
let subject = CurrentValueSubject<[RoomMemberProxyProtocol], Never>([]) let subject = CurrentValueSubject<[RoomMemberProxyProtocol], Never>([])
@@ -23,11 +27,11 @@ struct PillContextTests {
timelineController: MockTimelineController(), timelineController: MockTimelineController(),
userSession: UserSessionMock(.init()), userSession: UserSessionMock(.init()),
mediaPlayerProvider: MediaPlayerProviderMock(), mediaPlayerProvider: MediaPlayerProviderMock(),
userIndicatorController: ServiceLocator.shared.userIndicatorController, userIndicatorController: userIndicatorController,
appMediator: AppMediatorMock.default, appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
analyticsService: ServiceLocator.shared.analytics, analyticsService: analytics,
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings), emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(), linkMetadataProvider: LinkMetadataProvider(),
timelineControllerFactory: TimelineControllerFactoryMock(.init())) timelineControllerFactory: TimelineControllerFactoryMock(.init()))
let context = PillContext(timelineContext: mock.context, data: PillTextAttachmentData(type: .user(userID: id), font: .preferredFont(forTextStyle: .body))) let context = PillContext(timelineContext: mock.context, data: PillTextAttachmentData(type: .user(userID: id), font: .preferredFont(forTextStyle: .body)))
@@ -46,6 +50,10 @@ struct PillContextTests {
@Test @Test
func ownUser() { func ownUser() {
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
let userIndicatorController = UserIndicatorControllerMock.default
let id = "@test:matrix.org" let id = "@test:matrix.org"
let proxyMock = JoinedRoomProxyMock(.init(name: "Test", ownUserID: id)) let proxyMock = JoinedRoomProxyMock(.init(name: "Test", ownUserID: id))
let subject = CurrentValueSubject<[RoomMemberProxyProtocol], Never>([]) let subject = CurrentValueSubject<[RoomMemberProxyProtocol], Never>([])
@@ -54,11 +62,11 @@ struct PillContextTests {
timelineController: MockTimelineController(), timelineController: MockTimelineController(),
userSession: UserSessionMock(.init()), userSession: UserSessionMock(.init()),
mediaPlayerProvider: MediaPlayerProviderMock(), mediaPlayerProvider: MediaPlayerProviderMock(),
userIndicatorController: ServiceLocator.shared.userIndicatorController, userIndicatorController: userIndicatorController,
appMediator: AppMediatorMock.default, appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
analyticsService: ServiceLocator.shared.analytics, analyticsService: analytics,
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings), emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(), linkMetadataProvider: LinkMetadataProvider(),
timelineControllerFactory: TimelineControllerFactoryMock(.init())) timelineControllerFactory: TimelineControllerFactoryMock(.init()))
let context = PillContext(timelineContext: mock.context, data: PillTextAttachmentData(type: .user(userID: id), font: .preferredFont(forTextStyle: .body))) let context = PillContext(timelineContext: mock.context, data: PillTextAttachmentData(type: .user(userID: id), font: .preferredFont(forTextStyle: .body)))
@@ -68,6 +76,10 @@ struct PillContextTests {
@Test @Test
func allUsers() { func allUsers() {
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
let userIndicatorController = UserIndicatorControllerMock.default
let avatarURL = URL(string: "https://matrix.jpg") let avatarURL = URL(string: "https://matrix.jpg")
let id = "test_room" let id = "test_room"
let displayName = "Test" let displayName = "Test"
@@ -78,11 +90,11 @@ struct PillContextTests {
timelineController: mockController, timelineController: mockController,
userSession: UserSessionMock(.init()), userSession: UserSessionMock(.init()),
mediaPlayerProvider: MediaPlayerProviderMock(), mediaPlayerProvider: MediaPlayerProviderMock(),
userIndicatorController: ServiceLocator.shared.userIndicatorController, userIndicatorController: userIndicatorController,
appMediator: AppMediatorMock.default, appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
analyticsService: ServiceLocator.shared.analytics, analyticsService: analytics,
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings), emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(), linkMetadataProvider: LinkMetadataProvider(),
timelineControllerFactory: TimelineControllerFactoryMock(.init())) timelineControllerFactory: TimelineControllerFactoryMock(.init()))
let context = PillContext(timelineContext: mock.context, data: PillTextAttachmentData(type: .allUsers, font: .preferredFont(forTextStyle: .body))) let context = PillContext(timelineContext: mock.context, data: PillTextAttachmentData(type: .allUsers, font: .preferredFont(forTextStyle: .body)))
@@ -93,6 +105,10 @@ struct PillContextTests {
@Test @Test
func roomIDMention() { func roomIDMention() {
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
let userIndicatorController = UserIndicatorControllerMock.default
let proxyMock = JoinedRoomProxyMock(.init()) let proxyMock = JoinedRoomProxyMock(.init())
let mockController = MockTimelineController() let mockController = MockTimelineController()
let clientMock = ClientProxyMock(.init()) let clientMock = ClientProxyMock(.init())
@@ -102,11 +118,11 @@ struct PillContextTests {
timelineController: mockController, timelineController: mockController,
userSession: UserSessionMock(.init(clientProxy: clientMock)), userSession: UserSessionMock(.init(clientProxy: clientMock)),
mediaPlayerProvider: MediaPlayerProviderMock(), mediaPlayerProvider: MediaPlayerProviderMock(),
userIndicatorController: ServiceLocator.shared.userIndicatorController, userIndicatorController: userIndicatorController,
appMediator: AppMediatorMock.default, appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
analyticsService: ServiceLocator.shared.analytics, analyticsService: analytics,
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings), emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(), linkMetadataProvider: LinkMetadataProvider(),
timelineControllerFactory: TimelineControllerFactoryMock(.init())) timelineControllerFactory: TimelineControllerFactoryMock(.init()))
let context = PillContext(timelineContext: mock.context, data: PillTextAttachmentData(type: .roomID("1"), font: .preferredFont(forTextStyle: .body))) let context = PillContext(timelineContext: mock.context, data: PillTextAttachmentData(type: .roomID("1"), font: .preferredFont(forTextStyle: .body)))
@@ -118,6 +134,10 @@ struct PillContextTests {
@Test @Test
func roomIDMentionMissingRoom() { func roomIDMentionMissingRoom() {
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
let userIndicatorController = UserIndicatorControllerMock.default
let proxyMock = JoinedRoomProxyMock(.init()) let proxyMock = JoinedRoomProxyMock(.init())
let mockController = MockTimelineController() let mockController = MockTimelineController()
mockController.roomProxy = proxyMock mockController.roomProxy = proxyMock
@@ -125,11 +145,11 @@ struct PillContextTests {
timelineController: mockController, timelineController: mockController,
userSession: UserSessionMock(.init()), userSession: UserSessionMock(.init()),
mediaPlayerProvider: MediaPlayerProviderMock(), mediaPlayerProvider: MediaPlayerProviderMock(),
userIndicatorController: ServiceLocator.shared.userIndicatorController, userIndicatorController: userIndicatorController,
appMediator: AppMediatorMock.default, appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
analyticsService: ServiceLocator.shared.analytics, analyticsService: analytics,
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings), emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(), linkMetadataProvider: LinkMetadataProvider(),
timelineControllerFactory: TimelineControllerFactoryMock(.init())) timelineControllerFactory: TimelineControllerFactoryMock(.init()))
let context = PillContext(timelineContext: mock.context, data: PillTextAttachmentData(type: .roomID("1"), font: .preferredFont(forTextStyle: .body))) let context = PillContext(timelineContext: mock.context, data: PillTextAttachmentData(type: .roomID("1"), font: .preferredFont(forTextStyle: .body)))
@@ -141,6 +161,10 @@ struct PillContextTests {
@Test @Test
func roomAliasMention() { func roomAliasMention() {
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
let userIndicatorController = UserIndicatorControllerMock.default
let proxyMock = JoinedRoomProxyMock(.init()) let proxyMock = JoinedRoomProxyMock(.init())
let mockController = MockTimelineController() let mockController = MockTimelineController()
mockController.roomProxy = proxyMock mockController.roomProxy = proxyMock
@@ -152,11 +176,11 @@ struct PillContextTests {
timelineController: mockController, timelineController: mockController,
userSession: UserSessionMock(.init(clientProxy: clientMock)), userSession: UserSessionMock(.init(clientProxy: clientMock)),
mediaPlayerProvider: MediaPlayerProviderMock(), mediaPlayerProvider: MediaPlayerProviderMock(),
userIndicatorController: ServiceLocator.shared.userIndicatorController, userIndicatorController: userIndicatorController,
appMediator: AppMediatorMock.default, appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
analyticsService: ServiceLocator.shared.analytics, analyticsService: analytics,
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings), emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(), linkMetadataProvider: LinkMetadataProvider(),
timelineControllerFactory: TimelineControllerFactoryMock(.init())) timelineControllerFactory: TimelineControllerFactoryMock(.init()))
let context = PillContext(timelineContext: mock.context, data: PillTextAttachmentData(type: .roomAlias("#foundation-and-empire:matrix.org"), font: .preferredFont(forTextStyle: .body))) let context = PillContext(timelineContext: mock.context, data: PillTextAttachmentData(type: .roomAlias("#foundation-and-empire:matrix.org"), font: .preferredFont(forTextStyle: .body)))
@@ -168,6 +192,10 @@ struct PillContextTests {
@Test @Test
func roomAliasMentionMissingRoom() { func roomAliasMentionMissingRoom() {
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
let userIndicatorController = UserIndicatorControllerMock.default
let proxyMock = JoinedRoomProxyMock(.init()) let proxyMock = JoinedRoomProxyMock(.init())
let mockController = MockTimelineController() let mockController = MockTimelineController()
mockController.roomProxy = proxyMock mockController.roomProxy = proxyMock
@@ -175,11 +203,11 @@ struct PillContextTests {
timelineController: mockController, timelineController: mockController,
userSession: UserSessionMock(.init()), userSession: UserSessionMock(.init()),
mediaPlayerProvider: MediaPlayerProviderMock(), mediaPlayerProvider: MediaPlayerProviderMock(),
userIndicatorController: ServiceLocator.shared.userIndicatorController, userIndicatorController: userIndicatorController,
appMediator: AppMediatorMock.default, appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
analyticsService: ServiceLocator.shared.analytics, analyticsService: analytics,
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings), emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(), linkMetadataProvider: LinkMetadataProvider(),
timelineControllerFactory: TimelineControllerFactoryMock(.init())) timelineControllerFactory: TimelineControllerFactoryMock(.init()))
let context = PillContext(timelineContext: mock.context, data: PillTextAttachmentData(type: .roomAlias("#foundation-and-empire:matrix.org"), font: .preferredFont(forTextStyle: .body))) let context = PillContext(timelineContext: mock.context, data: PillTextAttachmentData(type: .roomAlias("#foundation-and-empire:matrix.org"), font: .preferredFont(forTextStyle: .body)))
@@ -191,6 +219,10 @@ struct PillContextTests {
@Test @Test
func eventOnRoomIDMention() { func eventOnRoomIDMention() {
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
let userIndicatorController = UserIndicatorControllerMock.default
let proxyMock = JoinedRoomProxyMock(.init()) let proxyMock = JoinedRoomProxyMock(.init())
let mockController = MockTimelineController() let mockController = MockTimelineController()
mockController.roomProxy = proxyMock mockController.roomProxy = proxyMock
@@ -200,11 +232,11 @@ struct PillContextTests {
timelineController: mockController, timelineController: mockController,
userSession: UserSessionMock(.init(clientProxy: clientMock)), userSession: UserSessionMock(.init(clientProxy: clientMock)),
mediaPlayerProvider: MediaPlayerProviderMock(), mediaPlayerProvider: MediaPlayerProviderMock(),
userIndicatorController: ServiceLocator.shared.userIndicatorController, userIndicatorController: userIndicatorController,
appMediator: AppMediatorMock.default, appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
analyticsService: ServiceLocator.shared.analytics, analyticsService: analytics,
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings), emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(), linkMetadataProvider: LinkMetadataProvider(),
timelineControllerFactory: TimelineControllerFactoryMock(.init())) timelineControllerFactory: TimelineControllerFactoryMock(.init()))
let context = PillContext(timelineContext: mock.context, data: PillTextAttachmentData(type: .event(room: .roomID("1")), font: .preferredFont(forTextStyle: .body))) let context = PillContext(timelineContext: mock.context, data: PillTextAttachmentData(type: .event(room: .roomID("1")), font: .preferredFont(forTextStyle: .body)))
@@ -216,6 +248,10 @@ struct PillContextTests {
@Test @Test
func eventOnRoomIDMentionMissingRoom() { func eventOnRoomIDMentionMissingRoom() {
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
let userIndicatorController = UserIndicatorControllerMock.default
let proxyMock = JoinedRoomProxyMock(.init()) let proxyMock = JoinedRoomProxyMock(.init())
let mockController = MockTimelineController() let mockController = MockTimelineController()
mockController.roomProxy = proxyMock mockController.roomProxy = proxyMock
@@ -223,11 +259,11 @@ struct PillContextTests {
timelineController: mockController, timelineController: mockController,
userSession: UserSessionMock(.init()), userSession: UserSessionMock(.init()),
mediaPlayerProvider: MediaPlayerProviderMock(), mediaPlayerProvider: MediaPlayerProviderMock(),
userIndicatorController: ServiceLocator.shared.userIndicatorController, userIndicatorController: userIndicatorController,
appMediator: AppMediatorMock.default, appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
analyticsService: ServiceLocator.shared.analytics, analyticsService: analytics,
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings), emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(), linkMetadataProvider: LinkMetadataProvider(),
timelineControllerFactory: TimelineControllerFactoryMock(.init())) timelineControllerFactory: TimelineControllerFactoryMock(.init()))
let context = PillContext(timelineContext: mock.context, data: PillTextAttachmentData(type: .event(room: .roomID("1")), font: .preferredFont(forTextStyle: .body))) let context = PillContext(timelineContext: mock.context, data: PillTextAttachmentData(type: .event(room: .roomID("1")), font: .preferredFont(forTextStyle: .body)))
@@ -239,6 +275,10 @@ struct PillContextTests {
@Test @Test
func eventOnRoomAliasMention() { func eventOnRoomAliasMention() {
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
let userIndicatorController = UserIndicatorControllerMock.default
let proxyMock = JoinedRoomProxyMock(.init()) let proxyMock = JoinedRoomProxyMock(.init())
let mockController = MockTimelineController() let mockController = MockTimelineController()
mockController.roomProxy = proxyMock mockController.roomProxy = proxyMock
@@ -250,11 +290,11 @@ struct PillContextTests {
timelineController: mockController, timelineController: mockController,
userSession: UserSessionMock(.init(clientProxy: clientMock)), userSession: UserSessionMock(.init(clientProxy: clientMock)),
mediaPlayerProvider: MediaPlayerProviderMock(), mediaPlayerProvider: MediaPlayerProviderMock(),
userIndicatorController: ServiceLocator.shared.userIndicatorController, userIndicatorController: userIndicatorController,
appMediator: AppMediatorMock.default, appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
analyticsService: ServiceLocator.shared.analytics, analyticsService: analytics,
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings), emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(), linkMetadataProvider: LinkMetadataProvider(),
timelineControllerFactory: TimelineControllerFactoryMock(.init())) timelineControllerFactory: TimelineControllerFactoryMock(.init()))
let context = PillContext(timelineContext: mock.context, data: PillTextAttachmentData(type: .event(room: .roomAlias("#foundation-and-empire:matrix.org")), font: .preferredFont(forTextStyle: .body))) let context = PillContext(timelineContext: mock.context, data: PillTextAttachmentData(type: .event(room: .roomAlias("#foundation-and-empire:matrix.org")), font: .preferredFont(forTextStyle: .body)))
@@ -266,6 +306,10 @@ struct PillContextTests {
@Test @Test
func eventOnRoomAliasMentionMissingRoom() { func eventOnRoomAliasMentionMissingRoom() {
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
let userIndicatorController = UserIndicatorControllerMock.default
let proxyMock = JoinedRoomProxyMock(.init()) let proxyMock = JoinedRoomProxyMock(.init())
let mockController = MockTimelineController() let mockController = MockTimelineController()
mockController.roomProxy = proxyMock mockController.roomProxy = proxyMock
@@ -273,11 +317,11 @@ struct PillContextTests {
timelineController: mockController, timelineController: mockController,
userSession: UserSessionMock(.init()), userSession: UserSessionMock(.init()),
mediaPlayerProvider: MediaPlayerProviderMock(), mediaPlayerProvider: MediaPlayerProviderMock(),
userIndicatorController: ServiceLocator.shared.userIndicatorController, userIndicatorController: userIndicatorController,
appMediator: AppMediatorMock.default, appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
analyticsService: ServiceLocator.shared.analytics, analyticsService: analytics,
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings), emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(), linkMetadataProvider: LinkMetadataProvider(),
timelineControllerFactory: TimelineControllerFactoryMock(.init())) timelineControllerFactory: TimelineControllerFactoryMock(.init()))
let context = PillContext(timelineContext: mock.context, data: PillTextAttachmentData(type: .event(room: .roomAlias("#foundation-and-empire:matrix.org")), font: .preferredFont(forTextStyle: .body))) let context = PillContext(timelineContext: mock.context, data: PillTextAttachmentData(type: .event(room: .roomAlias("#foundation-and-empire:matrix.org")), font: .preferredFont(forTextStyle: .body)))
@@ -179,7 +179,7 @@ struct PollFormScreenViewModelTests {
private mutating func setupViewModel(mode: PollFormMode = .new) { private mutating func setupViewModel(mode: PollFormMode = .new) {
viewModel = PollFormScreenViewModel(mode: mode, viewModel = PollFormScreenViewModel(mode: mode,
timelineController: MockTimelineController(timelineProxy: timelineProxy), timelineController: MockTimelineController(timelineProxy: timelineProxy),
analytics: ServiceLocator.shared.analytics, analytics: .mock(),
userIndicatorController: UserIndicatorControllerMock()) userIndicatorController: UserIndicatorControllerMock())
} }
} }
@@ -125,6 +125,6 @@ struct RoomChangePermissionsScreenViewModelTests {
ownPowerLevel: ownPowerLevel, ownPowerLevel: ownPowerLevel,
roomProxy: roomProxy, roomProxy: roomProxy,
userIndicatorController: UserIndicatorControllerMock(), userIndicatorController: UserIndicatorControllerMock(),
analytics: ServiceLocator.shared.analytics) analytics: .mock())
} }
} }
@@ -197,6 +197,6 @@ struct RoomChangeRolesScreenViewModelTests {
roomProxy: roomProxy, roomProxy: roomProxy,
mediaProvider: MediaProviderMock(configuration: .init()), mediaProvider: MediaProviderMock(configuration: .init()),
userIndicatorController: UserIndicatorControllerMock(), userIndicatorController: UserIndicatorControllerMock(),
analytics: ServiceLocator.shared.analytics) analytics: .mock())
} }
} }
@@ -167,7 +167,7 @@ struct RoomDetailsEditScreenViewModelTests {
userIndicatorController = UserIndicatorControllerMock.default userIndicatorController = UserIndicatorControllerMock.default
viewModel = .init(roomProxy: JoinedRoomProxyMock(roomProxyConfiguration), viewModel = .init(roomProxy: JoinedRoomProxyMock(roomProxyConfiguration),
userSession: UserSessionMock(.init()), userSession: UserSessionMock(.init()),
mediaUploadingPreprocessor: MediaUploadingPreprocessor(appSettings: ServiceLocator.shared.settings), mediaUploadingPreprocessor: MediaUploadingPreprocessor(appSettings: AppSettings()),
userIndicatorController: userIndicatorController) userIndicatorController: userIndicatorController)
} }
} }
@@ -26,29 +26,33 @@ struct RoomDetailsScreenViewModelTests {
init() { init() {
AppSettings.resetAllSettings() AppSettings.resetAllSettings()
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
cancellables.removeAll() cancellables.removeAll()
roomProxyMock = JoinedRoomProxyMock(.init(name: "Test")) roomProxyMock = JoinedRoomProxyMock(.init(name: "Test"))
notificationSettingsProxyMock = NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()) notificationSettingsProxyMock = NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration())
viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock,
userSession: UserSessionMock(.init()), userSession: UserSessionMock(.init()),
analyticsService: ServiceLocator.shared.analytics, analyticsService: .mock(settings: appSettings),
userIndicatorController: ServiceLocator.shared.userIndicatorController, userIndicatorController: UserIndicatorControllerMock.default,
notificationSettingsProxy: notificationSettingsProxyMock, notificationSettingsProxy: notificationSettingsProxyMock,
attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()), attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()),
appSettings: ServiceLocator.shared.settings) appSettings: appSettings)
} }
@Test @Test
mutating func leaveRoomTappedWhenPublic() async throws { mutating func leaveRoomTappedWhenPublic() async throws {
let appSettings = AppSettings()
let mockedMembers: [RoomMemberProxyMock] = [.mockBob, .mockAlice] let mockedMembers: [RoomMemberProxyMock] = [.mockBob, .mockAlice]
roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", members: mockedMembers, joinRule: .public)) roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", members: mockedMembers, joinRule: .public))
viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock,
userSession: UserSessionMock(.init()), userSession: UserSessionMock(.init()),
analyticsService: ServiceLocator.shared.analytics, analyticsService: .mock(settings: appSettings),
userIndicatorController: ServiceLocator.shared.userIndicatorController, userIndicatorController: UserIndicatorControllerMock.default,
notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()), notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()),
attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()), attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()),
appSettings: ServiceLocator.shared.settings) appSettings: appSettings)
let deferred = deferFulfillment(context.observe(\.viewState.bindings.leaveRoomAlertItem)) { $0 != nil } let deferred = deferFulfillment(context.observe(\.viewState.bindings.leaveRoomAlertItem)) { $0 != nil }
context.send(viewAction: .processTapLeave) context.send(viewAction: .processTapLeave)
@@ -60,15 +64,17 @@ struct RoomDetailsScreenViewModelTests {
@Test @Test
mutating func leaveRoomTappedWhenRoomNotPublic() async throws { mutating func leaveRoomTappedWhenRoomNotPublic() async throws {
let appSettings = AppSettings()
let mockedMembers: [RoomMemberProxyMock] = [.mockBob, .mockAlice] let mockedMembers: [RoomMemberProxyMock] = [.mockBob, .mockAlice]
roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", members: mockedMembers)) roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", members: mockedMembers))
viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock,
userSession: UserSessionMock(.init()), userSession: UserSessionMock(.init()),
analyticsService: ServiceLocator.shared.analytics, analyticsService: .mock(settings: appSettings),
userIndicatorController: ServiceLocator.shared.userIndicatorController, userIndicatorController: UserIndicatorControllerMock.default,
notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()), notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()),
attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()), attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()),
appSettings: ServiceLocator.shared.settings) appSettings: appSettings)
let deferred = deferFulfillment(context.observe(\.viewState.bindings.leaveRoomAlertItem)) { $0 != nil } let deferred = deferFulfillment(context.observe(\.viewState.bindings.leaveRoomAlertItem)) { $0 != nil }
context.send(viewAction: .processTapLeave) context.send(viewAction: .processTapLeave)
@@ -81,15 +87,17 @@ struct RoomDetailsScreenViewModelTests {
@Test @Test
mutating func leaveRoomTappedWithLessThanTwoMembers() { mutating func leaveRoomTappedWithLessThanTwoMembers() {
let appSettings = AppSettings()
let mockedMembers: [RoomMemberProxyMock] = [.mockAlice] let mockedMembers: [RoomMemberProxyMock] = [.mockAlice]
roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", members: mockedMembers)) roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", members: mockedMembers))
viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock,
userSession: UserSessionMock(.init()), userSession: UserSessionMock(.init()),
analyticsService: ServiceLocator.shared.analytics, analyticsService: .mock(settings: appSettings),
userIndicatorController: ServiceLocator.shared.userIndicatorController, userIndicatorController: UserIndicatorControllerMock.default,
notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()), notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()),
attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()), attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()),
appSettings: ServiceLocator.shared.settings) appSettings: appSettings)
context.send(viewAction: .processTapLeave) context.send(viewAction: .processTapLeave)
#expect(context.leaveRoomAlertItem?.state == .empty) #expect(context.leaveRoomAlertItem?.state == .empty)
@@ -138,16 +146,18 @@ struct RoomDetailsScreenViewModelTests {
@Test @Test
mutating func initialDMDetailsState() async throws { mutating func initialDMDetailsState() async throws {
let appSettings = AppSettings()
let recipient = RoomMemberProxyMock.mockDan let recipient = RoomMemberProxyMock.mockDan
let mockedMembers: [RoomMemberProxyMock] = [.mockMe, recipient] let mockedMembers: [RoomMemberProxyMock] = [.mockMe, recipient]
roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", isDirect: true, isEncrypted: true, members: mockedMembers)) roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", isDirect: true, isEncrypted: true, members: mockedMembers))
viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock,
userSession: UserSessionMock(.init()), userSession: UserSessionMock(.init()),
analyticsService: ServiceLocator.shared.analytics, analyticsService: .mock(settings: appSettings),
userIndicatorController: ServiceLocator.shared.userIndicatorController, userIndicatorController: UserIndicatorControllerMock.default,
notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()), notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()),
attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()), attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()),
appSettings: ServiceLocator.shared.settings) appSettings: appSettings)
let deferred = deferFulfillment(viewModel.context.observe(\.viewState.dmRecipientInfo)) { $0 != nil } let deferred = deferFulfillment(viewModel.context.observe(\.viewState.dmRecipientInfo)) { $0 != nil }
@@ -158,17 +168,19 @@ struct RoomDetailsScreenViewModelTests {
@Test @Test
mutating func ignoreSuccess() async throws { mutating func ignoreSuccess() async throws {
let appSettings = AppSettings()
let recipient = RoomMemberProxyMock.mockDan let recipient = RoomMemberProxyMock.mockDan
let mockedMembers: [RoomMemberProxyMock] = [.mockMe, recipient] let mockedMembers: [RoomMemberProxyMock] = [.mockMe, recipient]
roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", isDirect: true, isEncrypted: true, members: mockedMembers)) roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", isDirect: true, isEncrypted: true, members: mockedMembers))
viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock,
userSession: UserSessionMock(.init()), userSession: UserSessionMock(.init()),
analyticsService: ServiceLocator.shared.analytics, analyticsService: .mock(settings: appSettings),
userIndicatorController: ServiceLocator.shared.userIndicatorController, userIndicatorController: UserIndicatorControllerMock.default,
notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()), notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()),
attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()), attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()),
appSettings: ServiceLocator.shared.settings) appSettings: appSettings)
let deferredRecipient = deferFulfillment(viewModel.context.observe(\.viewState.dmRecipientInfo)) { $0 != nil } let deferredRecipient = deferFulfillment(viewModel.context.observe(\.viewState.dmRecipientInfo)) { $0 != nil }
@@ -188,6 +200,8 @@ struct RoomDetailsScreenViewModelTests {
@Test @Test
mutating func ignoreFailure() async throws { mutating func ignoreFailure() async throws {
let appSettings = AppSettings()
let recipient = RoomMemberProxyMock.mockDan let recipient = RoomMemberProxyMock.mockDan
let mockedMembers: [RoomMemberProxyMock] = [.mockMe, recipient] let mockedMembers: [RoomMemberProxyMock] = [.mockMe, recipient]
let clientProxy = ClientProxyMock(.init()) let clientProxy = ClientProxyMock(.init())
@@ -195,11 +209,11 @@ struct RoomDetailsScreenViewModelTests {
roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", isDirect: true, isEncrypted: true, members: mockedMembers)) roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", isDirect: true, isEncrypted: true, members: mockedMembers))
viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock,
userSession: UserSessionMock(.init(clientProxy: clientProxy)), userSession: UserSessionMock(.init(clientProxy: clientProxy)),
analyticsService: ServiceLocator.shared.analytics, analyticsService: .mock(settings: appSettings),
userIndicatorController: ServiceLocator.shared.userIndicatorController, userIndicatorController: UserIndicatorControllerMock.default,
notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()), notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()),
attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()), attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()),
appSettings: ServiceLocator.shared.settings) appSettings: appSettings)
let deferredRecipient = deferFulfillment(viewModel.context.observe(\.viewState.dmRecipientInfo)) { $0 != nil } let deferredRecipient = deferFulfillment(viewModel.context.observe(\.viewState.dmRecipientInfo)) { $0 != nil }
@@ -220,16 +234,18 @@ struct RoomDetailsScreenViewModelTests {
@Test @Test
mutating func unignoreSuccess() async throws { mutating func unignoreSuccess() async throws {
let appSettings = AppSettings()
let recipient = RoomMemberProxyMock.mockIgnored let recipient = RoomMemberProxyMock.mockIgnored
let mockedMembers: [RoomMemberProxyMock] = [.mockMe, recipient] let mockedMembers: [RoomMemberProxyMock] = [.mockMe, recipient]
roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", isDirect: true, isEncrypted: true, members: mockedMembers)) roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", isDirect: true, isEncrypted: true, members: mockedMembers))
viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock,
userSession: UserSessionMock(.init()), userSession: UserSessionMock(.init()),
analyticsService: ServiceLocator.shared.analytics, analyticsService: .mock(settings: appSettings),
userIndicatorController: ServiceLocator.shared.userIndicatorController, userIndicatorController: UserIndicatorControllerMock.default,
notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()), notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()),
attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()), attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()),
appSettings: ServiceLocator.shared.settings) appSettings: appSettings)
let deferredRecipient = deferFulfillment(viewModel.context.observe(\.viewState.dmRecipientInfo)) { $0 != nil } let deferredRecipient = deferFulfillment(viewModel.context.observe(\.viewState.dmRecipientInfo)) { $0 != nil }
@@ -249,6 +265,8 @@ struct RoomDetailsScreenViewModelTests {
@Test @Test
mutating func unignoreFailure() async throws { mutating func unignoreFailure() async throws {
let appSettings = AppSettings()
let recipient = RoomMemberProxyMock.mockIgnored let recipient = RoomMemberProxyMock.mockIgnored
let mockedMembers: [RoomMemberProxyMock] = [.mockMe, recipient] let mockedMembers: [RoomMemberProxyMock] = [.mockMe, recipient]
let clientProxy = ClientProxyMock(.init()) let clientProxy = ClientProxyMock(.init())
@@ -256,11 +274,11 @@ struct RoomDetailsScreenViewModelTests {
roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", isDirect: true, isEncrypted: true, members: mockedMembers)) roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", isDirect: true, isEncrypted: true, members: mockedMembers))
viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock,
userSession: UserSessionMock(.init(clientProxy: clientProxy)), userSession: UserSessionMock(.init(clientProxy: clientProxy)),
analyticsService: ServiceLocator.shared.analytics, analyticsService: .mock(settings: appSettings),
userIndicatorController: ServiceLocator.shared.userIndicatorController, userIndicatorController: UserIndicatorControllerMock.default,
notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()), notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()),
attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()), attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()),
appSettings: ServiceLocator.shared.settings) appSettings: appSettings)
let deferredRecipient = deferFulfillment(viewModel.context.observe(\.viewState.dmRecipientInfo)) { $0 != nil } let deferredRecipient = deferFulfillment(viewModel.context.observe(\.viewState.dmRecipientInfo)) { $0 != nil }
@@ -281,6 +299,8 @@ struct RoomDetailsScreenViewModelTests {
@Test @Test
mutating func cannotInvitePeople() async { mutating func cannotInvitePeople() async {
let appSettings = AppSettings()
let mockedMembers: [RoomMemberProxyMock] = [.mockMe, .mockAlice] let mockedMembers: [RoomMemberProxyMock] = [.mockMe, .mockAlice]
roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", roomProxyMock = JoinedRoomProxyMock(.init(name: "Test",
members: mockedMembers, members: mockedMembers,
@@ -288,11 +308,11 @@ struct RoomDetailsScreenViewModelTests {
powerLevelsConfiguration: .init(canUserInvite: false))) powerLevelsConfiguration: .init(canUserInvite: false)))
viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock,
userSession: UserSessionMock(.init()), userSession: UserSessionMock(.init()),
analyticsService: ServiceLocator.shared.analytics, analyticsService: .mock(settings: appSettings),
userIndicatorController: ServiceLocator.shared.userIndicatorController, userIndicatorController: UserIndicatorControllerMock.default,
notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()), notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()),
attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()), attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()),
appSettings: ServiceLocator.shared.settings) appSettings: appSettings)
_ = await context.observe(\.viewState).debounce(for: .milliseconds(100)).first() _ = await context.observe(\.viewState).debounce(for: .milliseconds(100)).first()
@@ -301,15 +321,17 @@ struct RoomDetailsScreenViewModelTests {
@Test @Test
mutating func invitePeople() async { mutating func invitePeople() async {
let appSettings = AppSettings()
let mockedMembers: [RoomMemberProxyMock] = [.mockMe, .mockBob, .mockAlice] let mockedMembers: [RoomMemberProxyMock] = [.mockMe, .mockBob, .mockAlice]
roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", members: mockedMembers, joinRule: .public)) roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", members: mockedMembers, joinRule: .public))
viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock,
userSession: UserSessionMock(.init()), userSession: UserSessionMock(.init()),
analyticsService: ServiceLocator.shared.analytics, analyticsService: .mock(settings: appSettings),
userIndicatorController: ServiceLocator.shared.userIndicatorController, userIndicatorController: UserIndicatorControllerMock.default,
notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()), notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()),
attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()), attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()),
appSettings: ServiceLocator.shared.settings) appSettings: appSettings)
_ = await context.observe(\.viewState).debounce(for: .milliseconds(100)).first() _ = await context.observe(\.viewState).debounce(for: .milliseconds(100)).first()
@@ -334,6 +356,8 @@ struct RoomDetailsScreenViewModelTests {
@Test @Test
mutating func canEditAvatar() async { mutating func canEditAvatar() async {
let appSettings = AppSettings()
let mockedMembers: [RoomMemberProxyMock] = [.mockMe, .mockBob, .mockAlice] let mockedMembers: [RoomMemberProxyMock] = [.mockMe, .mockBob, .mockAlice]
let configuration = JoinedRoomProxyMockConfiguration(name: "Test", let configuration = JoinedRoomProxyMockConfiguration(name: "Test",
@@ -357,11 +381,11 @@ struct RoomDetailsScreenViewModelTests {
viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock,
userSession: UserSessionMock(.init()), userSession: UserSessionMock(.init()),
analyticsService: ServiceLocator.shared.analytics, analyticsService: .mock(settings: appSettings),
userIndicatorController: ServiceLocator.shared.userIndicatorController, userIndicatorController: UserIndicatorControllerMock.default,
notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()), notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()),
attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()), attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()),
appSettings: ServiceLocator.shared.settings) appSettings: appSettings)
_ = await context.observe(\.viewState).debounce(for: .milliseconds(100)).first() _ = await context.observe(\.viewState).debounce(for: .milliseconds(100)).first()
@@ -373,6 +397,8 @@ struct RoomDetailsScreenViewModelTests {
@Test @Test
mutating func canEditName() async { mutating func canEditName() async {
let appSettings = AppSettings()
let mockedMembers: [RoomMemberProxyMock] = [.mockMe, .mockBob, .mockAlice] let mockedMembers: [RoomMemberProxyMock] = [.mockMe, .mockBob, .mockAlice]
let configuration = JoinedRoomProxyMockConfiguration(name: "Test", let configuration = JoinedRoomProxyMockConfiguration(name: "Test",
@@ -396,11 +422,11 @@ struct RoomDetailsScreenViewModelTests {
viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock,
userSession: UserSessionMock(.init()), userSession: UserSessionMock(.init()),
analyticsService: ServiceLocator.shared.analytics, analyticsService: .mock(settings: appSettings),
userIndicatorController: ServiceLocator.shared.userIndicatorController, userIndicatorController: UserIndicatorControllerMock.default,
notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()), notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()),
attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()), attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()),
appSettings: ServiceLocator.shared.settings) appSettings: appSettings)
_ = await context.observe(\.viewState).debounce(for: .milliseconds(100)).first() _ = await context.observe(\.viewState).debounce(for: .milliseconds(100)).first()
@@ -412,6 +438,8 @@ struct RoomDetailsScreenViewModelTests {
@Test @Test
mutating func canEditTopic() async { mutating func canEditTopic() async {
let appSettings = AppSettings()
let mockedMembers: [RoomMemberProxyMock] = [.mockMe, .mockBob, .mockAlice] let mockedMembers: [RoomMemberProxyMock] = [.mockMe, .mockBob, .mockAlice]
let configuration = JoinedRoomProxyMockConfiguration(name: "Test", let configuration = JoinedRoomProxyMockConfiguration(name: "Test",
@@ -435,11 +463,11 @@ struct RoomDetailsScreenViewModelTests {
viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock,
userSession: UserSessionMock(.init()), userSession: UserSessionMock(.init()),
analyticsService: ServiceLocator.shared.analytics, analyticsService: .mock(settings: appSettings),
userIndicatorController: ServiceLocator.shared.userIndicatorController, userIndicatorController: UserIndicatorControllerMock.default,
notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()), notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()),
attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()), attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()),
appSettings: ServiceLocator.shared.settings) appSettings: appSettings)
_ = await context.observe(\.viewState).debounce(for: .milliseconds(100)).first() _ = await context.observe(\.viewState).debounce(for: .milliseconds(100)).first()
@@ -451,15 +479,17 @@ struct RoomDetailsScreenViewModelTests {
@Test @Test
mutating func cannotEditRoom() async { mutating func cannotEditRoom() async {
let appSettings = AppSettings()
let mockedMembers: [RoomMemberProxyMock] = [.mockMe, .mockBob, .mockAlice] let mockedMembers: [RoomMemberProxyMock] = [.mockMe, .mockBob, .mockAlice]
roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", isDirect: false, members: mockedMembers)) roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", isDirect: false, members: mockedMembers))
viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock,
userSession: UserSessionMock(.init()), userSession: UserSessionMock(.init()),
analyticsService: ServiceLocator.shared.analytics, analyticsService: .mock(settings: appSettings),
userIndicatorController: ServiceLocator.shared.userIndicatorController, userIndicatorController: UserIndicatorControllerMock.default,
notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()), notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()),
attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()), attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()),
appSettings: ServiceLocator.shared.settings) appSettings: appSettings)
_ = await context.observe(\.viewState).debounce(for: .milliseconds(100)).first() _ = await context.observe(\.viewState).debounce(for: .milliseconds(100)).first()
@@ -471,15 +501,17 @@ struct RoomDetailsScreenViewModelTests {
@Test @Test
mutating func cannotEditDirectRoom() async { mutating func cannotEditDirectRoom() async {
let appSettings = AppSettings()
let mockedMembers: [RoomMemberProxyMock] = [.mockMeAdmin, .mockBob, .mockAlice] let mockedMembers: [RoomMemberProxyMock] = [.mockMeAdmin, .mockBob, .mockAlice]
roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", isDirect: true, members: mockedMembers)) roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", isDirect: true, members: mockedMembers))
viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock,
userSession: UserSessionMock(.init()), userSession: UserSessionMock(.init()),
analyticsService: ServiceLocator.shared.analytics, analyticsService: .mock(settings: appSettings),
userIndicatorController: ServiceLocator.shared.userIndicatorController, userIndicatorController: UserIndicatorControllerMock.default,
notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()), notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()),
attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()), attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()),
appSettings: ServiceLocator.shared.settings) appSettings: appSettings)
_ = await context.observe(\.viewState).debounce(for: .milliseconds(100)).first() _ = await context.observe(\.viewState).debounce(for: .milliseconds(100)).first()
@@ -490,14 +522,16 @@ struct RoomDetailsScreenViewModelTests {
@Test @Test
mutating func notificationLoadingSettingsFailure() async throws { mutating func notificationLoadingSettingsFailure() async throws {
let appSettings = AppSettings()
notificationSettingsProxyMock.getNotificationSettingsRoomIdIsEncryptedIsOneToOneThrowableError = NotificationSettingsError.Generic(msg: "error") notificationSettingsProxyMock.getNotificationSettingsRoomIdIsEncryptedIsOneToOneThrowableError = NotificationSettingsError.Generic(msg: "error")
viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock,
userSession: UserSessionMock(.init()), userSession: UserSessionMock(.init()),
analyticsService: ServiceLocator.shared.analytics, analyticsService: .mock(settings: appSettings),
userIndicatorController: ServiceLocator.shared.userIndicatorController, userIndicatorController: UserIndicatorControllerMock.default,
notificationSettingsProxy: notificationSettingsProxyMock, notificationSettingsProxy: notificationSettingsProxyMock,
attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()), attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()),
appSettings: ServiceLocator.shared.settings) appSettings: appSettings)
var deferred = deferFulfillment(context.observe(\.viewState.notificationSettingsState)) { $0.isError } var deferred = deferFulfillment(context.observe(\.viewState.notificationSettingsState)) { $0.isError }
@@ -697,15 +731,17 @@ struct RoomDetailsScreenViewModelTests {
@Test @Test
mutating func knockRequestsCounter() async throws { mutating func knockRequestsCounter() async throws {
let appSettings = AppSettings()
let mockedRequests: [KnockRequestProxyMock] = [.init(), .init()] let mockedRequests: [KnockRequestProxyMock] = [.init(), .init()]
roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", isDirect: false, knockRequestsState: .loaded(mockedRequests), joinRule: .knock)) roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", isDirect: false, knockRequestsState: .loaded(mockedRequests), joinRule: .knock))
viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock,
userSession: UserSessionMock(.init()), userSession: UserSessionMock(.init()),
analyticsService: ServiceLocator.shared.analytics, analyticsService: .mock(settings: appSettings),
userIndicatorController: ServiceLocator.shared.userIndicatorController, userIndicatorController: UserIndicatorControllerMock.default,
notificationSettingsProxy: notificationSettingsProxyMock, notificationSettingsProxy: notificationSettingsProxyMock,
attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()), attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()),
appSettings: ServiceLocator.shared.settings) appSettings: appSettings)
let deferred = deferFulfillment(context.observe(\.viewState)) { state in let deferred = deferFulfillment(context.observe(\.viewState)) { state in
state.knockRequestsCount == 2 && state.canSeeKnockingRequests state.knockRequestsCount == 2 && state.canSeeKnockingRequests
@@ -719,14 +755,16 @@ struct RoomDetailsScreenViewModelTests {
@Test @Test
mutating func knockRequestsCounterIsLoading() async throws { mutating func knockRequestsCounterIsLoading() async throws {
let appSettings = AppSettings()
roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", isDirect: false, knockRequestsState: .loading, joinRule: .knock)) roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", isDirect: false, knockRequestsState: .loading, joinRule: .knock))
viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock,
userSession: UserSessionMock(.init()), userSession: UserSessionMock(.init()),
analyticsService: ServiceLocator.shared.analytics, analyticsService: .mock(settings: appSettings),
userIndicatorController: ServiceLocator.shared.userIndicatorController, userIndicatorController: UserIndicatorControllerMock.default,
notificationSettingsProxy: notificationSettingsProxyMock, notificationSettingsProxy: notificationSettingsProxyMock,
attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()), attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()),
appSettings: ServiceLocator.shared.settings) appSettings: appSettings)
let deferred = deferFulfillment(context.observe(\.viewState)) { state in let deferred = deferFulfillment(context.observe(\.viewState)) { state in
state.knockRequestsCount == 0 && state.canSeeKnockingRequests state.knockRequestsCount == 0 && state.canSeeKnockingRequests
@@ -737,6 +775,8 @@ struct RoomDetailsScreenViewModelTests {
@Test @Test
mutating func knockRequestsCounterIsNotShownIfNoPermissions() async throws { mutating func knockRequestsCounterIsNotShownIfNoPermissions() async throws {
let appSettings = AppSettings()
let mockedRequests: [KnockRequestProxyMock] = [.init(), .init()] let mockedRequests: [KnockRequestProxyMock] = [.init(), .init()]
roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", roomProxyMock = JoinedRoomProxyMock(.init(name: "Test",
isDirect: false, isDirect: false,
@@ -745,11 +785,11 @@ struct RoomDetailsScreenViewModelTests {
powerLevelsConfiguration: .init(canUserInvite: false))) powerLevelsConfiguration: .init(canUserInvite: false)))
viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock,
userSession: UserSessionMock(.init()), userSession: UserSessionMock(.init()),
analyticsService: ServiceLocator.shared.analytics, analyticsService: .mock(settings: appSettings),
userIndicatorController: ServiceLocator.shared.userIndicatorController, userIndicatorController: UserIndicatorControllerMock.default,
notificationSettingsProxy: notificationSettingsProxyMock, notificationSettingsProxy: notificationSettingsProxyMock,
attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()), attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()),
appSettings: ServiceLocator.shared.settings) appSettings: appSettings)
let deferred = deferFulfillment(context.observe(\.viewState)) { state in let deferred = deferFulfillment(context.observe(\.viewState)) { state in
state.knockRequestsCount == 2 && state.knockRequestsCount == 2 &&
@@ -763,16 +803,18 @@ struct RoomDetailsScreenViewModelTests {
@Test @Test
mutating func knockRequestsCounterIsNotShownIfDM() async throws { mutating func knockRequestsCounterIsNotShownIfDM() async throws {
let appSettings = AppSettings()
let mockedRequests: [KnockRequestProxyMock] = [.init(), .init()] let mockedRequests: [KnockRequestProxyMock] = [.init(), .init()]
let mockedMembers: [RoomMemberProxyMock] = [.mockMe, .mockAlice] let mockedMembers: [RoomMemberProxyMock] = [.mockMe, .mockAlice]
roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", isDirect: true, members: mockedMembers, knockRequestsState: .loaded(mockedRequests), joinRule: .knock)) roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", isDirect: true, members: mockedMembers, knockRequestsState: .loaded(mockedRequests), joinRule: .knock))
viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock,
userSession: UserSessionMock(.init()), userSession: UserSessionMock(.init()),
analyticsService: ServiceLocator.shared.analytics, analyticsService: .mock(settings: appSettings),
userIndicatorController: ServiceLocator.shared.userIndicatorController, userIndicatorController: UserIndicatorControllerMock.default,
notificationSettingsProxy: notificationSettingsProxyMock, notificationSettingsProxy: notificationSettingsProxyMock,
attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()), attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()),
appSettings: ServiceLocator.shared.settings) appSettings: appSettings)
let deferred = deferFulfillment(context.observe(\.viewState)) { state in let deferred = deferFulfillment(context.observe(\.viewState)) { state in
state.knockRequestsCount == 2 && state.knockRequestsCount == 2 &&
@@ -788,6 +830,8 @@ struct RoomDetailsScreenViewModelTests {
@Test @Test
mutating func historySharingPillDisplayed() async throws { mutating func historySharingPillDisplayed() async throws {
let appSettings = AppSettings()
let configuration = JoinedRoomProxyMockConfiguration(historyVisibility: .shared) let configuration = JoinedRoomProxyMockConfiguration(historyVisibility: .shared)
let infoSubject = CurrentValueSubject<RoomInfoProxyProtocol, Never>(RoomInfoProxyMock(configuration)) let infoSubject = CurrentValueSubject<RoomInfoProxyProtocol, Never>(RoomInfoProxyMock(configuration))
let roomProxyMock = JoinedRoomProxyMock(configuration) let roomProxyMock = JoinedRoomProxyMock(configuration)
@@ -795,11 +839,11 @@ struct RoomDetailsScreenViewModelTests {
viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock,
userSession: UserSessionMock(.init()), userSession: UserSessionMock(.init()),
analyticsService: ServiceLocator.shared.analytics, analyticsService: .mock(settings: appSettings),
userIndicatorController: ServiceLocator.shared.userIndicatorController, userIndicatorController: UserIndicatorControllerMock.default,
notificationSettingsProxy: notificationSettingsProxyMock, notificationSettingsProxy: notificationSettingsProxyMock,
attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()), attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()),
appSettings: ServiceLocator.shared.settings) appSettings: appSettings)
let deferredShared = deferFulfillment(context.observe(\.viewState), let deferredShared = deferFulfillment(context.observe(\.viewState),
message: "The pill should be shown for rooms with shared history visibility") { state in message: "The pill should be shown for rooms with shared history visibility") { state in
@@ -19,6 +19,12 @@ final class RoomFlowCoordinatorTests {
var navigationStackCoordinator: NavigationStackCoordinator! var navigationStackCoordinator: NavigationStackCoordinator!
var cancellables = Set<AnyCancellable>() var cancellables = Set<AnyCancellable>()
private let appSettings: AppSettings
init() {
appSettings = AppSettings()
}
deinit { deinit {
AppSettings.resetAllSettings() AppSettings.resetAllSettings()
} }
@@ -236,7 +242,7 @@ final class RoomFlowCoordinatorTests {
@Test @Test
func threadedEventRoutes() async throws { func threadedEventRoutes() async throws {
ServiceLocator.shared.settings.threadsEnabled = true appSettings.threadsEnabled = true
setupRoomFlowCoordinator() setupRoomFlowCoordinator()
// Navigate directly to the threaded event // Navigate directly to the threaded event
@@ -479,13 +485,13 @@ final class RoomFlowCoordinatorTests {
bugReportService: BugReportServiceMock(.init()), bugReportService: BugReportServiceMock(.init()),
elementCallService: ElementCallServiceMock(.init()), elementCallService: ElementCallServiceMock(.init()),
timelineControllerFactory: timelineControllerFactory, timelineControllerFactory: timelineControllerFactory,
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings), emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(), linkMetadataProvider: LinkMetadataProvider(),
appMediator: AppMediatorMock.default, appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
appHooks: AppHooks(), appHooks: AppHooks(),
analytics: ServiceLocator.shared.analytics, analytics: .mock(settings: appSettings),
userIndicatorController: ServiceLocator.shared.userIndicatorController, userIndicatorController: UserIndicatorControllerMock.default,
notificationManager: NotificationManagerMock(), notificationManager: NotificationManagerMock(),
stateMachineFactory: StateMachineFactory()) stateMachineFactory: StateMachineFactory())
@@ -205,13 +205,17 @@ struct RoomMemberDetailsViewModelTests {
roomProxyMock.getMemberUserIDClosure = { _ in roomProxyMock.getMemberUserIDClosure = { _ in
.success(roomMemberProxyMock) .success(roomMemberProxyMock)
} }
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
// swiftlint:disable:next force_unwrapping // swiftlint:disable:next force_unwrapping
let userSession = clientProxy != nil ? UserSessionMock(.init(clientProxy: clientProxy!)) : UserSessionMock(.init()) let userSession = clientProxy != nil ? UserSessionMock(.init(clientProxy: clientProxy!)) : UserSessionMock(.init())
viewModel = RoomMemberDetailsScreenViewModel(userID: roomMemberProxyMock.userID, viewModel = RoomMemberDetailsScreenViewModel(userID: roomMemberProxyMock.userID,
roomProxy: roomProxyMock, roomProxy: roomProxyMock,
userSession: userSession, userSession: userSession,
userIndicatorController: ServiceLocator.shared.userIndicatorController, userIndicatorController: UserIndicatorControllerMock.default,
analytics: ServiceLocator.shared.analytics, analytics: analytics,
appSettings: ServiceLocator.shared.settings) appSettings: appSettings)
} }
} }
@@ -51,16 +51,19 @@ struct RoomMembersFlowCoordinatorTests {
let clientProxy = ClientProxyMock(.init()) let clientProxy = ClientProxyMock(.init())
clientProxy.directRoomForUserIDReturnValue = .success(nil) clientProxy.directRoomForUserIDReturnValue = .success(nil)
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
let flowParameters = CommonFlowParameters(userSession: UserSessionMock(.init(clientProxy: clientProxy)), let flowParameters = CommonFlowParameters(userSession: UserSessionMock(.init(clientProxy: clientProxy)),
bugReportService: BugReportServiceMock(.init()), bugReportService: BugReportServiceMock(.init()),
elementCallService: ElementCallServiceMock(.init()), elementCallService: ElementCallServiceMock(.init()),
timelineControllerFactory: TimelineControllerFactoryMock(.init()), timelineControllerFactory: TimelineControllerFactoryMock(.init()),
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings), emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(), linkMetadataProvider: LinkMetadataProvider(),
appMediator: AppMediatorMock.default, appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
appHooks: AppHooks(), appHooks: AppHooks(),
analytics: ServiceLocator.shared.analytics, analytics: analytics,
userIndicatorController: UserIndicatorControllerMock(), userIndicatorController: UserIndicatorControllerMock(),
notificationManager: NotificationManagerMock(), notificationManager: NotificationManagerMock(),
stateMachineFactory: stateMachineFactory) stateMachineFactory: stateMachineFactory)
@@ -277,8 +277,8 @@ struct RoomMembersListScreenViewModelTests {
viewModel = RoomMembersListScreenViewModel(userSession: UserSessionMock(.init()), viewModel = RoomMembersListScreenViewModel(userSession: UserSessionMock(.init()),
roomProxy: roomProxy, roomProxy: roomProxy,
userIndicatorController: ServiceLocator.shared.userIndicatorController, userIndicatorController: UserIndicatorControllerMock.default,
analytics: ServiceLocator.shared.analytics) analytics: .mock())
let context = viewModel.context let context = viewModel.context
@@ -297,7 +297,7 @@ struct RoomMembersListScreenViewModelTests {
roomProxy = JoinedRoomProxyMock(.init(name: "test", members: members)) roomProxy = JoinedRoomProxyMock(.init(name: "test", members: members))
viewModel = RoomMembersListScreenViewModel(userSession: UserSessionMock(.init()), viewModel = RoomMembersListScreenViewModel(userSession: UserSessionMock(.init()),
roomProxy: roomProxy, roomProxy: roomProxy,
userIndicatorController: ServiceLocator.shared.userIndicatorController, userIndicatorController: UserIndicatorControllerMock.default,
analytics: ServiceLocator.shared.analytics) analytics: .mock())
} }
} }
@@ -84,6 +84,6 @@ struct RoomRolesAndPermissionsScreenViewModelTests {
roomProxy = JoinedRoomProxyMock(.init(members: members)) roomProxy = JoinedRoomProxyMock(.init(members: members))
viewModel = RoomRolesAndPermissionsScreenViewModel(roomProxy: roomProxy, viewModel = RoomRolesAndPermissionsScreenViewModel(roomProxy: roomProxy,
userIndicatorController: UserIndicatorControllerMock(), userIndicatorController: UserIndicatorControllerMock(),
analytics: ServiceLocator.shared.analytics) analytics: .mock())
} }
} }
@@ -17,8 +17,11 @@ import Testing
final class RoomScreenViewModelTests { final class RoomScreenViewModelTests {
private var viewModel: RoomScreenViewModel! private var viewModel: RoomScreenViewModel!
private let appSettings: AppSettings
init() async throws { init() async throws {
AppSettings.resetAllSettings() AppSettings.resetAllSettings()
appSettings = AppSettings()
} }
deinit { deinit {
@@ -45,10 +48,10 @@ final class RoomScreenViewModelTests {
roomProxy: roomProxyMock, roomProxy: roomProxyMock,
initialSelectedPinnedEventID: nil, initialSelectedPinnedEventID: nil,
ongoingCallRoomIDPublisher: .init(.init(nil)), ongoingCallRoomIDPublisher: .init(.init(nil)),
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
appHooks: AppHooks(), appHooks: AppHooks(),
analyticsService: ServiceLocator.shared.analytics, analyticsService: .mock(settings: appSettings),
userIndicatorController: ServiceLocator.shared.userIndicatorController) userIndicatorController: UserIndicatorControllerMock.default)
self.viewModel = viewModel self.viewModel = viewModel
// check if in the default state is not showing but is indeed loading // check if in the default state is not showing but is indeed loading
@@ -126,10 +129,10 @@ final class RoomScreenViewModelTests {
roomProxy: roomProxyMock, roomProxy: roomProxyMock,
initialSelectedPinnedEventID: "test1", initialSelectedPinnedEventID: "test1",
ongoingCallRoomIDPublisher: .init(.init(nil)), ongoingCallRoomIDPublisher: .init(.init(nil)),
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
appHooks: AppHooks(), appHooks: AppHooks(),
analyticsService: ServiceLocator.shared.analytics, analyticsService: .mock(settings: appSettings),
userIndicatorController: ServiceLocator.shared.userIndicatorController) userIndicatorController: UserIndicatorControllerMock.default)
self.viewModel = viewModel self.viewModel = viewModel
// check if the banner is now in a loaded state and is showing the counter // check if the banner is now in a loaded state and is showing the counter
@@ -166,7 +169,7 @@ final class RoomScreenViewModelTests {
@Test @Test
func pinnedEventsBannerThreadedSelection() async throws { func pinnedEventsBannerThreadedSelection() async throws {
ServiceLocator.shared.settings.threadsEnabled = true appSettings.threadsEnabled = true
let roomProxyMock = JoinedRoomProxyMock(.init()) let roomProxyMock = JoinedRoomProxyMock(.init())
let eventMock = TimelineEventSDKMock() let eventMock = TimelineEventSDKMock()
@@ -187,10 +190,10 @@ final class RoomScreenViewModelTests {
roomProxy: roomProxyMock, roomProxy: roomProxyMock,
initialSelectedPinnedEventID: "test1", initialSelectedPinnedEventID: "test1",
ongoingCallRoomIDPublisher: .init(.init(nil)), ongoingCallRoomIDPublisher: .init(.init(nil)),
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
appHooks: AppHooks(), appHooks: AppHooks(),
analyticsService: ServiceLocator.shared.analytics, analyticsService: .mock(settings: appSettings),
userIndicatorController: ServiceLocator.shared.userIndicatorController) userIndicatorController: UserIndicatorControllerMock.default)
self.viewModel = viewModel self.viewModel = viewModel
// check if the banner is now in a loaded state and is showing the counter // check if the banner is now in a loaded state and is showing the counter
@@ -246,10 +249,10 @@ final class RoomScreenViewModelTests {
roomProxy: roomProxyMock, roomProxy: roomProxyMock,
initialSelectedPinnedEventID: nil, initialSelectedPinnedEventID: nil,
ongoingCallRoomIDPublisher: .init(.init(nil)), ongoingCallRoomIDPublisher: .init(.init(nil)),
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
appHooks: AppHooks(), appHooks: AppHooks(),
analyticsService: ServiceLocator.shared.analytics, analyticsService: .mock(settings: appSettings),
userIndicatorController: ServiceLocator.shared.userIndicatorController) userIndicatorController: UserIndicatorControllerMock.default)
self.viewModel = viewModel self.viewModel = viewModel
#expect(viewModel.state.roomTitle == "StartingName") #expect(viewModel.state.roomTitle == "StartingName")
@@ -283,10 +286,10 @@ final class RoomScreenViewModelTests {
roomProxy: roomProxyMock, roomProxy: roomProxyMock,
initialSelectedPinnedEventID: nil, initialSelectedPinnedEventID: nil,
ongoingCallRoomIDPublisher: ongoingCallRoomIDSubject.asCurrentValuePublisher(), ongoingCallRoomIDPublisher: ongoingCallRoomIDSubject.asCurrentValuePublisher(),
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
appHooks: AppHooks(), appHooks: AppHooks(),
analyticsService: ServiceLocator.shared.analytics, analyticsService: .mock(settings: appSettings),
userIndicatorController: ServiceLocator.shared.userIndicatorController) userIndicatorController: UserIndicatorControllerMock.default)
self.viewModel = viewModel self.viewModel = viewModel
#expect(viewModel.state.shouldShowCallButton) #expect(viewModel.state.shouldShowCallButton)
@@ -328,10 +331,10 @@ final class RoomScreenViewModelTests {
roomProxy: roomProxyMock, roomProxy: roomProxyMock,
initialSelectedPinnedEventID: nil, initialSelectedPinnedEventID: nil,
ongoingCallRoomIDPublisher: .init(.init(nil)), ongoingCallRoomIDPublisher: .init(.init(nil)),
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
appHooks: AppHooks(), appHooks: AppHooks(),
analyticsService: ServiceLocator.shared.analytics, analyticsService: .mock(settings: appSettings),
userIndicatorController: ServiceLocator.shared.userIndicatorController) userIndicatorController: UserIndicatorControllerMock.default)
self.viewModel = viewModel self.viewModel = viewModel
viewModel.stop() viewModel.stop()
} }
@@ -349,10 +352,10 @@ final class RoomScreenViewModelTests {
roomProxy: roomProxyMock, roomProxy: roomProxyMock,
initialSelectedPinnedEventID: nil, initialSelectedPinnedEventID: nil,
ongoingCallRoomIDPublisher: .init(.init(nil)), ongoingCallRoomIDPublisher: .init(.init(nil)),
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
appHooks: AppHooks(), appHooks: AppHooks(),
analyticsService: ServiceLocator.shared.analytics, analyticsService: .mock(settings: appSettings),
userIndicatorController: ServiceLocator.shared.userIndicatorController) userIndicatorController: UserIndicatorControllerMock.default)
self.viewModel = viewModel self.viewModel = viewModel
var deferred = deferFulfillment(viewModel.context.$viewState) { state in var deferred = deferFulfillment(viewModel.context.$viewState) { state in
@@ -383,10 +386,10 @@ final class RoomScreenViewModelTests {
roomProxy: roomProxyMock, roomProxy: roomProxyMock,
initialSelectedPinnedEventID: nil, initialSelectedPinnedEventID: nil,
ongoingCallRoomIDPublisher: .init(.init(nil)), ongoingCallRoomIDPublisher: .init(.init(nil)),
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
appHooks: AppHooks(), appHooks: AppHooks(),
analyticsService: ServiceLocator.shared.analytics, analyticsService: .mock(settings: appSettings),
userIndicatorController: ServiceLocator.shared.userIndicatorController) userIndicatorController: UserIndicatorControllerMock.default)
self.viewModel = viewModel self.viewModel = viewModel
var deferred = deferFulfillment(viewModel.context.$viewState) { state in var deferred = deferFulfillment(viewModel.context.$viewState) { state in
@@ -412,10 +415,10 @@ final class RoomScreenViewModelTests {
roomProxy: roomProxyMock, roomProxy: roomProxyMock,
initialSelectedPinnedEventID: nil, initialSelectedPinnedEventID: nil,
ongoingCallRoomIDPublisher: .init(.init(nil)), ongoingCallRoomIDPublisher: .init(.init(nil)),
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
appHooks: AppHooks(), appHooks: AppHooks(),
analyticsService: ServiceLocator.shared.analytics, analyticsService: .mock(settings: appSettings),
userIndicatorController: ServiceLocator.shared.userIndicatorController) userIndicatorController: UserIndicatorControllerMock.default)
self.viewModel = viewModel self.viewModel = viewModel
// Loading state just does not appear at all // Loading state just does not appear at all
@@ -432,10 +435,10 @@ final class RoomScreenViewModelTests {
roomProxy: roomProxyMock, roomProxy: roomProxyMock,
initialSelectedPinnedEventID: nil, initialSelectedPinnedEventID: nil,
ongoingCallRoomIDPublisher: .init(.init(nil)), ongoingCallRoomIDPublisher: .init(.init(nil)),
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
appHooks: AppHooks(), appHooks: AppHooks(),
analyticsService: ServiceLocator.shared.analytics, analyticsService: .mock(settings: appSettings),
userIndicatorController: ServiceLocator.shared.userIndicatorController) userIndicatorController: UserIndicatorControllerMock.default)
self.viewModel = viewModel self.viewModel = viewModel
let deferred = deferFulfillment(viewModel.context.$viewState) { state in let deferred = deferFulfillment(viewModel.context.$viewState) { state in
@@ -459,10 +462,10 @@ final class RoomScreenViewModelTests {
roomProxy: roomProxyMock, roomProxy: roomProxyMock,
initialSelectedPinnedEventID: nil, initialSelectedPinnedEventID: nil,
ongoingCallRoomIDPublisher: .init(.init(nil)), ongoingCallRoomIDPublisher: .init(.init(nil)),
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
appHooks: AppHooks(), appHooks: AppHooks(),
analyticsService: ServiceLocator.shared.analytics, analyticsService: .mock(settings: appSettings),
userIndicatorController: ServiceLocator.shared.userIndicatorController) userIndicatorController: UserIndicatorControllerMock.default)
self.viewModel = viewModel self.viewModel = viewModel
let deferredInvisible = deferFailure(viewModel.context.$viewState, let deferredInvisible = deferFailure(viewModel.context.$viewState,
@@ -16,18 +16,17 @@ final class ServerConfirmationScreenViewModelTests {
var clientFactory: AuthenticationClientFactoryMock! var clientFactory: AuthenticationClientFactoryMock!
var client: ClientSDKMock! var client: ClientSDKMock!
var service: AuthenticationServiceProtocol! var service: AuthenticationServiceProtocol!
var appSettings: AppSettings!
var viewModel: ServerConfirmationScreenViewModel! var viewModel: ServerConfirmationScreenViewModel!
var context: ServerConfirmationScreenViewModel.Context { var context: ServerConfirmationScreenViewModel.Context {
viewModel.context viewModel.context
} }
private let appSettings: AppSettings
init() { init() {
AppSettings.resetAllSettings() AppSettings.resetAllSettings()
appSettings = AppSettings() appSettings = AppSettings()
// These app settings are kept local to the tests on purpose as if they are registered in the
// ServiceLocator, the providers override that we apply will break other tests in the suite.
} }
deinit { deinit {
@@ -367,7 +366,7 @@ final class ServerConfirmationScreenViewModelTests {
viewModel = ServerConfirmationScreenViewModel(authenticationService: service, viewModel = ServerConfirmationScreenViewModel(authenticationService: service,
mode: mode, mode: mode,
authenticationFlow: authenticationFlow, authenticationFlow: authenticationFlow,
appSettings: ServiceLocator.shared.settings, appSettings: appSettings,
userIndicatorController: UserIndicatorControllerMock()) userIndicatorController: UserIndicatorControllerMock())
// Add a fake window in order for the OAuth flow to continue // Add a fake window in order for the OAuth flow to continue

Some files were not shown because too many files have changed in this diff Show More