Removed unused swipe gesture (+3 squashed commits)

Squashed commits:
[d64bb3bb] Stop using the ServiceLocator directly in the ScreenTrackerViewModifier
[37c46ab9] Rename Analytics to AnalyticsService
[8852a371] #920 - Cleanup ServiceLocator usages
This commit is contained in:
Stefan Ceriu
2023-06-23 09:56:22 +03:00
committed by Stefan Ceriu
parent b4cd58b209
commit e6711a0236
104 changed files with 720 additions and 366 deletions
@@ -20,7 +20,6 @@ import XCTest
@MainActor
class AnalyticsSettingsScreenViewModelTests: XCTestCase {
private var appSettings: AppSettings { ServiceLocator.shared.settings }
private var viewModel: AnalyticsSettingsScreenViewModelProtocol!
private var context: AnalyticsSettingsScreenViewModelType.Context!
@@ -28,9 +27,12 @@ class AnalyticsSettingsScreenViewModelTests: XCTestCase {
AppSettings.reset()
let analyticsClient = AnalyticsClientMock()
analyticsClient.isRunning = false
ServiceLocator.shared.register(analytics: Analytics(client: analyticsClient))
ServiceLocator.shared.register(analytics: AnalyticsService(client: analyticsClient,
appSettings: ServiceLocator.shared.settings,
bugReportService: ServiceLocator.shared.bugReportService))
viewModel = AnalyticsSettingsScreenViewModel()
viewModel = AnalyticsSettingsScreenViewModel(appSettings: ServiceLocator.shared.settings,
analytics: ServiceLocator.shared.analytics)
context = viewModel.context
}
@@ -39,13 +41,13 @@ class AnalyticsSettingsScreenViewModelTests: XCTestCase {
}
func testOptIn() {
appSettings.analyticsConsentState = .optedOut
ServiceLocator.shared.settings.analyticsConsentState = .optedOut
context.send(viewAction: .toggleAnalytics)
XCTAssertTrue(context.enableAnalytics)
}
func testOptOut() {
appSettings.analyticsConsentState = .optedIn
ServiceLocator.shared.settings.analyticsConsentState = .optedIn
context.send(viewAction: .toggleAnalytics)
XCTAssertFalse(context.enableAnalytics)
}
+8 -6
View File
@@ -31,7 +31,9 @@ class AnalyticsTests: XCTestCase {
ServiceLocator.shared.register(bugReportService: bugReportService)
analyticsClient = AnalyticsClientMock()
analyticsClient.isRunning = false
ServiceLocator.shared.register(analytics: Analytics(client: analyticsClient))
ServiceLocator.shared.register(analytics: AnalyticsService(client: analyticsClient,
appSettings: ServiceLocator.shared.settings,
bugReportService: ServiceLocator.shared.bugReportService))
}
func testAnalyticsPromptNewUser() {
@@ -70,7 +72,7 @@ class AnalyticsTests: XCTestCase {
XCTAssertEqual(ServiceLocator.shared.settings.analyticsConsentState, .unknown)
XCTAssertFalse(ServiceLocator.shared.analytics.isEnabled)
XCTAssertFalse(ServiceLocator.shared.analytics.isRunning)
XCTAssertFalse(analyticsClient.startCalled)
XCTAssertFalse(analyticsClient.startAnalyticsConfigurationCalled)
XCTAssertFalse(bugReportService.startCalled)
}
@@ -97,7 +99,7 @@ class AnalyticsTests: XCTestCase {
XCTAssertEqual(appSettings.analyticsConsentState, .optedIn)
XCTAssertTrue(ServiceLocator.shared.analytics.isEnabled)
// Analytics client and the bug report service should have been started
XCTAssertTrue(analyticsClient.startCalled)
XCTAssertTrue(analyticsClient.startAnalyticsConfigurationCalled)
XCTAssertTrue(bugReportService.startCalled)
}
@@ -107,7 +109,7 @@ class AnalyticsTests: XCTestCase {
// Analytics should not start
XCTAssertFalse(ServiceLocator.shared.analytics.isEnabled)
ServiceLocator.shared.analytics.startIfEnabled()
XCTAssertFalse(analyticsClient.startCalled)
XCTAssertFalse(analyticsClient.startAnalyticsConfigurationCalled)
XCTAssertFalse(bugReportService.startCalled)
}
@@ -117,7 +119,7 @@ class AnalyticsTests: XCTestCase {
// Analytics should start
XCTAssertTrue(ServiceLocator.shared.analytics.isEnabled)
ServiceLocator.shared.analytics.startIfEnabled()
XCTAssertTrue(analyticsClient.startCalled)
XCTAssertTrue(analyticsClient.startAnalyticsConfigurationCalled)
XCTAssertTrue(bugReportService.startCalled)
}
@@ -172,7 +174,7 @@ class AnalyticsTests: XCTestCase {
numFavouriteRooms: nil,
numSpaces: nil,
allChatsActiveFilter: nil))
client.start()
client.start(analyticsConfiguration: ServiceLocator.shared.settings.analyticsConfiguration)
XCTAssertNotNil(client.pendingUserProperties, "The user properties should be cached.")
XCTAssertEqual(client.pendingUserProperties?.ftueUseCaseSelection, .PersonalMessaging, "The use case selection should match.")
@@ -18,7 +18,7 @@
import XCTest
class AttributedStringBuilderTests: XCTestCase {
let attributedStringBuilder = AttributedStringBuilder()
let attributedStringBuilder = AttributedStringBuilder(permalinkBaseURL: ServiceLocator.shared.settings.permalinkBaseURL)
let maxHeaderPointSize = ceil(UIFont.preferredFont(forTextStyle: .body).pointSize * 1.2)
func testRenderHTMLStringWithHeaders() {
@@ -21,7 +21,8 @@ class AttributedStringTests: XCTestCase {
func testReplacingFontWithPresentationIntent() {
// Given a string parsed from HTML that contains specific fixed size fonts.
let boldString = "Bold"
guard let originalString = AttributedStringBuilder().fromHTML("Normal <b>\(boldString)</b> Normal.") else {
guard let originalString = AttributedStringBuilder(permalinkBaseURL: ServiceLocator.shared.settings.permalinkBaseURL)
.fromHTML("Normal <b>\(boldString)</b> Normal.") else {
XCTFail("The attributed string should be built from the HTML.")
return
}
@@ -50,6 +50,7 @@ class BugReportServiceTests: XCTestCase {
let service = BugReportService(withBaseURL: URL(staticString: "https://www.example.com"),
sentryURL: URL(staticString: "https://1234@sentry.com/1234"),
applicationId: "mock_app_id",
maxUploadSize: ServiceLocator.shared.settings.bugReportMaxUploadSize,
session: .mock)
XCTAssertFalse(service.crashedLastRun)
}
@@ -58,6 +59,7 @@ class BugReportServiceTests: XCTestCase {
let service = BugReportService(withBaseURL: URL(staticString: "https://www.example.com"),
sentryURL: URL(staticString: "https://1234@sentry.com/1234"),
applicationId: "mock_app_id",
maxUploadSize: ServiceLocator.shared.settings.bugReportMaxUploadSize,
session: .mock)
let bugReport = BugReport(userID: "@mock:client.com",
@@ -37,7 +37,11 @@ class CreateRoomScreenViewModelTests: XCTestCase {
userSession = MockUserSession(clientProxy: clientProxy, mediaProvider: MockMediaProvider())
let parameters = CreateRoomFlowParameters()
usersSubject.send([.mockAlice, .mockBob, .mockCharlie])
let viewModel = CreateRoomViewModel(userSession: userSession, userIndicatorController: nil, createRoomParameters: .init(parameters), selectedUsers: usersSubject.asCurrentValuePublisher())
let viewModel = CreateRoomViewModel(userSession: userSession,
createRoomParameters: .init(parameters),
selectedUsers: usersSubject.asCurrentValuePublisher(),
analytics: ServiceLocator.shared.analytics,
userIndicatorController: nil)
self.viewModel = viewModel
viewModel.actions.sink { [weak self] action in
@@ -32,8 +32,10 @@ class HomeScreenViewModelTests: XCTestCase {
clientProxy = MockClientProxy(userID: "@mock:client.com")
viewModel = HomeScreenViewModel(userSession: MockUserSession(clientProxy: clientProxy,
mediaProvider: MockMediaProvider()),
attributedStringBuilder: AttributedStringBuilder(),
selectedRoomPublisher: CurrentValueSubject<String?, Never>(nil).asCurrentValuePublisher())
attributedStringBuilder: AttributedStringBuilder(permalinkBaseURL: ServiceLocator.shared.settings.permalinkBaseURL),
selectedRoomPublisher: CurrentValueSubject<String?, Never>(nil).asCurrentValuePublisher(),
appSettings: ServiceLocator.shared.settings,
userIndicatorController: ServiceLocator.shared.userIndicatorController)
}
func testSelectRoom() async throws {
@@ -89,6 +89,7 @@ class InviteUsersScreenViewModelTests: XCTestCase {
let viewModel = InviteUsersScreenViewModel(selectedUsers: usersSubject.asCurrentValuePublisher(),
roomType: roomType, mediaProvider: MockMediaProvider(),
userDiscoveryService: userDiscoveryService,
appSettings: ServiceLocator.shared.settings,
userIndicatorController: UserIndicatorControllerMock())
viewModel.state.usersSection = .init(type: .suggestions, users: [.mockAlice, .mockBob, .mockCharlie])
self.viewModel = viewModel
@@ -82,6 +82,9 @@ class InvitesScreenViewModelTests: XCTestCase {
clientProxy.roomSummaryProvider = summaryProvider
}
viewModel = InvitesScreenViewModel(userSession: userSession)
viewModel = InvitesScreenViewModel(userSession: userSession,
appSettings: ServiceLocator.shared.settings,
analytics: ServiceLocator.shared.analytics,
userIndicatorController: ServiceLocator.shared.userIndicatorController)
}
}
+1 -1
View File
@@ -25,7 +25,7 @@ class LoginViewModelTests: XCTestCase {
var context: LoginScreenViewModelType.Context!
@MainActor override func setUp() async throws {
viewModel = LoginScreenViewModel(homeserver: defaultHomeserver)
viewModel = LoginScreenViewModel(homeserver: defaultHomeserver, slidingSyncLearnMoreURL: ServiceLocator.shared.settings.slidingSyncLearnMoreURL)
context = viewModel.context
}
@@ -34,7 +34,7 @@ final class NotificationManagerTests: XCTestCase {
override func setUp() {
AppSettings.reset()
notificationManager = NotificationManager(notificationCenter: notificationCenter)
notificationManager = NotificationManager(notificationCenter: notificationCenter, appSettings: appSettings)
notificationManager.start()
notificationManager.setUserSession(mockUserSession)
}
+13 -13
View File
@@ -30,7 +30,7 @@ class PermalinkBuilderTests: XCTestCase {
let userId = "@abcdefghijklmnopqrstuvwxyz1234567890._-=/:matrix.org"
do {
let permalink = try PermalinkBuilder.permalinkTo(userIdentifier: userId)
let permalink = try PermalinkBuilder.permalinkTo(userIdentifier: userId, baseURL: appSettings.permalinkBaseURL)
XCTAssertEqual(permalink, URL(string: "\(appSettings.permalinkBaseURL)/#/\(userId)"))
} catch {
XCTFail("User identifier must be valid: \(error)")
@@ -39,7 +39,7 @@ class PermalinkBuilderTests: XCTestCase {
func testInvalidUserIdentifier() {
do {
_ = try PermalinkBuilder.permalinkTo(userIdentifier: "This1sN0tV4lid!@#$%^&*()")
_ = try PermalinkBuilder.permalinkTo(userIdentifier: "This1sN0tV4lid!@#$%^&*()", baseURL: appSettings.permalinkBaseURL)
XCTFail("A permalink should not be created.")
} catch {
XCTAssertEqual(error as? PermalinkBuilderError, PermalinkBuilderError.invalidUserIdentifier)
@@ -50,7 +50,7 @@ class PermalinkBuilderTests: XCTestCase {
let roomId = "!abcdefghijklmnopqrstuvwxyz1234567890:matrix.org"
do {
let permalink = try PermalinkBuilder.permalinkTo(roomIdentifier: roomId)
let permalink = try PermalinkBuilder.permalinkTo(roomIdentifier: roomId, baseURL: appSettings.permalinkBaseURL)
XCTAssertEqual(permalink, URL(string: "\(appSettings.permalinkBaseURL)/#/!abcdefghijklmnopqrstuvwxyz1234567890%3Amatrix.org"))
} catch {
XCTFail("Room identifier must be valid: \(error)")
@@ -59,7 +59,7 @@ class PermalinkBuilderTests: XCTestCase {
func testInvalidRoomIdentifier() {
do {
_ = try PermalinkBuilder.permalinkTo(roomIdentifier: "This1sN0tV4lid!@#$%^&*()")
_ = try PermalinkBuilder.permalinkTo(roomIdentifier: "This1sN0tV4lid!@#$%^&*()", baseURL: appSettings.permalinkBaseURL)
XCTFail("A permalink should not be created.")
} catch {
XCTAssertEqual(error as? PermalinkBuilderError, PermalinkBuilderError.invalidRoomIdentifier)
@@ -70,7 +70,7 @@ class PermalinkBuilderTests: XCTestCase {
let roomAlias = "#abcdefghijklmnopqrstuvwxyz-_.1234567890:matrix.org"
do {
let permalink = try PermalinkBuilder.permalinkTo(roomAlias: roomAlias)
let permalink = try PermalinkBuilder.permalinkTo(roomAlias: roomAlias, baseURL: appSettings.permalinkBaseURL)
XCTAssertEqual(permalink, URL(string: "\(appSettings.permalinkBaseURL)/#/%23abcdefghijklmnopqrstuvwxyz-_.1234567890%3Amatrix.org"))
} catch {
XCTFail("Room alias must be valid: \(error)")
@@ -79,7 +79,7 @@ class PermalinkBuilderTests: XCTestCase {
func testInvalidRoomAlias() {
do {
_ = try PermalinkBuilder.permalinkTo(roomAlias: "This1sN0tV4lid!@#$%^&*()")
_ = try PermalinkBuilder.permalinkTo(roomAlias: "This1sN0tV4lid!@#$%^&*()", baseURL: appSettings.permalinkBaseURL)
XCTFail("A permalink should not be created.")
} catch {
XCTAssertEqual(error as? PermalinkBuilderError, PermalinkBuilderError.invalidRoomAlias)
@@ -91,7 +91,7 @@ class PermalinkBuilderTests: XCTestCase {
let roomId = "!abcdefghijklmnopqrstuvwxyz1234567890:matrix.org"
do {
let permalink = try PermalinkBuilder.permalinkTo(eventIdentifier: eventId, roomIdentifier: roomId)
let permalink = try PermalinkBuilder.permalinkTo(eventIdentifier: eventId, roomIdentifier: roomId, baseURL: appSettings.permalinkBaseURL)
XCTAssertEqual(permalink, URL(string: "\(appSettings.permalinkBaseURL)/#/!abcdefghijklmnopqrstuvwxyz1234567890%3Amatrix.org/%24abcdefghijklmnopqrstuvwxyz1234567890"))
} catch {
XCTFail("Room and event identifiers must be valid: \(error)")
@@ -100,7 +100,7 @@ class PermalinkBuilderTests: XCTestCase {
func testInvalidEventIdentifier() {
do {
_ = try PermalinkBuilder.permalinkTo(eventIdentifier: "This1sN0tV4lid!@#$%^&*()", roomIdentifier: "")
_ = try PermalinkBuilder.permalinkTo(eventIdentifier: "This1sN0tV4lid!@#$%^&*()", roomIdentifier: "", baseURL: appSettings.permalinkBaseURL)
XCTFail("A permalink should not be created.")
} catch {
XCTAssertEqual(error as? PermalinkBuilderError, PermalinkBuilderError.invalidEventIdentifier)
@@ -109,18 +109,18 @@ class PermalinkBuilderTests: XCTestCase {
func testPermalinkDetection() {
var url = URL(staticString: "https://www.matrix.org")
XCTAssertEqual(PermalinkBuilder.detectPermalink(in: url), nil)
XCTAssertEqual(PermalinkBuilder.detectPermalink(in: url, baseURL: appSettings.permalinkBaseURL), nil)
url = URL(staticString: "https://matrix.to/#/@bob:matrix.org?via=matrix.org")
XCTAssertEqual(PermalinkBuilder.detectPermalink(in: url), PermalinkType.userIdentifier("@bob:matrix.org"))
XCTAssertEqual(PermalinkBuilder.detectPermalink(in: url, baseURL: appSettings.permalinkBaseURL), PermalinkType.userIdentifier("@bob:matrix.org"))
url = URL(staticString: "https://matrix.to/#/!roomidentifier:matrix.org?via=matrix.org")
XCTAssertEqual(PermalinkBuilder.detectPermalink(in: url), PermalinkType.roomIdentifier("!roomidentifier:matrix.org"))
XCTAssertEqual(PermalinkBuilder.detectPermalink(in: url, baseURL: appSettings.permalinkBaseURL), PermalinkType.roomIdentifier("!roomidentifier:matrix.org"))
url = URL(staticString: "https://matrix.to/#/%23roomalias:matrix.org?via=matrix.org")
XCTAssertEqual(PermalinkBuilder.detectPermalink(in: url), PermalinkType.roomAlias("#roomalias:matrix.org"))
XCTAssertEqual(PermalinkBuilder.detectPermalink(in: url, baseURL: appSettings.permalinkBaseURL), PermalinkType.roomAlias("#roomalias:matrix.org"))
url = URL(staticString: "https://matrix.to/#/!roomidentifier:matrix.org/$eventidentifier?via=matrix.org")
XCTAssertEqual(PermalinkBuilder.detectPermalink(in: url), PermalinkType.event(roomIdentifier: "!roomidentifier:matrix.org", eventIdentifier: "$eventidentifier"))
XCTAssertEqual(PermalinkBuilder.detectPermalink(in: url, baseURL: appSettings.permalinkBaseURL), PermalinkType.event(roomIdentifier: "!roomidentifier:matrix.org", eventIdentifier: "$eventidentifier"))
}
}
@@ -27,7 +27,10 @@ class RoomDetailsScreenViewModelTests: XCTestCase {
override func setUp() {
roomProxyMock = RoomProxyMock(with: .init(displayName: "Test", joinedMembersCount: 0))
viewModel = RoomDetailsScreenViewModel(accountUserID: "@owner:somewhere.com", roomProxy: roomProxyMock, mediaProvider: MockMediaProvider())
viewModel = RoomDetailsScreenViewModel(accountUserID: "@owner:somewhere.com",
roomProxy: roomProxyMock,
mediaProvider: MockMediaProvider(),
userIndicatorController: ServiceLocator.shared.userIndicatorController)
AppSettings.reset()
}
@@ -35,7 +38,10 @@ class RoomDetailsScreenViewModelTests: XCTestCase {
func testLeaveRoomTappedWhenPublic() async {
let mockedMembers: [RoomMemberProxyMock] = [.mockBob, .mockAlice]
roomProxyMock = RoomProxyMock(with: .init(displayName: "Test", isPublic: true, members: mockedMembers))
viewModel = RoomDetailsScreenViewModel(accountUserID: "@owner:somewhere.com", roomProxy: roomProxyMock, mediaProvider: MockMediaProvider())
viewModel = RoomDetailsScreenViewModel(accountUserID: "@owner:somewhere.com",
roomProxy: roomProxyMock,
mediaProvider: MockMediaProvider(),
userIndicatorController: ServiceLocator.shared.userIndicatorController)
await context.nextViewState()
context.send(viewAction: .processTapLeave)
XCTAssertEqual(context.leaveRoomAlertItem?.state, .public)
@@ -45,7 +51,10 @@ class RoomDetailsScreenViewModelTests: XCTestCase {
func testLeaveRoomTappedWhenRoomNotPublic() async {
let mockedMembers: [RoomMemberProxyMock] = [.mockBob, .mockAlice]
roomProxyMock = RoomProxyMock(with: .init(displayName: "Test", isPublic: false, members: mockedMembers))
viewModel = RoomDetailsScreenViewModel(accountUserID: "@owner:somewhere.com", roomProxy: roomProxyMock, mediaProvider: MockMediaProvider())
viewModel = RoomDetailsScreenViewModel(accountUserID: "@owner:somewhere.com",
roomProxy: roomProxyMock,
mediaProvider: MockMediaProvider(),
userIndicatorController: ServiceLocator.shared.userIndicatorController)
await context.nextViewState()
context.send(viewAction: .processTapLeave)
XCTAssertEqual(context.leaveRoomAlertItem?.state, .private)
@@ -89,7 +98,10 @@ class RoomDetailsScreenViewModelTests: XCTestCase {
let recipient = RoomMemberProxyMock.mockDan
let mockedMembers: [RoomMemberProxyMock] = [.mockMe, recipient]
roomProxyMock = RoomProxyMock(with: .init(displayName: "Test", isDirect: true, isEncrypted: true, members: mockedMembers, activeMembersCount: mockedMembers.count))
viewModel = RoomDetailsScreenViewModel(accountUserID: "@owner:somewhere.com", roomProxy: roomProxyMock, mediaProvider: MockMediaProvider())
viewModel = RoomDetailsScreenViewModel(accountUserID: "@owner:somewhere.com",
roomProxy: roomProxyMock,
mediaProvider: MockMediaProvider(),
userIndicatorController: ServiceLocator.shared.userIndicatorController)
await context.nextViewState()
XCTAssertEqual(context.viewState.dmRecipient, RoomMemberDetails(withProxy: recipient))
}
@@ -102,7 +114,10 @@ class RoomDetailsScreenViewModelTests: XCTestCase {
}
let mockedMembers: [RoomMemberProxyMock] = [.mockMe, recipient]
roomProxyMock = RoomProxyMock(with: .init(displayName: "Test", isDirect: true, isEncrypted: true, members: mockedMembers, activeMembersCount: mockedMembers.count))
viewModel = RoomDetailsScreenViewModel(accountUserID: "@owner:somewhere.com", roomProxy: roomProxyMock, mediaProvider: MockMediaProvider())
viewModel = RoomDetailsScreenViewModel(accountUserID: "@owner:somewhere.com",
roomProxy: roomProxyMock,
mediaProvider: MockMediaProvider(),
userIndicatorController: ServiceLocator.shared.userIndicatorController)
await context.nextViewState()
XCTAssertEqual(context.viewState.dmRecipient, RoomMemberDetails(withProxy: recipient))
@@ -124,7 +139,10 @@ class RoomDetailsScreenViewModelTests: XCTestCase {
}
let mockedMembers: [RoomMemberProxyMock] = [.mockMe, recipient]
roomProxyMock = RoomProxyMock(with: .init(displayName: "Test", isDirect: true, isEncrypted: true, members: mockedMembers, activeMembersCount: mockedMembers.count))
viewModel = RoomDetailsScreenViewModel(accountUserID: "@owner:somewhere.com", roomProxy: roomProxyMock, mediaProvider: MockMediaProvider())
viewModel = RoomDetailsScreenViewModel(accountUserID: "@owner:somewhere.com",
roomProxy: roomProxyMock,
mediaProvider: MockMediaProvider(),
userIndicatorController: ServiceLocator.shared.userIndicatorController)
await context.nextViewState()
XCTAssertEqual(context.viewState.dmRecipient, RoomMemberDetails(withProxy: recipient))
@@ -147,7 +165,10 @@ class RoomDetailsScreenViewModelTests: XCTestCase {
}
let mockedMembers: [RoomMemberProxyMock] = [.mockMe, recipient]
roomProxyMock = RoomProxyMock(with: .init(displayName: "Test", isDirect: true, isEncrypted: true, members: mockedMembers, activeMembersCount: mockedMembers.count))
viewModel = RoomDetailsScreenViewModel(accountUserID: "@owner:somewhere.com", roomProxy: roomProxyMock, mediaProvider: MockMediaProvider())
viewModel = RoomDetailsScreenViewModel(accountUserID: "@owner:somewhere.com",
roomProxy: roomProxyMock,
mediaProvider: MockMediaProvider(),
userIndicatorController: ServiceLocator.shared.userIndicatorController)
await context.nextViewState()
XCTAssertEqual(context.viewState.dmRecipient, RoomMemberDetails(withProxy: recipient))
@@ -169,7 +190,10 @@ class RoomDetailsScreenViewModelTests: XCTestCase {
}
let mockedMembers: [RoomMemberProxyMock] = [.mockMe, recipient]
roomProxyMock = RoomProxyMock(with: .init(displayName: "Test", isDirect: true, isEncrypted: true, members: mockedMembers, activeMembersCount: mockedMembers.count))
viewModel = RoomDetailsScreenViewModel(accountUserID: "@owner:somewhere.com", roomProxy: roomProxyMock, mediaProvider: MockMediaProvider())
viewModel = RoomDetailsScreenViewModel(accountUserID: "@owner:somewhere.com",
roomProxy: roomProxyMock,
mediaProvider: MockMediaProvider(),
userIndicatorController: ServiceLocator.shared.userIndicatorController)
await context.nextViewState()
XCTAssertEqual(context.viewState.dmRecipient, RoomMemberDetails(withProxy: recipient))
@@ -191,7 +215,10 @@ class RoomDetailsScreenViewModelTests: XCTestCase {
members: mockedMembers,
memberForID: .mockOwner(allowedStateEvents: [], canInviteUsers: false),
activeMembersCount: mockedMembers.count))
viewModel = RoomDetailsScreenViewModel(accountUserID: "@owner:somewhere.com", roomProxy: roomProxyMock, mediaProvider: MockMediaProvider())
viewModel = RoomDetailsScreenViewModel(accountUserID: "@owner:somewhere.com",
roomProxy: roomProxyMock,
mediaProvider: MockMediaProvider(),
userIndicatorController: ServiceLocator.shared.userIndicatorController)
_ = await context.$viewState.debounce(for: .milliseconds(100), scheduler: DispatchQueue.main).values.first()
@@ -201,7 +228,10 @@ class RoomDetailsScreenViewModelTests: XCTestCase {
func testInvitePeople() async {
let mockedMembers: [RoomMemberProxyMock] = [.mockMe, .mockBob, .mockAlice]
roomProxyMock = RoomProxyMock(with: .init(displayName: "Test", isPublic: true, members: mockedMembers, activeMembersCount: mockedMembers.count))
viewModel = RoomDetailsScreenViewModel(accountUserID: "@owner:somewhere.com", roomProxy: roomProxyMock, mediaProvider: MockMediaProvider())
viewModel = RoomDetailsScreenViewModel(accountUserID: "@owner:somewhere.com",
roomProxy: roomProxyMock,
mediaProvider: MockMediaProvider(),
userIndicatorController: ServiceLocator.shared.userIndicatorController)
_ = await context.$viewState.debounce(for: .milliseconds(100), scheduler: DispatchQueue.main).values.first()
@@ -226,7 +256,10 @@ class RoomDetailsScreenViewModelTests: XCTestCase {
let owner: RoomMemberProxyMock = .mockOwner(allowedStateEvents: [.roomAvatar])
let mockedMembers: [RoomMemberProxyMock] = [owner, .mockBob, .mockAlice]
roomProxyMock = RoomProxyMock(with: .init(displayName: "Test", isDirect: false, isPublic: false, members: mockedMembers, memberForID: owner))
viewModel = RoomDetailsScreenViewModel(accountUserID: "@owner:somewhere.com", roomProxy: roomProxyMock, mediaProvider: MockMediaProvider())
viewModel = RoomDetailsScreenViewModel(accountUserID: "@owner:somewhere.com",
roomProxy: roomProxyMock,
mediaProvider: MockMediaProvider(),
userIndicatorController: ServiceLocator.shared.userIndicatorController)
_ = await context.$viewState.debounce(for: .milliseconds(100), scheduler: DispatchQueue.main).values.first()
@@ -240,7 +273,10 @@ class RoomDetailsScreenViewModelTests: XCTestCase {
let owner: RoomMemberProxyMock = .mockOwner(allowedStateEvents: [.roomName])
let mockedMembers: [RoomMemberProxyMock] = [owner, .mockBob, .mockAlice]
roomProxyMock = RoomProxyMock(with: .init(displayName: "Test", isDirect: false, isPublic: false, members: mockedMembers, memberForID: owner))
viewModel = RoomDetailsScreenViewModel(accountUserID: "@owner:somewhere.com", roomProxy: roomProxyMock, mediaProvider: MockMediaProvider())
viewModel = RoomDetailsScreenViewModel(accountUserID: "@owner:somewhere.com",
roomProxy: roomProxyMock,
mediaProvider: MockMediaProvider(),
userIndicatorController: ServiceLocator.shared.userIndicatorController)
_ = await context.$viewState.debounce(for: .milliseconds(100), scheduler: DispatchQueue.main).values.first()
@@ -254,7 +290,10 @@ class RoomDetailsScreenViewModelTests: XCTestCase {
let owner: RoomMemberProxyMock = .mockOwner(allowedStateEvents: [.roomTopic])
let mockedMembers: [RoomMemberProxyMock] = [owner, .mockBob, .mockAlice]
roomProxyMock = RoomProxyMock(with: .init(displayName: "Test", isDirect: false, isPublic: false, members: mockedMembers, memberForID: owner))
viewModel = RoomDetailsScreenViewModel(accountUserID: "@owner:somewhere.com", roomProxy: roomProxyMock, mediaProvider: MockMediaProvider())
viewModel = RoomDetailsScreenViewModel(accountUserID: "@owner:somewhere.com",
roomProxy: roomProxyMock,
mediaProvider: MockMediaProvider(),
userIndicatorController: ServiceLocator.shared.userIndicatorController)
_ = await context.$viewState.debounce(for: .milliseconds(100), scheduler: DispatchQueue.main).values.first()
@@ -268,7 +307,10 @@ class RoomDetailsScreenViewModelTests: XCTestCase {
let owner: RoomMemberProxyMock = .mockOwner(allowedStateEvents: [])
let mockedMembers: [RoomMemberProxyMock] = [owner, .mockBob, .mockAlice]
roomProxyMock = RoomProxyMock(with: .init(displayName: "Test", isDirect: false, isPublic: false, members: mockedMembers, memberForID: owner))
viewModel = RoomDetailsScreenViewModel(accountUserID: "@owner:somewhere.com", roomProxy: roomProxyMock, mediaProvider: MockMediaProvider())
viewModel = RoomDetailsScreenViewModel(accountUserID: "@owner:somewhere.com",
roomProxy: roomProxyMock,
mediaProvider: MockMediaProvider(),
userIndicatorController: ServiceLocator.shared.userIndicatorController)
_ = await context.$viewState.debounce(for: .milliseconds(100), scheduler: DispatchQueue.main).values.first()
@@ -281,7 +323,10 @@ class RoomDetailsScreenViewModelTests: XCTestCase {
func testCannotEditDirectRoom() async {
let mockedMembers: [RoomMemberProxyMock] = [.mockOwner(allowedStateEvents: [.roomAvatar, .roomName, .roomTopic]), .mockBob, .mockAlice]
roomProxyMock = RoomProxyMock(with: .init(displayName: "Test", isDirect: true, isPublic: false, members: mockedMembers))
viewModel = RoomDetailsScreenViewModel(accountUserID: "@owner:somewhere.com", roomProxy: roomProxyMock, mediaProvider: MockMediaProvider())
viewModel = RoomDetailsScreenViewModel(accountUserID: "@owner:somewhere.com",
roomProxy: roomProxyMock,
mediaProvider: MockMediaProvider(),
userIndicatorController: ServiceLocator.shared.userIndicatorController)
_ = await context.$viewState.debounce(for: .milliseconds(100), scheduler: DispatchQueue.main).values.first()
@@ -39,6 +39,8 @@ class RoomFlowCoordinatorTests: XCTestCase {
navigationStackCoordinator: navigationStackCoordinator,
navigationSplitCoordinator: navigationSplitCoordinator,
emojiProvider: EmojiProvider(),
appSettings: ServiceLocator.shared.settings,
analytics: ServiceLocator.shared.analytics,
userIndicatorController: ServiceLocator.shared.userIndicatorController)
}
@@ -76,6 +76,7 @@ class RoomMembersListScreenViewModelTests: XCTestCase {
private func setup(with members: [RoomMemberProxyMock]) {
viewModel = .init(roomProxy: RoomProxyMock(with: .init(displayName: "test", members: members, joinedMembersCount: members.filter { $0.membership == .join }.count)),
mediaProvider: MockMediaProvider())
mediaProvider: MockMediaProvider(),
userIndicatorController: ServiceLocator.shared.userIndicatorController)
}
}
@@ -45,7 +45,10 @@ class RoomScreenViewModelTests: XCTestCase {
timelineController.timelineItems = items
let viewModel = RoomScreenViewModel(timelineController: timelineController,
mediaProvider: MockMediaProvider(),
roomProxy: RoomProxyMock(with: .init(displayName: "")))
roomProxy: RoomProxyMock(with: .init(displayName: "")),
appSettings: ServiceLocator.shared.settings,
analytics: ServiceLocator.shared.analytics,
userIndicatorController: userIndicatorControllerMock)
// Then the messages should be grouped together.
XCTAssertEqual(viewModel.state.items[0].timelineGroupStyle, .first, "Nothing should prevent the first message from being grouped.")
@@ -75,7 +78,10 @@ class RoomScreenViewModelTests: XCTestCase {
timelineController.timelineItems = items
let viewModel = RoomScreenViewModel(timelineController: timelineController,
mediaProvider: MockMediaProvider(),
roomProxy: RoomProxyMock(with: .init(displayName: "")))
roomProxy: RoomProxyMock(with: .init(displayName: "")),
appSettings: ServiceLocator.shared.settings,
analytics: ServiceLocator.shared.analytics,
userIndicatorController: userIndicatorControllerMock)
// Then the messages should be grouped by sender.
XCTAssertEqual(viewModel.state.items[0].timelineGroupStyle, .single, "A message should not be grouped when the sender changes.")
@@ -103,7 +109,10 @@ class RoomScreenViewModelTests: XCTestCase {
timelineController.timelineItems = items
let viewModel = RoomScreenViewModel(timelineController: timelineController,
mediaProvider: MockMediaProvider(),
roomProxy: RoomProxyMock(with: .init(displayName: "")))
roomProxy: RoomProxyMock(with: .init(displayName: "")),
appSettings: ServiceLocator.shared.settings,
analytics: ServiceLocator.shared.analytics,
userIndicatorController: userIndicatorControllerMock)
// Then the first message should not be grouped but the other two should.
XCTAssertEqual(viewModel.state.items[0].timelineGroupStyle, .single, "When the first message has reactions it should not be grouped.")
@@ -128,7 +137,10 @@ class RoomScreenViewModelTests: XCTestCase {
timelineController.timelineItems = items
let viewModel = RoomScreenViewModel(timelineController: timelineController,
mediaProvider: MockMediaProvider(),
roomProxy: RoomProxyMock(with: .init(displayName: "")))
roomProxy: RoomProxyMock(with: .init(displayName: "")),
appSettings: ServiceLocator.shared.settings,
analytics: ServiceLocator.shared.analytics,
userIndicatorController: userIndicatorControllerMock)
// Then the first and second messages should be grouped and the last one should not.
XCTAssertEqual(viewModel.state.items[0].timelineGroupStyle, .first, "Nothing should prevent the first message from being grouped.")
@@ -153,7 +165,10 @@ class RoomScreenViewModelTests: XCTestCase {
timelineController.timelineItems = items
let viewModel = RoomScreenViewModel(timelineController: timelineController,
mediaProvider: MockMediaProvider(),
roomProxy: RoomProxyMock(with: .init(displayName: "")))
roomProxy: RoomProxyMock(with: .init(displayName: "")),
appSettings: ServiceLocator.shared.settings,
analytics: ServiceLocator.shared.analytics,
userIndicatorController: userIndicatorControllerMock)
// Then the messages should be grouped together.
XCTAssertEqual(viewModel.state.items[0].timelineGroupStyle, .first, "Nothing should prevent the first message from being grouped.")
@@ -172,6 +187,8 @@ class RoomScreenViewModelTests: XCTestCase {
let viewModel = RoomScreenViewModel(timelineController: timelineController,
mediaProvider: MockMediaProvider(),
roomProxy: roomProxyMock,
appSettings: ServiceLocator.shared.settings,
analytics: ServiceLocator.shared.analytics,
userIndicatorController: userIndicatorControllerMock)
viewModel.callback = { action in
switch action {
@@ -204,7 +221,10 @@ class RoomScreenViewModelTests: XCTestCase {
let viewModel = RoomScreenViewModel(timelineController: timelineController,
mediaProvider: MockMediaProvider(),
roomProxy: roomProxyMock,
appSettings: ServiceLocator.shared.settings,
analytics: ServiceLocator.shared.analytics,
userIndicatorController: userIndicatorControllerMock)
viewModel.callback = { action in
switch action {
case .displayRoomMemberDetails(let member):
@@ -236,6 +256,8 @@ class RoomScreenViewModelTests: XCTestCase {
let viewModel = RoomScreenViewModel(timelineController: timelineController,
mediaProvider: MockMediaProvider(),
roomProxy: roomProxyMock,
appSettings: ServiceLocator.shared.settings,
analytics: ServiceLocator.shared.analytics,
userIndicatorController: userIndicatorControllerMock)
viewModel.callback = { _ in
XCTFail("Should not receive any action")
@@ -256,7 +278,10 @@ class RoomScreenViewModelTests: XCTestCase {
let viewModel = RoomScreenViewModel(timelineController: timelineController,
mediaProvider: MockMediaProvider(),
roomProxy: roomProxyMock)
roomProxy: roomProxyMock,
appSettings: ServiceLocator.shared.settings,
analytics: ServiceLocator.shared.analytics,
userIndicatorController: userIndicatorControllerMock)
// Test
viewModel.context.send(viewAction: .retrySend(transactionID: "test retry send id"))
@@ -272,7 +297,10 @@ class RoomScreenViewModelTests: XCTestCase {
let viewModel = RoomScreenViewModel(timelineController: timelineController,
mediaProvider: MockMediaProvider(),
roomProxy: roomProxyMock)
roomProxy: roomProxyMock,
appSettings: ServiceLocator.shared.settings,
analytics: ServiceLocator.shared.analytics,
userIndicatorController: userIndicatorControllerMock)
// Test
viewModel.context.send(viewAction: .retrySend(transactionID: nil))
@@ -287,7 +315,10 @@ class RoomScreenViewModelTests: XCTestCase {
let viewModel = RoomScreenViewModel(timelineController: timelineController,
mediaProvider: MockMediaProvider(),
roomProxy: roomProxyMock)
roomProxy: roomProxyMock,
appSettings: ServiceLocator.shared.settings,
analytics: ServiceLocator.shared.analytics,
userIndicatorController: userIndicatorControllerMock)
// Test
viewModel.context.send(viewAction: .cancelSend(transactionID: "test cancel send id"))
@@ -303,7 +334,10 @@ class RoomScreenViewModelTests: XCTestCase {
let viewModel = RoomScreenViewModel(timelineController: timelineController,
mediaProvider: MockMediaProvider(),
roomProxy: roomProxyMock)
roomProxy: roomProxyMock,
appSettings: ServiceLocator.shared.settings,
analytics: ServiceLocator.shared.analytics,
userIndicatorController: userIndicatorControllerMock)
// Test
viewModel.context.send(viewAction: .cancelSend(transactionID: nil))
@@ -28,7 +28,9 @@ class ServerSelectionViewModelTests: XCTestCase {
var context: ServerSelectionScreenViewModelType.Context!
@MainActor override func setUp() {
viewModel = ServerSelectionScreenViewModel(homeserverAddress: "", isModallyPresented: true)
viewModel = ServerSelectionScreenViewModel(homeserverAddress: "",
slidingSyncLearnMoreURL: ServiceLocator.shared.settings.slidingSyncLearnMoreURL,
isModallyPresented: true)
context = viewModel.context
}
@@ -26,7 +26,7 @@ class SettingsScreenViewModelTests: XCTestCase {
@MainActor override func setUpWithError() throws {
let userSession = MockUserSession(clientProxy: MockClientProxy(userID: ""),
mediaProvider: MockMediaProvider())
viewModel = SettingsScreenViewModel(withUserSession: userSession)
viewModel = SettingsScreenViewModel(userSession: userSession, appSettings: ServiceLocator.shared.settings)
context = viewModel.context
}
@@ -34,7 +34,11 @@ class StartChatScreenViewModelTests: XCTestCase {
userDiscoveryService.fetchSuggestionsReturnValue = .success([])
userDiscoveryService.searchProfilesWithReturnValue = .success([])
let userSession = MockUserSession(clientProxy: clientProxy, mediaProvider: MockMediaProvider())
viewModel = StartChatScreenViewModel(userSession: userSession, userIndicatorController: nil, userDiscoveryService: userDiscoveryService)
viewModel = StartChatScreenViewModel(userSession: userSession,
appSettings: ServiceLocator.shared.settings,
analytics: ServiceLocator.shared.analytics,
userIndicatorController: nil,
userDiscoveryService: userDiscoveryService)
AppSettings.reset()
ServiceLocator.shared.settings.userSuggestionsEnabled = true