Make AnalyticsService mockable via `AnalyticsServiceProtocol (#5599)

* Create AnalyticsServiceProtocol and conform AnalyticsService

* Replace AnalyticsService properties and arguments with AnalyticsServiceProtocol

* Inline AnalyticsServiceMock replacing old mock

* handle more complex AnalyticsServiceMock callsites

* move documentation from AnalyticsService to AnalyticsServiceProtocol
This commit is contained in:
Michael
2026-05-20 00:23:58 -05:00
committed by GitHub
parent 946cb53559
commit 5a07c98afc
118 changed files with 1218 additions and 505 deletions
@@ -14,7 +14,7 @@ struct UserProfileScreenCoordinatorParameters {
let isPresentedModally: Bool
let userSession: UserSessionProtocol
let userIndicatorController: UserIndicatorControllerProtocol
let analytics: AnalyticsService
let analytics: AnalyticsServiceProtocol
let appSettings: AppSettings
}
@@ -15,7 +15,7 @@ typealias UserProfileScreenViewModelType = StateStoreViewModelV2<UserProfileScre
class UserProfileScreenViewModel: UserProfileScreenViewModelType, UserProfileScreenViewModelProtocol {
private let userSession: UserSessionProtocol
private let userIndicatorController: UserIndicatorControllerProtocol
private let analytics: AnalyticsService
private let analytics: AnalyticsServiceProtocol
private let appSettings: AppSettings
private var actionsSubject: PassthroughSubject<UserProfileScreenViewModelAction, Never> = .init()
@@ -27,7 +27,7 @@ class UserProfileScreenViewModel: UserProfileScreenViewModelType, UserProfileScr
isPresentedModally: Bool,
userSession: UserSessionProtocol,
userIndicatorController: UserIndicatorControllerProtocol,
analytics: AnalyticsService,
analytics: AnalyticsServiceProtocol,
appSettings: AppSettings) {
self.userSession = userSession
self.userIndicatorController = userIndicatorController
@@ -143,14 +143,11 @@ struct UserProfileScreen_Previews: PreviewProvider, TestablePreview {
clientProxyMock.directRoomForUserIDReturnValue = .success("roomID")
}
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
return UserProfileScreenViewModel(userID: userID,
isPresentedModally: false,
userSession: UserSessionMock(.init(clientProxy: clientProxyMock)),
userIndicatorController: UserIndicatorControllerMock.default,
analytics: analytics,
appSettings: appSettings)
analytics: AnalyticsServiceMock.default(),
appSettings: AppSettings())
}
}