mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 12:07:55 +00:00
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:
@@ -13,6 +13,10 @@ import Testing
|
||||
struct UserProfileScreenViewModelTests {
|
||||
@Test
|
||||
func initialState() async throws {
|
||||
let appSettings = AppSettings()
|
||||
let analytics = AnalyticsService.mock(settings: appSettings)
|
||||
let userIndicatorController = UserIndicatorControllerMock.default
|
||||
|
||||
let profile = UserProfileProxy(userID: "@alice:matrix.org", displayName: "Alice", avatarURL: .mockMXCAvatar)
|
||||
let clientProxy = ClientProxyMock(.init())
|
||||
clientProxy.profileForReturnValue = .success(profile)
|
||||
@@ -20,9 +24,9 @@ struct UserProfileScreenViewModelTests {
|
||||
let viewModel = UserProfileScreenViewModel(userID: profile.userID,
|
||||
isPresentedModally: false,
|
||||
userSession: UserSessionMock(.init(clientProxy: clientProxy)),
|
||||
userIndicatorController: ServiceLocator.shared.userIndicatorController,
|
||||
analytics: ServiceLocator.shared.analytics,
|
||||
appSettings: ServiceLocator.shared.settings)
|
||||
userIndicatorController: userIndicatorController,
|
||||
analytics: analytics,
|
||||
appSettings: appSettings)
|
||||
let context = viewModel.context
|
||||
|
||||
let waitForMemberToLoad = deferFulfillment(context.observe(\.viewState.userProfile)) { $0 != nil }
|
||||
@@ -35,6 +39,10 @@ struct UserProfileScreenViewModelTests {
|
||||
|
||||
@Test
|
||||
func initialStateAccountOwner() async throws {
|
||||
let appSettings = AppSettings()
|
||||
let analytics = AnalyticsService.mock(settings: appSettings)
|
||||
let userIndicatorController = UserIndicatorControllerMock.default
|
||||
|
||||
let profile = UserProfileProxy(userID: RoomMemberProxyMock.mockMe.userID, displayName: "Me", avatarURL: .mockMXCAvatar)
|
||||
let clientProxy = ClientProxyMock(.init())
|
||||
clientProxy.profileForReturnValue = .success(profile)
|
||||
@@ -42,9 +50,9 @@ struct UserProfileScreenViewModelTests {
|
||||
let viewModel = UserProfileScreenViewModel(userID: profile.userID,
|
||||
isPresentedModally: false,
|
||||
userSession: UserSessionMock(.init(clientProxy: clientProxy)),
|
||||
userIndicatorController: ServiceLocator.shared.userIndicatorController,
|
||||
analytics: ServiceLocator.shared.analytics,
|
||||
appSettings: ServiceLocator.shared.settings)
|
||||
userIndicatorController: userIndicatorController,
|
||||
analytics: analytics,
|
||||
appSettings: appSettings)
|
||||
let context = viewModel.context
|
||||
|
||||
let waitForMemberToLoad = deferFulfillment(context.observe(\.viewState.userProfile)) { $0 != nil }
|
||||
@@ -57,6 +65,10 @@ struct UserProfileScreenViewModelTests {
|
||||
|
||||
@Test
|
||||
func startingDmWithUnknownUserFetchesIdentity() async throws {
|
||||
let appSettings = AppSettings()
|
||||
let analytics = AnalyticsService.mock(settings: appSettings)
|
||||
let userIndicatorController = UserIndicatorControllerMock.default
|
||||
|
||||
let profile = UserProfileProxy.mockAlice
|
||||
|
||||
let clientProxy = ClientProxyMock(.init())
|
||||
@@ -66,9 +78,9 @@ struct UserProfileScreenViewModelTests {
|
||||
let viewModel = UserProfileScreenViewModel(userID: profile.userID,
|
||||
isPresentedModally: false,
|
||||
userSession: UserSessionMock(.init(clientProxy: clientProxy)),
|
||||
userIndicatorController: ServiceLocator.shared.userIndicatorController,
|
||||
analytics: ServiceLocator.shared.analytics,
|
||||
appSettings: ServiceLocator.shared.settings)
|
||||
userIndicatorController: userIndicatorController,
|
||||
analytics: analytics,
|
||||
appSettings: appSettings)
|
||||
|
||||
let context = viewModel.context
|
||||
|
||||
|
||||
Reference in New Issue
Block a user