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
@@ -11,20 +11,19 @@ import Testing
@MainActor
final class AnalyticsSettingsScreenViewModelTests {
private var appSettings: AppSettings!
private let appSettings: AppSettings
private let analytics: AnalyticsService
private var viewModel: AnalyticsSettingsScreenViewModelProtocol!
private var context: AnalyticsSettingsScreenViewModelType.Context!
init() {
AppSettings.resetAllSettings()
appSettings = AppSettings()
let analyticsClient = AnalyticsClientMock()
analyticsClient.isRunning = false
ServiceLocator.shared.register(analytics: AnalyticsService(client: analyticsClient,
appSettings: appSettings))
analytics = .mock(settings: appSettings)
viewModel = AnalyticsSettingsScreenViewModel(appSettings: appSettings,
analytics: ServiceLocator.shared.analytics)
analytics: analytics)
context = viewModel.context
}
+20 -19
View File
@@ -12,18 +12,19 @@ import PostHog
import Testing
final class AnalyticsTests {
private var appSettings: AppSettings
private var analyticsClient: AnalyticsClientMock
private let appSettings: AppSettings
private let analytics: AnalyticsService
private let analyticsClient: AnalyticsClientMock
private var posthogMock: PHGPostHogMock
@MainActor
init() {
AppSettings.resetAllSettings()
appSettings = AppSettings()
analyticsClient = AnalyticsClientMock()
analyticsClient.isRunning = false
ServiceLocator.shared.register(analytics: AnalyticsService(client: analyticsClient,
appSettings: appSettings))
analytics = .mock(analyticsClient, settings: appSettings)
posthogMock = PHGPostHogMock()
posthogMock.configureMockBehavior()
@@ -37,7 +38,7 @@ final class AnalyticsTests {
func analyticsPromptNewUser() {
// Given a fresh install of the app (without PostHog analytics having been set).
// When the user is prompted for analytics.
let showPrompt = ServiceLocator.shared.analytics.shouldShowAnalyticsPrompt
let showPrompt = analytics.shouldShowAnalyticsPrompt
// Then the prompt should be shown.
#expect(showPrompt, "A prompt should be shown for a new user.")
@@ -49,7 +50,7 @@ final class AnalyticsTests {
appSettings.analyticsConsentState = .optedOut
// When the user is prompted for analytics
let showPrompt = ServiceLocator.shared.analytics.shouldShowAnalyticsPrompt
let showPrompt = analytics.shouldShowAnalyticsPrompt
// Then no prompt should be shown.
#expect(!showPrompt, "A prompt should not be shown any more.")
@@ -61,7 +62,7 @@ final class AnalyticsTests {
appSettings.analyticsConsentState = .optedIn
// When the user is prompted for analytics
let showPrompt = ServiceLocator.shared.analytics.shouldShowAnalyticsPrompt
let showPrompt = analytics.shouldShowAnalyticsPrompt
// Then no prompt should be shown.
#expect(!showPrompt, "A prompt should not be shown any more.")
@@ -71,7 +72,7 @@ final class AnalyticsTests {
func analyticsPromptNotDisplayed() {
// Given a fresh install of the app Analytics should be disabled
#expect(appSettings.analyticsConsentState == .unknown)
#expect(!ServiceLocator.shared.analytics.isEnabled)
#expect(!analytics.isEnabled)
#expect(!analyticsClient.startAnalyticsConfigurationCalled)
}
@@ -79,10 +80,10 @@ final class AnalyticsTests {
func analyticsOptOut() {
// Given a fresh install of the app (without PostHog analytics having been set).
// When analytics is opt-out
ServiceLocator.shared.analytics.optOut()
analytics.optOut()
// Then analytics should be disabled
#expect(appSettings.analyticsConsentState == .optedOut)
#expect(!ServiceLocator.shared.analytics.isEnabled)
#expect(!analytics.isEnabled)
#expect(!analyticsClient.isRunning)
// Analytics client should have been stopped
#expect(analyticsClient.stopCalled)
@@ -92,10 +93,10 @@ final class AnalyticsTests {
func analyticsOptIn() {
// Given a fresh install of the app (without PostHog analytics having been set).
// When analytics is opt-in
ServiceLocator.shared.analytics.optIn()
analytics.optIn()
// The analytics should be enabled
#expect(appSettings.analyticsConsentState == .optedIn)
#expect(ServiceLocator.shared.analytics.isEnabled)
#expect(analytics.isEnabled)
// Analytics client should have been started
#expect(analyticsClient.startAnalyticsConfigurationCalled)
}
@@ -105,8 +106,8 @@ final class AnalyticsTests {
// Given an existing install of the app where the user previously declined the tracking
appSettings.analyticsConsentState = .optedOut
// Analytics should not start
#expect(!ServiceLocator.shared.analytics.isEnabled)
ServiceLocator.shared.analytics.startIfEnabled()
#expect(!analytics.isEnabled)
analytics.startIfEnabled()
#expect(!analyticsClient.startAnalyticsConfigurationCalled)
}
@@ -115,8 +116,8 @@ final class AnalyticsTests {
// Given an existing install of the app where the user previously accepted the tracking
appSettings.analyticsConsentState = .optedIn
// Analytics should start
#expect(ServiceLocator.shared.analytics.isEnabled)
ServiceLocator.shared.analytics.startIfEnabled()
#expect(analytics.isEnabled)
analytics.startIfEnabled()
#expect(analyticsClient.startAnalyticsConfigurationCalled)
}
@@ -214,14 +215,14 @@ final class AnalyticsTests {
func resetConsentState() {
// Given an existing install of the app where the user previously accpeted the tracking
appSettings.analyticsConsentState = .optedIn
#expect(!ServiceLocator.shared.analytics.shouldShowAnalyticsPrompt)
#expect(!analytics.shouldShowAnalyticsPrompt)
// When forgetting analytics consents
ServiceLocator.shared.analytics.resetConsentState()
analytics.resetConsentState()
// Then the analytics prompt should be presented again
#expect(appSettings.analyticsConsentState == .unknown)
#expect(ServiceLocator.shared.analytics.shouldShowAnalyticsPrompt)
#expect(analytics.shouldShowAnalyticsPrompt)
}
@Test
@@ -153,7 +153,7 @@ struct AuthenticationServiceTests {
encryptionKeyProvider: encryptionKeyProvider,
classicAppManager: classicAppManager,
clientFactory: clientFactory,
appSettings: ServiceLocator.shared.settings,
appSettings: AppSettings(),
appHooks: AppHooks())
if let classicAppAccount = service.classicAppAccount {
@@ -28,8 +28,6 @@ final class AuthenticationStartScreenViewModelTests {
init() {
AppSettings.resetAllSettings()
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 {
@@ -19,7 +19,7 @@ struct BlockedUsersScreenViewModelTests {
let viewModel = BlockedUsersScreenViewModel(hideProfiles: true,
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 } }
try await deferred.fulfill()
@@ -34,7 +34,7 @@ struct BlockedUsersScreenViewModelTests {
let viewModel = BlockedUsersScreenViewModel(hideProfiles: false,
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 } }
try await deferred.fulfill()
@@ -31,6 +31,9 @@ struct ChatsTabFlowCoordinatorTests {
}
init() async throws {
let appSettings = AppSettings()
let analytics: AnalyticsService = .mock(settings: appSettings)
clientProxy = ClientProxyMock(.init(userID: "hi@bob", roomSummaryProvider: RoomSummaryProviderMock(.init(state: .loaded(.mockRooms)))))
timelineControllerFactory = TimelineControllerFactoryMock(.init())
@@ -42,12 +45,12 @@ struct ChatsTabFlowCoordinatorTests {
bugReportService: BugReportServiceMock(.init()),
elementCallService: ElementCallServiceMock(.init()),
timelineControllerFactory: timelineControllerFactory,
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings),
emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(),
appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings,
appSettings: appSettings,
appHooks: AppHooks(),
analytics: ServiceLocator.shared.analytics,
analytics: analytics,
userIndicatorController: UserIndicatorControllerMock(),
notificationManager: notificationManager,
stateMachineFactory: stateMachineFactory)
@@ -15,16 +15,14 @@ import WysiwygComposer
@MainActor
final class ComposerToolbarViewModelTests {
private var appSettings: AppSettings!
private var wysiwygViewModel: WysiwygComposerViewModel!
private var viewModel: ComposerToolbarViewModel!
private var completionSuggestionServiceMock: CompletionSuggestionServiceMock!
private var draftServiceMock: ComposerDraftServiceMock!
init() {
AppSettings.resetAllSettings()
appSettings = AppSettings()
ServiceLocator.shared.register(appSettings: appSettings)
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: "")]
let mockCompletionSuggestionService = CompletionSuggestionServiceMock(configuration: .init(suggestions: suggestions))
let appSettings = AppSettings()
viewModel = ComposerToolbarViewModel(roomProxy: JoinedRoomProxyMock(.init()),
wysiwygViewModel: wysiwygViewModel,
completionSuggestionService: mockCompletionSuggestionService,
mediaProvider: MediaProviderMock(configuration: .init()),
mentionDisplayHelper: ComposerMentionDisplayHelper.mock,
appSettings: ServiceLocator.shared.settings,
analyticsService: ServiceLocator.shared.analytics,
appSettings: appSettings,
analyticsService: .mock(settings: appSettings),
composerDraftService: draftServiceMock)
#expect(viewModel.state.suggestions == suggestions)
@@ -708,13 +708,15 @@ final class ComposerToolbarViewModelTests {
let mockSubject = CurrentValueSubject<[IdentityStatusChange], Never>([])
roomProxyMock.underlyingIdentityStatusChangesPublisher = mockSubject.asCurrentValuePublisher()
let appSettings = AppSettings()
viewModel = ComposerToolbarViewModel(roomProxy: roomProxyMock,
wysiwygViewModel: wysiwygViewModel,
completionSuggestionService: mockCompletionSuggestionService,
mediaProvider: MediaProviderMock(configuration: .init()),
mentionDisplayHelper: ComposerMentionDisplayHelper.mock,
appSettings: ServiceLocator.shared.settings,
analyticsService: ServiceLocator.shared.analytics,
appSettings: appSettings,
analyticsService: .mock(settings: appSettings),
composerDraftService: draftServiceMock)
var fulfillment = deferFulfillment(viewModel.context.$viewState, message: "Composer is disabled") { $0.canSend == false }
@@ -753,13 +755,15 @@ final class ComposerToolbarViewModelTests {
roomProxyMock.underlyingIdentityStatusChangesPublisher = mockSubject.asCurrentValuePublisher()
let appSettings = AppSettings()
viewModel = ComposerToolbarViewModel(roomProxy: roomProxyMock,
wysiwygViewModel: wysiwygViewModel,
completionSuggestionService: mockCompletionSuggestionService,
mediaProvider: MediaProviderMock(configuration: .init()),
mentionDisplayHelper: ComposerMentionDisplayHelper.mock,
appSettings: ServiceLocator.shared.settings,
analyticsService: ServiceLocator.shared.analytics,
appSettings: appSettings,
analyticsService: .mock(settings: appSettings),
composerDraftService: draftServiceMock)
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()
let appSettings = AppSettings()
viewModel = ComposerToolbarViewModel(roomProxy: roomProxyMock,
wysiwygViewModel: wysiwygViewModel,
completionSuggestionService: mockCompletionSuggestionService,
mediaProvider: MediaProviderMock(configuration: .init()),
mentionDisplayHelper: ComposerMentionDisplayHelper.mock,
appSettings: ServiceLocator.shared.settings,
analyticsService: ServiceLocator.shared.analytics,
appSettings: appSettings,
analyticsService: .mock(settings: appSettings),
composerDraftService: draftServiceMock)
let deferred = deferFulfillment(viewModel.context.$viewState, message: "Composer should be enabled") { $0.canSend == true }
@@ -811,14 +816,16 @@ final class ComposerToolbarViewModelTests {
draftServiceMock.loadDraftClosure = loadDraftClosure
}
let appSettings = AppSettings()
viewModel = ComposerToolbarViewModel(initialText: initialText,
roomProxy: JoinedRoomProxyMock(.init()),
wysiwygViewModel: wysiwygViewModel,
completionSuggestionService: completionSuggestionServiceMock,
mediaProvider: MediaProviderMock(configuration: .init()),
mentionDisplayHelper: ComposerMentionDisplayHelper.mock,
appSettings: ServiceLocator.shared.settings,
analyticsService: ServiceLocator.shared.analytics,
appSettings: appSettings,
analyticsService: .mock(settings: appSettings),
composerDraftService: draftServiceMock)
viewModel.context.composerFormattingEnabled = true
}
@@ -16,13 +16,21 @@ final class CreateRoomScreenViewModelTests {
var clientProxy: ClientProxyMock!
var spaceService: SpaceServiceProxyMock!
var userSession: UserSessionMock!
private let appSettings: AppSettings
private let analytics: AnalyticsService
private let usersSubject = CurrentValueSubject<[UserProfileProxy], Never>([])
var context: CreateRoomScreenViewModel.Context {
viewModel.context
}
init() {
appSettings = AppSettings()
analytics = .mock(settings: appSettings)
}
deinit {
AppSettings.resetAllSettings()
viewModel = nil
@@ -82,14 +90,14 @@ final class CreateRoomScreenViewModelTests {
spaceServiceConfiguration: .init(spaceRoomLists: ["1": .init()])))
clientProxy.roomForIdentifierClosure = { roomID in .joined(JoinedRoomProxyMock(.init(id: roomID))) }
userSession = UserSessionMock(.init(clientProxy: clientProxy))
ServiceLocator.shared.settings.knockingEnabled = true
appSettings.knockingEnabled = true
let viewModel = CreateRoomScreenViewModel(isSpace: true,
spaceSelectionMode: .none,
shouldShowCancelButton: false,
userSession: userSession,
analytics: ServiceLocator.shared.analytics,
analytics: analytics,
userIndicatorController: UserIndicatorControllerMock(),
appSettings: ServiceLocator.shared.settings)
appSettings: appSettings)
self.viewModel = viewModel
// Given a form with a blank topic.
@@ -332,14 +340,14 @@ final class CreateRoomScreenViewModelTests {
clientProxy.spaceService = spaceService
clientProxy.roomForIdentifierClosure = { roomID in .joined(JoinedRoomProxyMock(.init(id: roomID))) }
userSession = UserSessionMock(.init(clientProxy: clientProxy))
ServiceLocator.shared.settings.knockingEnabled = true
appSettings.knockingEnabled = true
let viewModel = CreateRoomScreenViewModel(isSpace: isSpace,
spaceSelectionMode: spacesSelectionMode,
shouldShowCancelButton: false,
userSession: userSession,
analytics: ServiceLocator.shared.analytics,
analytics: analytics,
userIndicatorController: UserIndicatorControllerMock(),
appSettings: ServiceLocator.shared.settings)
appSettings: appSettings)
self.viewModel = viewModel
}
}
@@ -17,7 +17,7 @@ struct EmojiPickerScreenViewModelTests {
var context: EmojiPickerScreenViewModel.Context {
viewModel.context
}
@Test
mutating func toggleReaction() async throws {
setupViewModel()
@@ -45,7 +45,7 @@ struct EmojiPickerScreenViewModelTests {
viewModel = EmojiPickerScreenViewModel(itemID: .randomEvent,
selectedEmojis: selectedEmojis,
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings),
emojiProvider: EmojiProvider(appSettings: AppSettings()),
timelineController: MockTimelineController(timelineProxy: timelineProxy))
}
}
+4 -4
View File
@@ -19,7 +19,7 @@ struct EmojiProviderTests {
let emojiLoaderMock = EmojiLoaderMock()
emojiLoaderMock.categories = [category]
let emojiProvider = EmojiProvider(loader: emojiLoaderMock, appSettings: ServiceLocator.shared.settings)
let emojiProvider = EmojiProvider(loader: emojiLoaderMock, appSettings: AppSettings())
let categories = await emojiProvider.categories()
#expect(emojiLoaderMock.categories == categories)
@@ -33,7 +33,7 @@ struct EmojiProviderTests {
let emojiLoaderMock = EmojiLoaderMock()
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: "")
#expect(emojiLoaderMock.categories == categories)
@@ -51,7 +51,7 @@ struct EmojiProviderTests {
let emojiLoaderMock = EmojiLoaderMock()
emojiLoaderMock.categories = categoriesForFirstLoad
let emojiProvider = EmojiProvider(loader: emojiLoaderMock, appSettings: ServiceLocator.shared.settings)
let emojiProvider = EmojiProvider(loader: emojiLoaderMock, appSettings: AppSettings())
_ = await emojiProvider.categories()
emojiLoaderMock.categories = categoriesForSecondLoad
@@ -82,7 +82,7 @@ struct EmojiProviderTests {
let emojiLoaderMock = EmojiLoaderMock()
emojiLoaderMock.categories = categories
let emojiProvider = EmojiProvider(loader: emojiLoaderMock, appSettings: ServiceLocator.shared.settings)
let emojiProvider = EmojiProvider(loader: emojiLoaderMock, appSettings: AppSettings())
_ = await emojiProvider.categories()
let result = await emojiProvider.categories(searchString: searchString)
@@ -19,15 +19,18 @@ final class HomeScreenViewModelTests {
var clientProxy: ClientProxyMock!
var roomSummaryProvider: RoomSummaryProviderMock!
var appSettings: AppSettings!
var notificationManager: NotificationManagerMock!
private let appSettings: AppSettings
private let analytics: AnalyticsService
private let userIndicatorController: UserIndicatorControllerProtocol
var cancellables = Set<AnyCancellable>()
init() {
AppSettings.resetAllSettings()
appSettings = AppSettings()
ServiceLocator.shared.register(appSettings: appSettings)
analytics = .mock(settings: appSettings)
userIndicatorController = UserIndicatorControllerMock.default
}
deinit {
@@ -441,9 +444,9 @@ final class HomeScreenViewModelTests {
viewModel = HomeScreenViewModel(userSession: userSession,
selectedRoomPublisher: CurrentValueSubject<String?, Never>(nil).asCurrentValuePublisher(),
appSettings: appSettings,
analyticsService: ServiceLocator.shared.analytics,
analyticsService: analytics,
notificationManager: notificationManager,
userIndicatorController: ServiceLocator.shared.userIndicatorController)
userIndicatorController: userIndicatorController)
}
}
@@ -15,12 +15,9 @@ final class InviteUsersScreenViewModelTests {
var viewModel: InviteUsersScreenViewModelProtocol!
var userDiscoveryService: UserDiscoveryServiceMock!
var clientProxy: ClientProxyMock!
var appSettings: AppSettings!
init() {
AppSettings.resetAllSettings()
appSettings = AppSettings()
ServiceLocator.shared.register(appSettings: appSettings)
}
deinit {
@@ -175,7 +172,7 @@ final class InviteUsersScreenViewModelTests {
isSkippable: isSkippable,
userDiscoveryService: userDiscoveryService,
userIndicatorController: UserIndicatorControllerMock(),
appSettings: ServiceLocator.shared.settings)
appSettings: AppSettings())
viewModel.state.usersSection = .init(type: .suggestions, users: [.mockAlice, .mockBob, .mockCharlie])
self.viewModel = viewModel
}
@@ -21,16 +21,16 @@ final class JoinRoomScreenViewModelTests {
var viewModel: JoinRoomScreenViewModelProtocol!
var clientProxy: ClientProxyMock!
var appSettings: AppSettings!
var context: JoinRoomScreenViewModelType.Context {
viewModel.context
}
private let appSettings: AppSettings
init() {
AppSettings.resetAllSettings()
appSettings = AppSettings()
ServiceLocator.shared.register(appSettings: appSettings)
}
deinit {
@@ -205,7 +205,7 @@ final class JoinRoomScreenViewModelTests {
viewModel = JoinRoomScreenViewModel(source: .generic(roomID: "1", via: []),
appSettings: appSettings,
userSession: UserSessionMock(.init(clientProxy: clientProxy)),
userIndicatorController: ServiceLocator.shared.userIndicatorController)
userIndicatorController: UserIndicatorControllerMock.default)
}
}
@@ -394,12 +394,14 @@ struct LocationSharingScreenViewModelTests {
let roomProxyMock = JoinedRoomProxyMock(.init(members: .allMembers))
roomProxyMock.makeLiveLocationServiceReturnValue = liveLocationServiceMock
let appSettings = AppSettings()
viewModel = LocationSharingScreenViewModel(interactionMode: .viewLive(sender: nil, initialLiveLocationShare: nil),
mapURLBuilder: ServiceLocator.shared.settings.mapTilerConfiguration,
mapURLBuilder: appSettings.mapTilerConfiguration,
roomProxy: roomProxyMock,
timelineController: MockTimelineController(timelineProxy: TimelineProxyMock(.init())),
liveLocationManager: LiveLocationManagerMock(.init()),
analytics: ServiceLocator.shared.analytics,
analytics: .mock(settings: appSettings),
userIndicatorController: UserIndicatorControllerMock(),
mediaProvider: MediaProviderMock(configuration: .init()))
@@ -427,13 +429,14 @@ struct LocationSharingScreenViewModelTests {
private mutating func setupViewModel(liveLocationManagerConfiguration: LiveLocationManagerMock.Configuration = .init(),
members: [RoomMemberProxyMock] = .allMembersAsAdmin) {
let appSettings = AppSettings()
timelineProxy = TimelineProxyMock(.init())
viewModel = LocationSharingScreenViewModel(interactionMode: .picker(shouldShowLiveLocationOption: true),
mapURLBuilder: ServiceLocator.shared.settings.mapTilerConfiguration,
mapURLBuilder: appSettings.mapTilerConfiguration,
roomProxy: JoinedRoomProxyMock(.init(members: members)),
timelineController: MockTimelineController(timelineProxy: timelineProxy),
liveLocationManager: LiveLocationManagerMock(liveLocationManagerConfiguration),
analytics: ServiceLocator.shared.analytics,
analytics: .mock(settings: appSettings),
userIndicatorController: UserIndicatorControllerMock(),
mediaProvider: MediaProviderMock(configuration: .init()))
viewModel.state.bindings.isLocationAuthorized = true
@@ -441,13 +444,14 @@ struct LocationSharingScreenViewModelTests {
private mutating func setupViewModel(liveLocationManagerMock: LiveLocationManagerMock,
members: [RoomMemberProxyMock] = .allMembersAsAdmin) {
let appSettings = AppSettings()
timelineProxy = TimelineProxyMock(.init())
viewModel = LocationSharingScreenViewModel(interactionMode: .picker(shouldShowLiveLocationOption: true),
mapURLBuilder: ServiceLocator.shared.settings.mapTilerConfiguration,
mapURLBuilder: appSettings.mapTilerConfiguration,
roomProxy: JoinedRoomProxyMock(.init(members: members)),
timelineController: MockTimelineController(timelineProxy: timelineProxy),
liveLocationManager: liveLocationManagerMock,
analytics: ServiceLocator.shared.analytics,
analytics: .mock(settings: appSettings),
userIndicatorController: UserIndicatorControllerMock(),
mediaProvider: MediaProviderMock(configuration: .init()))
viewModel.state.bindings.isLocationAuthorized = true
@@ -457,6 +461,7 @@ struct LocationSharingScreenViewModelTests {
initialShare: LiveLocationShare,
liveLocationsSubject: CurrentValueSubject<[LiveLocationShare], Never>,
members: [RoomMemberProxyMock] = .allMembers) {
let appSettings = AppSettings()
let liveLocationServiceMock = RoomLiveLocationServiceMock()
liveLocationServiceMock.liveLocationsPublisher = liveLocationsSubject.asCurrentValuePublisher()
@@ -464,11 +469,11 @@ struct LocationSharingScreenViewModelTests {
roomProxyMock.makeLiveLocationServiceReturnValue = liveLocationServiceMock
viewModel = LocationSharingScreenViewModel(interactionMode: .viewLive(sender: sender, initialLiveLocationShare: initialShare),
mapURLBuilder: ServiceLocator.shared.settings.mapTilerConfiguration,
mapURLBuilder: appSettings.mapTilerConfiguration,
roomProxy: roomProxyMock,
timelineController: MockTimelineController(timelineProxy: TimelineProxyMock(.init())),
liveLocationManager: LiveLocationManagerMock(.init()),
analytics: ServiceLocator.shared.analytics,
analytics: .mock(settings: appSettings),
userIndicatorController: UserIndicatorControllerMock(),
mediaProvider: MediaProviderMock(configuration: .init()))
}
@@ -227,12 +227,14 @@ struct LoginScreenViewModelTests {
// MARK: - Helpers
private mutating func setupViewModel(homeserverAddress: String = "example.com", loginHint: String? = nil) async {
let appSettings = AppSettings()
clientFactory = AuthenticationClientFactoryMock(configuration: .init())
service = AuthenticationService(userSessionStore: UserSessionStoreMock(configuration: .init()),
encryptionKeyProvider: EncryptionKeyProvider(),
classicAppManager: nil,
clientFactory: clientFactory,
appSettings: ServiceLocator.shared.settings,
appSettings: appSettings,
appHooks: AppHooks())
guard case .success = await service
@@ -244,7 +246,7 @@ struct LoginScreenViewModelTests {
viewModel = LoginScreenViewModel(authenticationService: service,
loginHint: loginHint,
userIndicatorController: UserIndicatorControllerMock(),
appSettings: ServiceLocator.shared.settings,
analytics: ServiceLocator.shared.analytics)
appSettings: appSettings,
analytics: .mock(settings: appSettings))
}
}
@@ -32,7 +32,7 @@ struct ManageRoomMemberSheetViewModelTests {
permissions: .init(canKick: true, canBan: true, ownPowerLevel: RoomMemberProxyMock.mockAdmin.powerLevel),
roomProxy: roomProxy,
userIndicatorController: UserIndicatorControllerMock(),
analyticsService: ServiceLocator.shared.analytics,
analyticsService: .mock(),
mediaProvider: MediaProviderMock(configuration: .init()))
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),
roomProxy: roomProxy,
userIndicatorController: UserIndicatorControllerMock(),
analyticsService: ServiceLocator.shared.analytics,
analyticsService: .mock(),
mediaProvider: MediaProviderMock(configuration: .init()))
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),
roomProxy: roomProxy,
userIndicatorController: UserIndicatorControllerMock(),
analyticsService: ServiceLocator.shared.analytics,
analyticsService: .mock(),
mediaProvider: MediaProviderMock(configuration: .init()))
let deferredAction = deferFulfillment(viewModel.actions) { action in
@@ -14,8 +14,9 @@ import Testing
final class MediaUploadPreviewScreenViewModelTests {
var timelineProxy: TimelineProxyMock!
var clientProxy: ClientProxyMock!
var userIndicatorController: UserIndicatorControllerMock!
var userIndicatorController: UserIndicatorControllerMock
private let appSettings: AppSettings
var viewModel: MediaUploadPreviewScreenViewModel!
var context: MediaUploadPreviewScreenViewModel.Context {
viewModel.context
@@ -28,9 +29,10 @@ final class MediaUploadPreviewScreenViewModelTests {
init() {
AppSettings.resetAllSettings()
let appSettings = AppSettings()
appSettings = AppSettings()
appSettings.optimizeMediaUploads = false
ServiceLocator.shared.register(appSettings: appSettings)
userIndicatorController = UserIndicatorControllerMock.default
}
deinit {
@@ -289,14 +291,12 @@ final class MediaUploadPreviewScreenViewModelTests {
if let maxUploadSizeResult {
clientProxy.underlyingMaxMediaUploadSize = maxUploadSizeResult
}
userIndicatorController = UserIndicatorControllerMock()
viewModel = MediaUploadPreviewScreenViewModel(mediaURLs: urls,
title: "Some File",
isRoomEncrypted: true,
shouldShowCaptionWarning: true,
mediaUploadingPreprocessor: MediaUploadingPreprocessor(appSettings: ServiceLocator.shared.settings),
mediaUploadingPreprocessor: MediaUploadingPreprocessor(appSettings: appSettings),
timelineController: MockTimelineController(timelineProxy: timelineProxy),
clientProxy: clientProxy,
userIndicatorController: userIndicatorController)
@@ -20,7 +20,6 @@ final class MediaUploadingPreprocessorTests {
AppSettings.resetAllSettings()
appSettings = AppSettings()
appSettings.optimizeMediaUploads = false
ServiceLocator.shared.register(appSettings: appSettings)
mediaUploadingPreprocessor = MediaUploadingPreprocessor(appSettings: appSettings)
}
@@ -22,13 +22,11 @@ final class NotificationManagerTests {
private var handleInlineReplyDelegateCalled = false
private var notificationTappedDelegateCalled = false
private var registerForRemoteNotificationsDelegateCalled: (() -> Void)?
private var appSettings: AppSettings {
ServiceLocator.shared.settings
}
private let appSettings: AppSettings
init() {
AppSettings.resetAllSettings()
appSettings = AppSettings()
notificationCenter = UserNotificationCenterMock()
notificationCenter.requestAuthorizationOptionsReturnValue = true
notificationCenter.authorizationStatusReturnValue = .authorized
+88 -44
View File
@@ -15,6 +15,10 @@ import Testing
struct PillContextTests {
@Test
func user() async {
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
let userIndicatorController = UserIndicatorControllerMock.default
let id = "@test:matrix.org"
let proxyMock = JoinedRoomProxyMock(.init(name: "Test"))
let subject = CurrentValueSubject<[RoomMemberProxyProtocol], Never>([])
@@ -23,11 +27,11 @@ struct PillContextTests {
timelineController: MockTimelineController(),
userSession: UserSessionMock(.init()),
mediaPlayerProvider: MediaPlayerProviderMock(),
userIndicatorController: ServiceLocator.shared.userIndicatorController,
userIndicatorController: userIndicatorController,
appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings,
analyticsService: ServiceLocator.shared.analytics,
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings),
appSettings: appSettings,
analyticsService: analytics,
emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(),
timelineControllerFactory: TimelineControllerFactoryMock(.init()))
let context = PillContext(timelineContext: mock.context, data: PillTextAttachmentData(type: .user(userID: id), font: .preferredFont(forTextStyle: .body)))
@@ -46,6 +50,10 @@ struct PillContextTests {
@Test
func ownUser() {
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
let userIndicatorController = UserIndicatorControllerMock.default
let id = "@test:matrix.org"
let proxyMock = JoinedRoomProxyMock(.init(name: "Test", ownUserID: id))
let subject = CurrentValueSubject<[RoomMemberProxyProtocol], Never>([])
@@ -54,11 +62,11 @@ struct PillContextTests {
timelineController: MockTimelineController(),
userSession: UserSessionMock(.init()),
mediaPlayerProvider: MediaPlayerProviderMock(),
userIndicatorController: ServiceLocator.shared.userIndicatorController,
userIndicatorController: userIndicatorController,
appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings,
analyticsService: ServiceLocator.shared.analytics,
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings),
appSettings: appSettings,
analyticsService: analytics,
emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(),
timelineControllerFactory: TimelineControllerFactoryMock(.init()))
let context = PillContext(timelineContext: mock.context, data: PillTextAttachmentData(type: .user(userID: id), font: .preferredFont(forTextStyle: .body)))
@@ -68,6 +76,10 @@ struct PillContextTests {
@Test
func allUsers() {
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
let userIndicatorController = UserIndicatorControllerMock.default
let avatarURL = URL(string: "https://matrix.jpg")
let id = "test_room"
let displayName = "Test"
@@ -78,11 +90,11 @@ struct PillContextTests {
timelineController: mockController,
userSession: UserSessionMock(.init()),
mediaPlayerProvider: MediaPlayerProviderMock(),
userIndicatorController: ServiceLocator.shared.userIndicatorController,
userIndicatorController: userIndicatorController,
appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings,
analyticsService: ServiceLocator.shared.analytics,
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings),
appSettings: appSettings,
analyticsService: analytics,
emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(),
timelineControllerFactory: TimelineControllerFactoryMock(.init()))
let context = PillContext(timelineContext: mock.context, data: PillTextAttachmentData(type: .allUsers, font: .preferredFont(forTextStyle: .body)))
@@ -93,6 +105,10 @@ struct PillContextTests {
@Test
func roomIDMention() {
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
let userIndicatorController = UserIndicatorControllerMock.default
let proxyMock = JoinedRoomProxyMock(.init())
let mockController = MockTimelineController()
let clientMock = ClientProxyMock(.init())
@@ -102,11 +118,11 @@ struct PillContextTests {
timelineController: mockController,
userSession: UserSessionMock(.init(clientProxy: clientMock)),
mediaPlayerProvider: MediaPlayerProviderMock(),
userIndicatorController: ServiceLocator.shared.userIndicatorController,
userIndicatorController: userIndicatorController,
appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings,
analyticsService: ServiceLocator.shared.analytics,
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings),
appSettings: appSettings,
analyticsService: analytics,
emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(),
timelineControllerFactory: TimelineControllerFactoryMock(.init()))
let context = PillContext(timelineContext: mock.context, data: PillTextAttachmentData(type: .roomID("1"), font: .preferredFont(forTextStyle: .body)))
@@ -118,6 +134,10 @@ struct PillContextTests {
@Test
func roomIDMentionMissingRoom() {
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
let userIndicatorController = UserIndicatorControllerMock.default
let proxyMock = JoinedRoomProxyMock(.init())
let mockController = MockTimelineController()
mockController.roomProxy = proxyMock
@@ -125,11 +145,11 @@ struct PillContextTests {
timelineController: mockController,
userSession: UserSessionMock(.init()),
mediaPlayerProvider: MediaPlayerProviderMock(),
userIndicatorController: ServiceLocator.shared.userIndicatorController,
userIndicatorController: userIndicatorController,
appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings,
analyticsService: ServiceLocator.shared.analytics,
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings),
appSettings: appSettings,
analyticsService: analytics,
emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(),
timelineControllerFactory: TimelineControllerFactoryMock(.init()))
let context = PillContext(timelineContext: mock.context, data: PillTextAttachmentData(type: .roomID("1"), font: .preferredFont(forTextStyle: .body)))
@@ -141,6 +161,10 @@ struct PillContextTests {
@Test
func roomAliasMention() {
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
let userIndicatorController = UserIndicatorControllerMock.default
let proxyMock = JoinedRoomProxyMock(.init())
let mockController = MockTimelineController()
mockController.roomProxy = proxyMock
@@ -152,11 +176,11 @@ struct PillContextTests {
timelineController: mockController,
userSession: UserSessionMock(.init(clientProxy: clientMock)),
mediaPlayerProvider: MediaPlayerProviderMock(),
userIndicatorController: ServiceLocator.shared.userIndicatorController,
userIndicatorController: userIndicatorController,
appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings,
analyticsService: ServiceLocator.shared.analytics,
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings),
appSettings: appSettings,
analyticsService: analytics,
emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(),
timelineControllerFactory: TimelineControllerFactoryMock(.init()))
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
func roomAliasMentionMissingRoom() {
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
let userIndicatorController = UserIndicatorControllerMock.default
let proxyMock = JoinedRoomProxyMock(.init())
let mockController = MockTimelineController()
mockController.roomProxy = proxyMock
@@ -175,11 +203,11 @@ struct PillContextTests {
timelineController: mockController,
userSession: UserSessionMock(.init()),
mediaPlayerProvider: MediaPlayerProviderMock(),
userIndicatorController: ServiceLocator.shared.userIndicatorController,
userIndicatorController: userIndicatorController,
appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings,
analyticsService: ServiceLocator.shared.analytics,
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings),
appSettings: appSettings,
analyticsService: analytics,
emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(),
timelineControllerFactory: TimelineControllerFactoryMock(.init()))
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
func eventOnRoomIDMention() {
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
let userIndicatorController = UserIndicatorControllerMock.default
let proxyMock = JoinedRoomProxyMock(.init())
let mockController = MockTimelineController()
mockController.roomProxy = proxyMock
@@ -200,11 +232,11 @@ struct PillContextTests {
timelineController: mockController,
userSession: UserSessionMock(.init(clientProxy: clientMock)),
mediaPlayerProvider: MediaPlayerProviderMock(),
userIndicatorController: ServiceLocator.shared.userIndicatorController,
userIndicatorController: userIndicatorController,
appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings,
analyticsService: ServiceLocator.shared.analytics,
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings),
appSettings: appSettings,
analyticsService: analytics,
emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(),
timelineControllerFactory: TimelineControllerFactoryMock(.init()))
let context = PillContext(timelineContext: mock.context, data: PillTextAttachmentData(type: .event(room: .roomID("1")), font: .preferredFont(forTextStyle: .body)))
@@ -216,6 +248,10 @@ struct PillContextTests {
@Test
func eventOnRoomIDMentionMissingRoom() {
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
let userIndicatorController = UserIndicatorControllerMock.default
let proxyMock = JoinedRoomProxyMock(.init())
let mockController = MockTimelineController()
mockController.roomProxy = proxyMock
@@ -223,11 +259,11 @@ struct PillContextTests {
timelineController: mockController,
userSession: UserSessionMock(.init()),
mediaPlayerProvider: MediaPlayerProviderMock(),
userIndicatorController: ServiceLocator.shared.userIndicatorController,
userIndicatorController: userIndicatorController,
appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings,
analyticsService: ServiceLocator.shared.analytics,
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings),
appSettings: appSettings,
analyticsService: analytics,
emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(),
timelineControllerFactory: TimelineControllerFactoryMock(.init()))
let context = PillContext(timelineContext: mock.context, data: PillTextAttachmentData(type: .event(room: .roomID("1")), font: .preferredFont(forTextStyle: .body)))
@@ -239,6 +275,10 @@ struct PillContextTests {
@Test
func eventOnRoomAliasMention() {
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
let userIndicatorController = UserIndicatorControllerMock.default
let proxyMock = JoinedRoomProxyMock(.init())
let mockController = MockTimelineController()
mockController.roomProxy = proxyMock
@@ -250,11 +290,11 @@ struct PillContextTests {
timelineController: mockController,
userSession: UserSessionMock(.init(clientProxy: clientMock)),
mediaPlayerProvider: MediaPlayerProviderMock(),
userIndicatorController: ServiceLocator.shared.userIndicatorController,
userIndicatorController: userIndicatorController,
appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings,
analyticsService: ServiceLocator.shared.analytics,
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings),
appSettings: appSettings,
analyticsService: analytics,
emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(),
timelineControllerFactory: TimelineControllerFactoryMock(.init()))
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
func eventOnRoomAliasMentionMissingRoom() {
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
let userIndicatorController = UserIndicatorControllerMock.default
let proxyMock = JoinedRoomProxyMock(.init())
let mockController = MockTimelineController()
mockController.roomProxy = proxyMock
@@ -273,11 +317,11 @@ struct PillContextTests {
timelineController: mockController,
userSession: UserSessionMock(.init()),
mediaPlayerProvider: MediaPlayerProviderMock(),
userIndicatorController: ServiceLocator.shared.userIndicatorController,
userIndicatorController: userIndicatorController,
appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings,
analyticsService: ServiceLocator.shared.analytics,
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings),
appSettings: appSettings,
analyticsService: analytics,
emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(),
timelineControllerFactory: TimelineControllerFactoryMock(.init()))
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) {
viewModel = PollFormScreenViewModel(mode: mode,
timelineController: MockTimelineController(timelineProxy: timelineProxy),
analytics: ServiceLocator.shared.analytics,
analytics: .mock(),
userIndicatorController: UserIndicatorControllerMock())
}
}
@@ -125,6 +125,6 @@ struct RoomChangePermissionsScreenViewModelTests {
ownPowerLevel: ownPowerLevel,
roomProxy: roomProxy,
userIndicatorController: UserIndicatorControllerMock(),
analytics: ServiceLocator.shared.analytics)
analytics: .mock())
}
}
@@ -197,6 +197,6 @@ struct RoomChangeRolesScreenViewModelTests {
roomProxy: roomProxy,
mediaProvider: MediaProviderMock(configuration: .init()),
userIndicatorController: UserIndicatorControllerMock(),
analytics: ServiceLocator.shared.analytics)
analytics: .mock())
}
}
@@ -167,7 +167,7 @@ struct RoomDetailsEditScreenViewModelTests {
userIndicatorController = UserIndicatorControllerMock.default
viewModel = .init(roomProxy: JoinedRoomProxyMock(roomProxyConfiguration),
userSession: UserSessionMock(.init()),
mediaUploadingPreprocessor: MediaUploadingPreprocessor(appSettings: ServiceLocator.shared.settings),
mediaUploadingPreprocessor: MediaUploadingPreprocessor(appSettings: AppSettings()),
userIndicatorController: userIndicatorController)
}
}
@@ -26,29 +26,33 @@ struct RoomDetailsScreenViewModelTests {
init() {
AppSettings.resetAllSettings()
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
cancellables.removeAll()
roomProxyMock = JoinedRoomProxyMock(.init(name: "Test"))
notificationSettingsProxyMock = NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration())
viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock,
userSession: UserSessionMock(.init()),
analyticsService: ServiceLocator.shared.analytics,
userIndicatorController: ServiceLocator.shared.userIndicatorController,
analyticsService: .mock(settings: appSettings),
userIndicatorController: UserIndicatorControllerMock.default,
notificationSettingsProxy: notificationSettingsProxyMock,
attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()),
appSettings: ServiceLocator.shared.settings)
appSettings: appSettings)
}
@Test
mutating func leaveRoomTappedWhenPublic() async throws {
let appSettings = AppSettings()
let mockedMembers: [RoomMemberProxyMock] = [.mockBob, .mockAlice]
roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", members: mockedMembers, joinRule: .public))
viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock,
userSession: UserSessionMock(.init()),
analyticsService: ServiceLocator.shared.analytics,
userIndicatorController: ServiceLocator.shared.userIndicatorController,
analyticsService: .mock(settings: appSettings),
userIndicatorController: UserIndicatorControllerMock.default,
notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()),
attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()),
appSettings: ServiceLocator.shared.settings)
appSettings: appSettings)
let deferred = deferFulfillment(context.observe(\.viewState.bindings.leaveRoomAlertItem)) { $0 != nil }
context.send(viewAction: .processTapLeave)
@@ -60,15 +64,17 @@ struct RoomDetailsScreenViewModelTests {
@Test
mutating func leaveRoomTappedWhenRoomNotPublic() async throws {
let appSettings = AppSettings()
let mockedMembers: [RoomMemberProxyMock] = [.mockBob, .mockAlice]
roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", members: mockedMembers))
viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock,
userSession: UserSessionMock(.init()),
analyticsService: ServiceLocator.shared.analytics,
userIndicatorController: ServiceLocator.shared.userIndicatorController,
analyticsService: .mock(settings: appSettings),
userIndicatorController: UserIndicatorControllerMock.default,
notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()),
attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()),
appSettings: ServiceLocator.shared.settings)
appSettings: appSettings)
let deferred = deferFulfillment(context.observe(\.viewState.bindings.leaveRoomAlertItem)) { $0 != nil }
context.send(viewAction: .processTapLeave)
@@ -81,15 +87,17 @@ struct RoomDetailsScreenViewModelTests {
@Test
mutating func leaveRoomTappedWithLessThanTwoMembers() {
let appSettings = AppSettings()
let mockedMembers: [RoomMemberProxyMock] = [.mockAlice]
roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", members: mockedMembers))
viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock,
userSession: UserSessionMock(.init()),
analyticsService: ServiceLocator.shared.analytics,
userIndicatorController: ServiceLocator.shared.userIndicatorController,
analyticsService: .mock(settings: appSettings),
userIndicatorController: UserIndicatorControllerMock.default,
notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()),
attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()),
appSettings: ServiceLocator.shared.settings)
appSettings: appSettings)
context.send(viewAction: .processTapLeave)
#expect(context.leaveRoomAlertItem?.state == .empty)
@@ -138,16 +146,18 @@ struct RoomDetailsScreenViewModelTests {
@Test
mutating func initialDMDetailsState() async throws {
let appSettings = AppSettings()
let recipient = RoomMemberProxyMock.mockDan
let mockedMembers: [RoomMemberProxyMock] = [.mockMe, recipient]
roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", isDirect: true, isEncrypted: true, members: mockedMembers))
viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock,
userSession: UserSessionMock(.init()),
analyticsService: ServiceLocator.shared.analytics,
userIndicatorController: ServiceLocator.shared.userIndicatorController,
analyticsService: .mock(settings: appSettings),
userIndicatorController: UserIndicatorControllerMock.default,
notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()),
attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()),
appSettings: ServiceLocator.shared.settings)
appSettings: appSettings)
let deferred = deferFulfillment(viewModel.context.observe(\.viewState.dmRecipientInfo)) { $0 != nil }
@@ -158,17 +168,19 @@ struct RoomDetailsScreenViewModelTests {
@Test
mutating func ignoreSuccess() async throws {
let appSettings = AppSettings()
let recipient = RoomMemberProxyMock.mockDan
let mockedMembers: [RoomMemberProxyMock] = [.mockMe, recipient]
roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", isDirect: true, isEncrypted: true, members: mockedMembers))
viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock,
userSession: UserSessionMock(.init()),
analyticsService: ServiceLocator.shared.analytics,
userIndicatorController: ServiceLocator.shared.userIndicatorController,
analyticsService: .mock(settings: appSettings),
userIndicatorController: UserIndicatorControllerMock.default,
notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()),
attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()),
appSettings: ServiceLocator.shared.settings)
appSettings: appSettings)
let deferredRecipient = deferFulfillment(viewModel.context.observe(\.viewState.dmRecipientInfo)) { $0 != nil }
@@ -188,6 +200,8 @@ struct RoomDetailsScreenViewModelTests {
@Test
mutating func ignoreFailure() async throws {
let appSettings = AppSettings()
let recipient = RoomMemberProxyMock.mockDan
let mockedMembers: [RoomMemberProxyMock] = [.mockMe, recipient]
let clientProxy = ClientProxyMock(.init())
@@ -195,11 +209,11 @@ struct RoomDetailsScreenViewModelTests {
roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", isDirect: true, isEncrypted: true, members: mockedMembers))
viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock,
userSession: UserSessionMock(.init(clientProxy: clientProxy)),
analyticsService: ServiceLocator.shared.analytics,
userIndicatorController: ServiceLocator.shared.userIndicatorController,
analyticsService: .mock(settings: appSettings),
userIndicatorController: UserIndicatorControllerMock.default,
notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()),
attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()),
appSettings: ServiceLocator.shared.settings)
appSettings: appSettings)
let deferredRecipient = deferFulfillment(viewModel.context.observe(\.viewState.dmRecipientInfo)) { $0 != nil }
@@ -220,16 +234,18 @@ struct RoomDetailsScreenViewModelTests {
@Test
mutating func unignoreSuccess() async throws {
let appSettings = AppSettings()
let recipient = RoomMemberProxyMock.mockIgnored
let mockedMembers: [RoomMemberProxyMock] = [.mockMe, recipient]
roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", isDirect: true, isEncrypted: true, members: mockedMembers))
viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock,
userSession: UserSessionMock(.init()),
analyticsService: ServiceLocator.shared.analytics,
userIndicatorController: ServiceLocator.shared.userIndicatorController,
analyticsService: .mock(settings: appSettings),
userIndicatorController: UserIndicatorControllerMock.default,
notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()),
attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()),
appSettings: ServiceLocator.shared.settings)
appSettings: appSettings)
let deferredRecipient = deferFulfillment(viewModel.context.observe(\.viewState.dmRecipientInfo)) { $0 != nil }
@@ -249,6 +265,8 @@ struct RoomDetailsScreenViewModelTests {
@Test
mutating func unignoreFailure() async throws {
let appSettings = AppSettings()
let recipient = RoomMemberProxyMock.mockIgnored
let mockedMembers: [RoomMemberProxyMock] = [.mockMe, recipient]
let clientProxy = ClientProxyMock(.init())
@@ -256,11 +274,11 @@ struct RoomDetailsScreenViewModelTests {
roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", isDirect: true, isEncrypted: true, members: mockedMembers))
viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock,
userSession: UserSessionMock(.init(clientProxy: clientProxy)),
analyticsService: ServiceLocator.shared.analytics,
userIndicatorController: ServiceLocator.shared.userIndicatorController,
analyticsService: .mock(settings: appSettings),
userIndicatorController: UserIndicatorControllerMock.default,
notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()),
attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()),
appSettings: ServiceLocator.shared.settings)
appSettings: appSettings)
let deferredRecipient = deferFulfillment(viewModel.context.observe(\.viewState.dmRecipientInfo)) { $0 != nil }
@@ -281,6 +299,8 @@ struct RoomDetailsScreenViewModelTests {
@Test
mutating func cannotInvitePeople() async {
let appSettings = AppSettings()
let mockedMembers: [RoomMemberProxyMock] = [.mockMe, .mockAlice]
roomProxyMock = JoinedRoomProxyMock(.init(name: "Test",
members: mockedMembers,
@@ -288,11 +308,11 @@ struct RoomDetailsScreenViewModelTests {
powerLevelsConfiguration: .init(canUserInvite: false)))
viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock,
userSession: UserSessionMock(.init()),
analyticsService: ServiceLocator.shared.analytics,
userIndicatorController: ServiceLocator.shared.userIndicatorController,
analyticsService: .mock(settings: appSettings),
userIndicatorController: UserIndicatorControllerMock.default,
notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()),
attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()),
appSettings: ServiceLocator.shared.settings)
appSettings: appSettings)
_ = await context.observe(\.viewState).debounce(for: .milliseconds(100)).first()
@@ -301,15 +321,17 @@ struct RoomDetailsScreenViewModelTests {
@Test
mutating func invitePeople() async {
let appSettings = AppSettings()
let mockedMembers: [RoomMemberProxyMock] = [.mockMe, .mockBob, .mockAlice]
roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", members: mockedMembers, joinRule: .public))
viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock,
userSession: UserSessionMock(.init()),
analyticsService: ServiceLocator.shared.analytics,
userIndicatorController: ServiceLocator.shared.userIndicatorController,
analyticsService: .mock(settings: appSettings),
userIndicatorController: UserIndicatorControllerMock.default,
notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()),
attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()),
appSettings: ServiceLocator.shared.settings)
appSettings: appSettings)
_ = await context.observe(\.viewState).debounce(for: .milliseconds(100)).first()
@@ -334,6 +356,8 @@ struct RoomDetailsScreenViewModelTests {
@Test
mutating func canEditAvatar() async {
let appSettings = AppSettings()
let mockedMembers: [RoomMemberProxyMock] = [.mockMe, .mockBob, .mockAlice]
let configuration = JoinedRoomProxyMockConfiguration(name: "Test",
@@ -357,11 +381,11 @@ struct RoomDetailsScreenViewModelTests {
viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock,
userSession: UserSessionMock(.init()),
analyticsService: ServiceLocator.shared.analytics,
userIndicatorController: ServiceLocator.shared.userIndicatorController,
analyticsService: .mock(settings: appSettings),
userIndicatorController: UserIndicatorControllerMock.default,
notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()),
attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()),
appSettings: ServiceLocator.shared.settings)
appSettings: appSettings)
_ = await context.observe(\.viewState).debounce(for: .milliseconds(100)).first()
@@ -373,6 +397,8 @@ struct RoomDetailsScreenViewModelTests {
@Test
mutating func canEditName() async {
let appSettings = AppSettings()
let mockedMembers: [RoomMemberProxyMock] = [.mockMe, .mockBob, .mockAlice]
let configuration = JoinedRoomProxyMockConfiguration(name: "Test",
@@ -396,11 +422,11 @@ struct RoomDetailsScreenViewModelTests {
viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock,
userSession: UserSessionMock(.init()),
analyticsService: ServiceLocator.shared.analytics,
userIndicatorController: ServiceLocator.shared.userIndicatorController,
analyticsService: .mock(settings: appSettings),
userIndicatorController: UserIndicatorControllerMock.default,
notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()),
attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()),
appSettings: ServiceLocator.shared.settings)
appSettings: appSettings)
_ = await context.observe(\.viewState).debounce(for: .milliseconds(100)).first()
@@ -412,6 +438,8 @@ struct RoomDetailsScreenViewModelTests {
@Test
mutating func canEditTopic() async {
let appSettings = AppSettings()
let mockedMembers: [RoomMemberProxyMock] = [.mockMe, .mockBob, .mockAlice]
let configuration = JoinedRoomProxyMockConfiguration(name: "Test",
@@ -435,11 +463,11 @@ struct RoomDetailsScreenViewModelTests {
viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock,
userSession: UserSessionMock(.init()),
analyticsService: ServiceLocator.shared.analytics,
userIndicatorController: ServiceLocator.shared.userIndicatorController,
analyticsService: .mock(settings: appSettings),
userIndicatorController: UserIndicatorControllerMock.default,
notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()),
attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()),
appSettings: ServiceLocator.shared.settings)
appSettings: appSettings)
_ = await context.observe(\.viewState).debounce(for: .milliseconds(100)).first()
@@ -451,15 +479,17 @@ struct RoomDetailsScreenViewModelTests {
@Test
mutating func cannotEditRoom() async {
let appSettings = AppSettings()
let mockedMembers: [RoomMemberProxyMock] = [.mockMe, .mockBob, .mockAlice]
roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", isDirect: false, members: mockedMembers))
viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock,
userSession: UserSessionMock(.init()),
analyticsService: ServiceLocator.shared.analytics,
userIndicatorController: ServiceLocator.shared.userIndicatorController,
analyticsService: .mock(settings: appSettings),
userIndicatorController: UserIndicatorControllerMock.default,
notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()),
attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()),
appSettings: ServiceLocator.shared.settings)
appSettings: appSettings)
_ = await context.observe(\.viewState).debounce(for: .milliseconds(100)).first()
@@ -471,15 +501,17 @@ struct RoomDetailsScreenViewModelTests {
@Test
mutating func cannotEditDirectRoom() async {
let appSettings = AppSettings()
let mockedMembers: [RoomMemberProxyMock] = [.mockMeAdmin, .mockBob, .mockAlice]
roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", isDirect: true, members: mockedMembers))
viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock,
userSession: UserSessionMock(.init()),
analyticsService: ServiceLocator.shared.analytics,
userIndicatorController: ServiceLocator.shared.userIndicatorController,
analyticsService: .mock(settings: appSettings),
userIndicatorController: UserIndicatorControllerMock.default,
notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()),
attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()),
appSettings: ServiceLocator.shared.settings)
appSettings: appSettings)
_ = await context.observe(\.viewState).debounce(for: .milliseconds(100)).first()
@@ -490,14 +522,16 @@ struct RoomDetailsScreenViewModelTests {
@Test
mutating func notificationLoadingSettingsFailure() async throws {
let appSettings = AppSettings()
notificationSettingsProxyMock.getNotificationSettingsRoomIdIsEncryptedIsOneToOneThrowableError = NotificationSettingsError.Generic(msg: "error")
viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock,
userSession: UserSessionMock(.init()),
analyticsService: ServiceLocator.shared.analytics,
userIndicatorController: ServiceLocator.shared.userIndicatorController,
analyticsService: .mock(settings: appSettings),
userIndicatorController: UserIndicatorControllerMock.default,
notificationSettingsProxy: notificationSettingsProxyMock,
attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()),
appSettings: ServiceLocator.shared.settings)
appSettings: appSettings)
var deferred = deferFulfillment(context.observe(\.viewState.notificationSettingsState)) { $0.isError }
@@ -697,15 +731,17 @@ struct RoomDetailsScreenViewModelTests {
@Test
mutating func knockRequestsCounter() async throws {
let appSettings = AppSettings()
let mockedRequests: [KnockRequestProxyMock] = [.init(), .init()]
roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", isDirect: false, knockRequestsState: .loaded(mockedRequests), joinRule: .knock))
viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock,
userSession: UserSessionMock(.init()),
analyticsService: ServiceLocator.shared.analytics,
userIndicatorController: ServiceLocator.shared.userIndicatorController,
analyticsService: .mock(settings: appSettings),
userIndicatorController: UserIndicatorControllerMock.default,
notificationSettingsProxy: notificationSettingsProxyMock,
attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()),
appSettings: ServiceLocator.shared.settings)
appSettings: appSettings)
let deferred = deferFulfillment(context.observe(\.viewState)) { state in
state.knockRequestsCount == 2 && state.canSeeKnockingRequests
@@ -719,14 +755,16 @@ struct RoomDetailsScreenViewModelTests {
@Test
mutating func knockRequestsCounterIsLoading() async throws {
let appSettings = AppSettings()
roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", isDirect: false, knockRequestsState: .loading, joinRule: .knock))
viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock,
userSession: UserSessionMock(.init()),
analyticsService: ServiceLocator.shared.analytics,
userIndicatorController: ServiceLocator.shared.userIndicatorController,
analyticsService: .mock(settings: appSettings),
userIndicatorController: UserIndicatorControllerMock.default,
notificationSettingsProxy: notificationSettingsProxyMock,
attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()),
appSettings: ServiceLocator.shared.settings)
appSettings: appSettings)
let deferred = deferFulfillment(context.observe(\.viewState)) { state in
state.knockRequestsCount == 0 && state.canSeeKnockingRequests
@@ -737,6 +775,8 @@ struct RoomDetailsScreenViewModelTests {
@Test
mutating func knockRequestsCounterIsNotShownIfNoPermissions() async throws {
let appSettings = AppSettings()
let mockedRequests: [KnockRequestProxyMock] = [.init(), .init()]
roomProxyMock = JoinedRoomProxyMock(.init(name: "Test",
isDirect: false,
@@ -745,11 +785,11 @@ struct RoomDetailsScreenViewModelTests {
powerLevelsConfiguration: .init(canUserInvite: false)))
viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock,
userSession: UserSessionMock(.init()),
analyticsService: ServiceLocator.shared.analytics,
userIndicatorController: ServiceLocator.shared.userIndicatorController,
analyticsService: .mock(settings: appSettings),
userIndicatorController: UserIndicatorControllerMock.default,
notificationSettingsProxy: notificationSettingsProxyMock,
attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()),
appSettings: ServiceLocator.shared.settings)
appSettings: appSettings)
let deferred = deferFulfillment(context.observe(\.viewState)) { state in
state.knockRequestsCount == 2 &&
@@ -763,16 +803,18 @@ struct RoomDetailsScreenViewModelTests {
@Test
mutating func knockRequestsCounterIsNotShownIfDM() async throws {
let appSettings = AppSettings()
let mockedRequests: [KnockRequestProxyMock] = [.init(), .init()]
let mockedMembers: [RoomMemberProxyMock] = [.mockMe, .mockAlice]
roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", isDirect: true, members: mockedMembers, knockRequestsState: .loaded(mockedRequests), joinRule: .knock))
viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock,
userSession: UserSessionMock(.init()),
analyticsService: ServiceLocator.shared.analytics,
userIndicatorController: ServiceLocator.shared.userIndicatorController,
analyticsService: .mock(settings: appSettings),
userIndicatorController: UserIndicatorControllerMock.default,
notificationSettingsProxy: notificationSettingsProxyMock,
attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()),
appSettings: ServiceLocator.shared.settings)
appSettings: appSettings)
let deferred = deferFulfillment(context.observe(\.viewState)) { state in
state.knockRequestsCount == 2 &&
@@ -788,6 +830,8 @@ struct RoomDetailsScreenViewModelTests {
@Test
mutating func historySharingPillDisplayed() async throws {
let appSettings = AppSettings()
let configuration = JoinedRoomProxyMockConfiguration(historyVisibility: .shared)
let infoSubject = CurrentValueSubject<RoomInfoProxyProtocol, Never>(RoomInfoProxyMock(configuration))
let roomProxyMock = JoinedRoomProxyMock(configuration)
@@ -795,11 +839,11 @@ struct RoomDetailsScreenViewModelTests {
viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock,
userSession: UserSessionMock(.init()),
analyticsService: ServiceLocator.shared.analytics,
userIndicatorController: ServiceLocator.shared.userIndicatorController,
analyticsService: .mock(settings: appSettings),
userIndicatorController: UserIndicatorControllerMock.default,
notificationSettingsProxy: notificationSettingsProxyMock,
attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()),
appSettings: ServiceLocator.shared.settings)
appSettings: appSettings)
let deferredShared = deferFulfillment(context.observe(\.viewState),
message: "The pill should be shown for rooms with shared history visibility") { state in
@@ -18,7 +18,13 @@ final class RoomFlowCoordinatorTests {
var roomFlowCoordinator: RoomFlowCoordinator!
var navigationStackCoordinator: NavigationStackCoordinator!
var cancellables = Set<AnyCancellable>()
private let appSettings: AppSettings
init() {
appSettings = AppSettings()
}
deinit {
AppSettings.resetAllSettings()
}
@@ -236,7 +242,7 @@ final class RoomFlowCoordinatorTests {
@Test
func threadedEventRoutes() async throws {
ServiceLocator.shared.settings.threadsEnabled = true
appSettings.threadsEnabled = true
setupRoomFlowCoordinator()
// Navigate directly to the threaded event
@@ -479,13 +485,13 @@ final class RoomFlowCoordinatorTests {
bugReportService: BugReportServiceMock(.init()),
elementCallService: ElementCallServiceMock(.init()),
timelineControllerFactory: timelineControllerFactory,
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings),
emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(),
appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings,
appSettings: appSettings,
appHooks: AppHooks(),
analytics: ServiceLocator.shared.analytics,
userIndicatorController: ServiceLocator.shared.userIndicatorController,
analytics: .mock(settings: appSettings),
userIndicatorController: UserIndicatorControllerMock.default,
notificationManager: NotificationManagerMock(),
stateMachineFactory: StateMachineFactory())
@@ -205,13 +205,17 @@ struct RoomMemberDetailsViewModelTests {
roomProxyMock.getMemberUserIDClosure = { _ in
.success(roomMemberProxyMock)
}
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
// swiftlint:disable:next force_unwrapping
let userSession = clientProxy != nil ? UserSessionMock(.init(clientProxy: clientProxy!)) : UserSessionMock(.init())
viewModel = RoomMemberDetailsScreenViewModel(userID: roomMemberProxyMock.userID,
roomProxy: roomProxyMock,
userSession: userSession,
userIndicatorController: ServiceLocator.shared.userIndicatorController,
analytics: ServiceLocator.shared.analytics,
appSettings: ServiceLocator.shared.settings)
userIndicatorController: UserIndicatorControllerMock.default,
analytics: analytics,
appSettings: appSettings)
}
}
@@ -51,16 +51,19 @@ struct RoomMembersFlowCoordinatorTests {
let clientProxy = ClientProxyMock(.init())
clientProxy.directRoomForUserIDReturnValue = .success(nil)
let appSettings = AppSettings()
let analytics = AnalyticsService.mock(settings: appSettings)
let flowParameters = CommonFlowParameters(userSession: UserSessionMock(.init(clientProxy: clientProxy)),
bugReportService: BugReportServiceMock(.init()),
elementCallService: ElementCallServiceMock(.init()),
timelineControllerFactory: TimelineControllerFactoryMock(.init()),
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings),
emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(),
appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings,
appSettings: appSettings,
appHooks: AppHooks(),
analytics: ServiceLocator.shared.analytics,
analytics: analytics,
userIndicatorController: UserIndicatorControllerMock(),
notificationManager: NotificationManagerMock(),
stateMachineFactory: stateMachineFactory)
@@ -277,8 +277,8 @@ struct RoomMembersListScreenViewModelTests {
viewModel = RoomMembersListScreenViewModel(userSession: UserSessionMock(.init()),
roomProxy: roomProxy,
userIndicatorController: ServiceLocator.shared.userIndicatorController,
analytics: ServiceLocator.shared.analytics)
userIndicatorController: UserIndicatorControllerMock.default,
analytics: .mock())
let context = viewModel.context
@@ -297,7 +297,7 @@ struct RoomMembersListScreenViewModelTests {
roomProxy = JoinedRoomProxyMock(.init(name: "test", members: members))
viewModel = RoomMembersListScreenViewModel(userSession: UserSessionMock(.init()),
roomProxy: roomProxy,
userIndicatorController: ServiceLocator.shared.userIndicatorController,
analytics: ServiceLocator.shared.analytics)
userIndicatorController: UserIndicatorControllerMock.default,
analytics: .mock())
}
}
@@ -84,6 +84,6 @@ struct RoomRolesAndPermissionsScreenViewModelTests {
roomProxy = JoinedRoomProxyMock(.init(members: members))
viewModel = RoomRolesAndPermissionsScreenViewModel(roomProxy: roomProxy,
userIndicatorController: UserIndicatorControllerMock(),
analytics: ServiceLocator.shared.analytics)
analytics: .mock())
}
}
@@ -17,8 +17,11 @@ import Testing
final class RoomScreenViewModelTests {
private var viewModel: RoomScreenViewModel!
private let appSettings: AppSettings
init() async throws {
AppSettings.resetAllSettings()
appSettings = AppSettings()
}
deinit {
@@ -45,10 +48,10 @@ final class RoomScreenViewModelTests {
roomProxy: roomProxyMock,
initialSelectedPinnedEventID: nil,
ongoingCallRoomIDPublisher: .init(.init(nil)),
appSettings: ServiceLocator.shared.settings,
appSettings: appSettings,
appHooks: AppHooks(),
analyticsService: ServiceLocator.shared.analytics,
userIndicatorController: ServiceLocator.shared.userIndicatorController)
analyticsService: .mock(settings: appSettings),
userIndicatorController: UserIndicatorControllerMock.default)
self.viewModel = viewModel
// check if in the default state is not showing but is indeed loading
@@ -126,10 +129,10 @@ final class RoomScreenViewModelTests {
roomProxy: roomProxyMock,
initialSelectedPinnedEventID: "test1",
ongoingCallRoomIDPublisher: .init(.init(nil)),
appSettings: ServiceLocator.shared.settings,
appSettings: appSettings,
appHooks: AppHooks(),
analyticsService: ServiceLocator.shared.analytics,
userIndicatorController: ServiceLocator.shared.userIndicatorController)
analyticsService: .mock(settings: appSettings),
userIndicatorController: UserIndicatorControllerMock.default)
self.viewModel = viewModel
// check if the banner is now in a loaded state and is showing the counter
@@ -166,7 +169,7 @@ final class RoomScreenViewModelTests {
@Test
func pinnedEventsBannerThreadedSelection() async throws {
ServiceLocator.shared.settings.threadsEnabled = true
appSettings.threadsEnabled = true
let roomProxyMock = JoinedRoomProxyMock(.init())
let eventMock = TimelineEventSDKMock()
@@ -187,10 +190,10 @@ final class RoomScreenViewModelTests {
roomProxy: roomProxyMock,
initialSelectedPinnedEventID: "test1",
ongoingCallRoomIDPublisher: .init(.init(nil)),
appSettings: ServiceLocator.shared.settings,
appSettings: appSettings,
appHooks: AppHooks(),
analyticsService: ServiceLocator.shared.analytics,
userIndicatorController: ServiceLocator.shared.userIndicatorController)
analyticsService: .mock(settings: appSettings),
userIndicatorController: UserIndicatorControllerMock.default)
self.viewModel = viewModel
// check if the banner is now in a loaded state and is showing the counter
@@ -246,10 +249,10 @@ final class RoomScreenViewModelTests {
roomProxy: roomProxyMock,
initialSelectedPinnedEventID: nil,
ongoingCallRoomIDPublisher: .init(.init(nil)),
appSettings: ServiceLocator.shared.settings,
appSettings: appSettings,
appHooks: AppHooks(),
analyticsService: ServiceLocator.shared.analytics,
userIndicatorController: ServiceLocator.shared.userIndicatorController)
analyticsService: .mock(settings: appSettings),
userIndicatorController: UserIndicatorControllerMock.default)
self.viewModel = viewModel
#expect(viewModel.state.roomTitle == "StartingName")
@@ -283,10 +286,10 @@ final class RoomScreenViewModelTests {
roomProxy: roomProxyMock,
initialSelectedPinnedEventID: nil,
ongoingCallRoomIDPublisher: ongoingCallRoomIDSubject.asCurrentValuePublisher(),
appSettings: ServiceLocator.shared.settings,
appSettings: appSettings,
appHooks: AppHooks(),
analyticsService: ServiceLocator.shared.analytics,
userIndicatorController: ServiceLocator.shared.userIndicatorController)
analyticsService: .mock(settings: appSettings),
userIndicatorController: UserIndicatorControllerMock.default)
self.viewModel = viewModel
#expect(viewModel.state.shouldShowCallButton)
@@ -328,10 +331,10 @@ final class RoomScreenViewModelTests {
roomProxy: roomProxyMock,
initialSelectedPinnedEventID: nil,
ongoingCallRoomIDPublisher: .init(.init(nil)),
appSettings: ServiceLocator.shared.settings,
appSettings: appSettings,
appHooks: AppHooks(),
analyticsService: ServiceLocator.shared.analytics,
userIndicatorController: ServiceLocator.shared.userIndicatorController)
analyticsService: .mock(settings: appSettings),
userIndicatorController: UserIndicatorControllerMock.default)
self.viewModel = viewModel
viewModel.stop()
}
@@ -349,10 +352,10 @@ final class RoomScreenViewModelTests {
roomProxy: roomProxyMock,
initialSelectedPinnedEventID: nil,
ongoingCallRoomIDPublisher: .init(.init(nil)),
appSettings: ServiceLocator.shared.settings,
appSettings: appSettings,
appHooks: AppHooks(),
analyticsService: ServiceLocator.shared.analytics,
userIndicatorController: ServiceLocator.shared.userIndicatorController)
analyticsService: .mock(settings: appSettings),
userIndicatorController: UserIndicatorControllerMock.default)
self.viewModel = viewModel
var deferred = deferFulfillment(viewModel.context.$viewState) { state in
@@ -383,10 +386,10 @@ final class RoomScreenViewModelTests {
roomProxy: roomProxyMock,
initialSelectedPinnedEventID: nil,
ongoingCallRoomIDPublisher: .init(.init(nil)),
appSettings: ServiceLocator.shared.settings,
appSettings: appSettings,
appHooks: AppHooks(),
analyticsService: ServiceLocator.shared.analytics,
userIndicatorController: ServiceLocator.shared.userIndicatorController)
analyticsService: .mock(settings: appSettings),
userIndicatorController: UserIndicatorControllerMock.default)
self.viewModel = viewModel
var deferred = deferFulfillment(viewModel.context.$viewState) { state in
@@ -412,10 +415,10 @@ final class RoomScreenViewModelTests {
roomProxy: roomProxyMock,
initialSelectedPinnedEventID: nil,
ongoingCallRoomIDPublisher: .init(.init(nil)),
appSettings: ServiceLocator.shared.settings,
appSettings: appSettings,
appHooks: AppHooks(),
analyticsService: ServiceLocator.shared.analytics,
userIndicatorController: ServiceLocator.shared.userIndicatorController)
analyticsService: .mock(settings: appSettings),
userIndicatorController: UserIndicatorControllerMock.default)
self.viewModel = viewModel
// Loading state just does not appear at all
@@ -432,10 +435,10 @@ final class RoomScreenViewModelTests {
roomProxy: roomProxyMock,
initialSelectedPinnedEventID: nil,
ongoingCallRoomIDPublisher: .init(.init(nil)),
appSettings: ServiceLocator.shared.settings,
appSettings: appSettings,
appHooks: AppHooks(),
analyticsService: ServiceLocator.shared.analytics,
userIndicatorController: ServiceLocator.shared.userIndicatorController)
analyticsService: .mock(settings: appSettings),
userIndicatorController: UserIndicatorControllerMock.default)
self.viewModel = viewModel
let deferred = deferFulfillment(viewModel.context.$viewState) { state in
@@ -459,10 +462,10 @@ final class RoomScreenViewModelTests {
roomProxy: roomProxyMock,
initialSelectedPinnedEventID: nil,
ongoingCallRoomIDPublisher: .init(.init(nil)),
appSettings: ServiceLocator.shared.settings,
appSettings: appSettings,
appHooks: AppHooks(),
analyticsService: ServiceLocator.shared.analytics,
userIndicatorController: ServiceLocator.shared.userIndicatorController)
analyticsService: .mock(settings: appSettings),
userIndicatorController: UserIndicatorControllerMock.default)
self.viewModel = viewModel
let deferredInvisible = deferFailure(viewModel.context.$viewState,
@@ -16,18 +16,17 @@ final class ServerConfirmationScreenViewModelTests {
var clientFactory: AuthenticationClientFactoryMock!
var client: ClientSDKMock!
var service: AuthenticationServiceProtocol!
var appSettings: AppSettings!
var viewModel: ServerConfirmationScreenViewModel!
var context: ServerConfirmationScreenViewModel.Context {
viewModel.context
}
private let appSettings: AppSettings
init() {
AppSettings.resetAllSettings()
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 {
@@ -367,7 +366,7 @@ final class ServerConfirmationScreenViewModelTests {
viewModel = ServerConfirmationScreenViewModel(authenticationService: service,
mode: mode,
authenticationFlow: authenticationFlow,
appSettings: ServiceLocator.shared.settings,
appSettings: appSettings,
userIndicatorController: UserIndicatorControllerMock())
// Add a fake window in order for the OAuth flow to continue
@@ -148,17 +148,19 @@ struct ServerSelectionScreenViewModelTests {
// MARK: - Helpers
private mutating func setup(authenticationFlow: AuthenticationFlow) {
let appSettings = AppSettings()
clientFactory = AuthenticationClientFactoryMock(configuration: .init())
service = AuthenticationService(userSessionStore: UserSessionStoreMock(configuration: .init()),
encryptionKeyProvider: EncryptionKeyProvider(),
classicAppManager: nil,
clientFactory: clientFactory,
appSettings: ServiceLocator.shared.settings,
appSettings: appSettings,
appHooks: AppHooks())
viewModel = ServerSelectionScreenViewModel(authenticationService: service,
authenticationFlow: authenticationFlow,
appSettings: ServiceLocator.shared.settings,
appSettings: appSettings,
userIndicatorController: UserIndicatorControllerMock())
}
}
@@ -16,9 +16,10 @@ struct SettingsScreenViewModelTests {
private var context: SettingsScreenViewModelType.Context
init() {
let appSettings = AppSettings()
let userSession = UserSessionMock(.init(clientProxy: ClientProxyMock(.init(userID: ""))))
viewModel = SettingsScreenViewModel(userSession: userSession,
appSettings: ServiceLocator.shared.settings,
appSettings: appSettings,
isBugReportServiceEnabled: true,
isInSecondaryWindow: false)
context = viewModel.context
@@ -14,7 +14,7 @@ import Testing
final class SpacesScreenViewModelTests {
var topLevelSpacesSubject: CurrentValueSubject<[SpaceServiceRoom], Never>
var spaceServiceProxy: SpaceServiceProxyMock
var appSettings: AppSettings
var viewModel: SpacesScreenViewModelProtocol
var context: SpacesScreenViewModelType.Context {
@@ -23,7 +23,7 @@ final class SpacesScreenViewModelTests {
init() {
AppSettings.resetAllSettings()
appSettings = AppSettings()
let appSettings = AppSettings()
let clientProxy = ClientProxyMock(.init())
let userSession = UserSessionMock(.init(clientProxy: clientProxy))
@@ -43,7 +43,7 @@ final class SpacesScreenViewModelTests {
viewModel = SpacesScreenViewModel(userSession: userSession,
selectedSpacePublisher: .init(nil),
appSettings: ServiceLocator.shared.settings,
appSettings: appSettings,
userIndicatorController: UserIndicatorControllerMock())
}
@@ -20,15 +20,17 @@ struct StartChatScreenViewModelTests {
}
init() {
let appSettings = AppSettings()
clientProxy = .init(.init(userID: ""))
userDiscoveryService = UserDiscoveryServiceMock()
userDiscoveryService.searchProfilesWithReturnValue = .success([])
let userSession = UserSessionMock(.init(clientProxy: clientProxy))
viewModel = StartChatScreenViewModel(userSession: userSession,
analytics: ServiceLocator.shared.analytics,
analytics: .mock(settings: appSettings),
userIndicatorController: UserIndicatorControllerMock(),
userDiscoveryService: userDiscoveryService,
appSettings: ServiceLocator.shared.settings)
appSettings: appSettings)
}
@Test
+56 -46
View File
@@ -14,19 +14,13 @@ import Testing
@MainActor
final class TimelineViewModelTests {
var userIndicatorControllerMock: UserIndicatorControllerMock!
var cancellables = Set<AnyCancellable>()
init() async throws {
AppSettings.resetAllSettings()
cancellables.removeAll()
userIndicatorControllerMock = UserIndicatorControllerMock.default
}
deinit {
userIndicatorControllerMock = nil
}
// MARK: - Message Grouping
@Test
@@ -313,15 +307,17 @@ final class TimelineViewModelTests {
timelineController.timelineItems = items
timelineController.roomProxy = roomProxy
let appSettings = AppSettings()
let viewModel = TimelineViewModel(roomProxy: roomProxy,
timelineController: timelineController,
userSession: UserSessionMock(.init()),
mediaPlayerProvider: MediaPlayerProviderMock(),
userIndicatorController: userIndicatorControllerMock,
userIndicatorController: UserIndicatorControllerMock.default,
appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings,
analyticsService: ServiceLocator.shared.analytics,
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings),
appSettings: appSettings,
analyticsService: .mock(settings: appSettings),
emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(),
timelineControllerFactory: TimelineControllerFactoryMock(.init()))
return (viewModel, roomProxy, timelineProxy, timelineController)
@@ -337,6 +333,8 @@ final class TimelineViewModelTests {
addReadReceipts: receipts)
let id = message.id
let appSettings = AppSettings()
// When showing them in a timeline.
let timelineController = MockTimelineController()
timelineController.timelineItems = [message]
@@ -344,11 +342,11 @@ final class TimelineViewModelTests {
timelineController: timelineController,
userSession: UserSessionMock(.init()),
mediaPlayerProvider: MediaPlayerProviderMock(),
userIndicatorController: userIndicatorControllerMock,
userIndicatorController: UserIndicatorControllerMock.default,
appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings,
analyticsService: ServiceLocator.shared.analytics,
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings),
appSettings: appSettings,
analyticsService: .mock(settings: appSettings),
emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(),
timelineControllerFactory: TimelineControllerFactoryMock(.init()))
@@ -362,6 +360,8 @@ final class TimelineViewModelTests {
@Test
func showManageUserAsAdmin() async throws {
let appSettings = AppSettings()
let viewModel = TimelineViewModel(roomProxy: JoinedRoomProxyMock(.init(name: "",
members: [RoomMemberProxyMock.mockAdmin,
RoomMemberProxyMock.mockAlice],
@@ -369,11 +369,11 @@ final class TimelineViewModelTests {
timelineController: MockTimelineController(),
userSession: UserSessionMock(.init()),
mediaPlayerProvider: MediaPlayerProviderMock(),
userIndicatorController: userIndicatorControllerMock,
userIndicatorController: UserIndicatorControllerMock.default,
appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings,
analyticsService: ServiceLocator.shared.analytics,
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings),
appSettings: appSettings,
analyticsService: .mock(settings: appSettings),
emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(),
timelineControllerFactory: TimelineControllerFactoryMock(.init()))
@@ -399,6 +399,8 @@ final class TimelineViewModelTests {
@Test
func showDetailsForAnAdmin() async throws {
let appSettings = AppSettings()
let viewModel = TimelineViewModel(roomProxy: JoinedRoomProxyMock(.init(name: "",
members: [RoomMemberProxyMock.mockAdmin,
RoomMemberProxyMock.mockAlice],
@@ -406,11 +408,11 @@ final class TimelineViewModelTests {
timelineController: MockTimelineController(),
userSession: UserSessionMock(.init()),
mediaPlayerProvider: MediaPlayerProviderMock(),
userIndicatorController: userIndicatorControllerMock,
userIndicatorController: UserIndicatorControllerMock.default,
appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings,
analyticsService: ServiceLocator.shared.analytics,
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings),
appSettings: appSettings,
analyticsService: .mock(settings: appSettings),
emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(),
timelineControllerFactory: TimelineControllerFactoryMock(.init()))
@@ -436,6 +438,8 @@ final class TimelineViewModelTests {
@Test
func showDetailsForABannedUser() async throws {
let appSettings = AppSettings()
let viewModel = TimelineViewModel(roomProxy: JoinedRoomProxyMock(.init(name: "",
members: [RoomMemberProxyMock.mockAdmin,
RoomMemberProxyMock.mockBanned[0]],
@@ -443,11 +447,11 @@ final class TimelineViewModelTests {
timelineController: MockTimelineController(),
userSession: UserSessionMock(.init()),
mediaPlayerProvider: MediaPlayerProviderMock(),
userIndicatorController: userIndicatorControllerMock,
userIndicatorController: UserIndicatorControllerMock.default,
appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings,
analyticsService: ServiceLocator.shared.analytics,
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings),
appSettings: appSettings,
analyticsService: .mock(settings: appSettings),
emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(),
timelineControllerFactory: TimelineControllerFactoryMock(.init()))
@@ -476,6 +480,8 @@ final class TimelineViewModelTests {
@Test
func pinnedEvents() async throws {
let appSettings = AppSettings()
var configuration = JoinedRoomProxyMockConfiguration(name: "",
pinnedEventIDs: .init(["test1"]))
let roomProxyMock = JoinedRoomProxyMock(configuration)
@@ -486,11 +492,11 @@ final class TimelineViewModelTests {
timelineController: MockTimelineController(),
userSession: UserSessionMock(.init()),
mediaPlayerProvider: MediaPlayerProviderMock(),
userIndicatorController: userIndicatorControllerMock,
userIndicatorController: UserIndicatorControllerMock.default,
appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings,
analyticsService: ServiceLocator.shared.analytics,
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings),
appSettings: appSettings,
analyticsService: .mock(settings: appSettings),
emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(),
timelineControllerFactory: TimelineControllerFactoryMock(.init()))
#expect(configuration.pinnedEventIDs == viewModel.context.viewState.pinnedEventIDs)
@@ -505,6 +511,8 @@ final class TimelineViewModelTests {
@Test
func canUserPinEvents() async throws {
let appSettings = AppSettings()
let configuration = JoinedRoomProxyMockConfiguration(name: "",
powerLevelsConfiguration: .init(canUserPin: true))
let roomProxyMock = JoinedRoomProxyMock(configuration)
@@ -515,11 +523,11 @@ final class TimelineViewModelTests {
timelineController: MockTimelineController(),
userSession: UserSessionMock(.init()),
mediaPlayerProvider: MediaPlayerProviderMock(),
userIndicatorController: userIndicatorControllerMock,
userIndicatorController: UserIndicatorControllerMock.default,
appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings,
analyticsService: ServiceLocator.shared.analytics,
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings),
appSettings: appSettings,
analyticsService: .mock(settings: appSettings),
emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(),
timelineControllerFactory: TimelineControllerFactoryMock(.init()))
@@ -580,18 +588,20 @@ final class TimelineViewModelTests {
private func makeViewModel(roomProxy: JoinedRoomProxyProtocol? = nil,
focussedEventID: String? = nil,
timelineController: TimelineControllerProtocol) -> TimelineViewModel {
TimelineViewModel(roomProxy: roomProxy ?? JoinedRoomProxyMock(.init(name: "")),
focussedEventID: focussedEventID,
timelineController: timelineController,
userSession: UserSessionMock(.init()),
mediaPlayerProvider: MediaPlayerProviderMock(),
userIndicatorController: userIndicatorControllerMock,
appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings,
analyticsService: ServiceLocator.shared.analytics,
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings),
linkMetadataProvider: LinkMetadataProvider(),
timelineControllerFactory: TimelineControllerFactoryMock(.init()))
let appSettings = AppSettings()
return TimelineViewModel(roomProxy: roomProxy ?? JoinedRoomProxyMock(.init(name: "")),
focussedEventID: focussedEventID,
timelineController: timelineController,
userSession: UserSessionMock(.init()),
mediaPlayerProvider: MediaPlayerProviderMock(),
userIndicatorController: UserIndicatorControllerMock.default,
appMediator: AppMediatorMock.default,
appSettings: appSettings,
analyticsService: .mock(settings: appSettings),
emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(),
timelineControllerFactory: TimelineControllerFactoryMock(.init()))
}
}
@@ -13,17 +13,15 @@ import Testing
@MainActor
struct UserDetailsEditScreenViewModelTests {
private var viewModel: UserDetailsEditScreenViewModel!
private var userIndicatorController: UserIndicatorControllerMock!
private var context: UserDetailsEditScreenViewModelType.Context {
viewModel.context
}
init() {
userIndicatorController = UserIndicatorControllerMock.default
viewModel = .init(userSession: UserSessionMock(.init()),
mediaUploadingPreprocessor: MediaUploadingPreprocessor(appSettings: ServiceLocator.shared.settings),
userIndicatorController: userIndicatorController)
mediaUploadingPreprocessor: MediaUploadingPreprocessor(appSettings: AppSettings()),
userIndicatorController: UserIndicatorControllerMock.default)
}
@Test
@@ -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
@@ -15,7 +15,7 @@ import Testing
struct UserSessionFlowCoordinatorTests {
private var userSessionFlowCoordinator: UserSessionFlowCoordinator!
private var rootCoordinator: NavigationRootCoordinator!
private var userIndicatorController: UserIndicatorControllerMock!
private let userIndicatorController: UserIndicatorControllerMock
private let stateMachineFactory = PublishedStateMachineFactory()
private let networkReachabilitySubject: CurrentValueSubject<NetworkMonitorReachability, Never> = .init(.reachable)
@@ -49,18 +49,19 @@ struct UserSessionFlowCoordinatorTests {
let appMediator = AppMediatorMock.default
appMediator.networkMonitor = networkMonitor
userIndicatorController = UserIndicatorControllerMock()
userIndicatorController = UserIndicatorControllerMock.default
let appSettings = AppSettings()
let flowParameters = CommonFlowParameters(userSession: UserSessionMock(.init(clientProxy: clientProxy)),
bugReportService: BugReportServiceMock(.init()),
elementCallService: ElementCallServiceMock(.init()),
timelineControllerFactory: TimelineControllerFactoryMock(.init()),
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings),
emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(),
appMediator: appMediator,
appSettings: ServiceLocator.shared.settings,
appSettings: appSettings,
appHooks: AppHooks(),
analytics: ServiceLocator.shared.analytics,
analytics: .mock(settings: appSettings),
userIndicatorController: userIndicatorController,
notificationManager: NotificationManagerMock(),
stateMachineFactory: stateMachineFactory)