mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
Generating SDK Mocks through the usage of swift run tools generate-sdk-mocks (#982)
* basic implementation, that works for now only with the local SDK * replaced a handmade mock with a generated mock
This commit is contained in:
@@ -25,7 +25,7 @@ class CreateRoomScreenViewModelTests: XCTestCase {
|
||||
var clientProxy: MockClientProxy!
|
||||
var userSession: MockUserSession!
|
||||
|
||||
private let usersSubject = CurrentValueSubject<[UserProfile], Never>([])
|
||||
private let usersSubject = CurrentValueSubject<[UserProfileProxy], Never>([])
|
||||
private var cancellables: Set<AnyCancellable> = []
|
||||
|
||||
var context: CreateRoomViewModel.Context {
|
||||
@@ -59,9 +59,9 @@ class CreateRoomScreenViewModelTests: XCTestCase {
|
||||
func testDeselectUser() {
|
||||
XCTAssertFalse(context.viewState.selectedUsers.isEmpty)
|
||||
XCTAssertEqual(context.viewState.selectedUsers.count, 3)
|
||||
XCTAssertEqual(context.viewState.selectedUsers.first?.userID, UserProfile.mockAlice.userID)
|
||||
XCTAssertEqual(context.viewState.selectedUsers.first?.userID, UserProfileProxy.mockAlice.userID)
|
||||
context.send(viewAction: .deselectUser(.mockAlice))
|
||||
XCTAssertNotEqual(context.viewState.selectedUsers.first?.userID, UserProfile.mockAlice.userID)
|
||||
XCTAssertNotEqual(context.viewState.selectedUsers.first?.userID, UserProfileProxy.mockAlice.userID)
|
||||
}
|
||||
|
||||
func testDefaulSecurity() {
|
||||
|
||||
@@ -36,7 +36,7 @@ class InviteUsersScreenViewModelTests: XCTestCase {
|
||||
XCTAssertTrue(context.viewState.selectedUsers.isEmpty)
|
||||
context.send(viewAction: .toggleUser(.mockAlice))
|
||||
XCTAssertTrue(context.viewState.selectedUsers.count == 1)
|
||||
XCTAssertEqual(context.viewState.selectedUsers.first?.userID, UserProfile.mockAlice.userID)
|
||||
XCTAssertEqual(context.viewState.selectedUsers.first?.userID, UserProfileProxy.mockAlice.userID)
|
||||
}
|
||||
|
||||
func testReselectUser() {
|
||||
@@ -44,7 +44,7 @@ class InviteUsersScreenViewModelTests: XCTestCase {
|
||||
XCTAssertTrue(context.viewState.selectedUsers.isEmpty)
|
||||
context.send(viewAction: .toggleUser(.mockAlice))
|
||||
XCTAssertEqual(context.viewState.selectedUsers.count, 1)
|
||||
XCTAssertEqual(context.viewState.selectedUsers.first?.userID, UserProfile.mockAlice.userID)
|
||||
XCTAssertEqual(context.viewState.selectedUsers.first?.userID, UserProfileProxy.mockAlice.userID)
|
||||
context.send(viewAction: .toggleUser(.mockAlice))
|
||||
XCTAssertTrue(context.viewState.selectedUsers.isEmpty)
|
||||
}
|
||||
@@ -54,7 +54,7 @@ class InviteUsersScreenViewModelTests: XCTestCase {
|
||||
XCTAssertTrue(context.viewState.selectedUsers.isEmpty)
|
||||
context.send(viewAction: .toggleUser(.mockAlice))
|
||||
XCTAssertEqual(context.viewState.selectedUsers.count, 1)
|
||||
XCTAssertEqual(context.viewState.selectedUsers.first?.userID, UserProfile.mockAlice.userID)
|
||||
XCTAssertEqual(context.viewState.selectedUsers.first?.userID, UserProfileProxy.mockAlice.userID)
|
||||
context.send(viewAction: .toggleUser(.mockAlice))
|
||||
XCTAssertTrue(context.viewState.selectedUsers.isEmpty)
|
||||
}
|
||||
@@ -80,7 +80,7 @@ class InviteUsersScreenViewModelTests: XCTestCase {
|
||||
}
|
||||
|
||||
private func setupWithRoomType(roomType: InviteUsersScreenRoomType) {
|
||||
let usersSubject = CurrentValueSubject<[UserProfile], Never>([])
|
||||
let usersSubject = CurrentValueSubject<[UserProfileProxy], Never>([])
|
||||
clientProxy = .init(userID: "")
|
||||
userDiscoveryService = UserDiscoveryServiceMock()
|
||||
userDiscoveryService.fetchSuggestionsReturnValue = .success([])
|
||||
|
||||
@@ -20,7 +20,8 @@ import XCTest
|
||||
|
||||
final class MediaLoaderTests: XCTestCase {
|
||||
func testMediaRequestCoalescing() async {
|
||||
let mediaLoadingClient = MockMediaLoadingClient()
|
||||
let mediaLoadingClient = SDKClientMock()
|
||||
mediaLoadingClient.getMediaContentMediaSourceReturnValue = []
|
||||
let mediaLoader = MediaLoader(client: mediaLoadingClient)
|
||||
|
||||
let mediaSource = MediaSourceProxy(url: URL.documentsDirectory, mimeType: nil)
|
||||
@@ -30,14 +31,15 @@ final class MediaLoaderTests: XCTestCase {
|
||||
_ = try await mediaLoader.loadMediaContentForSource(mediaSource)
|
||||
}
|
||||
|
||||
XCTAssertEqual(mediaLoadingClient.numberOfInvocations, 10)
|
||||
XCTAssertEqual(mediaLoadingClient.getMediaContentMediaSourceCallsCount, 10)
|
||||
} catch {
|
||||
fatalError()
|
||||
}
|
||||
}
|
||||
|
||||
func testMediaThumbnailRequestCoalescing() async {
|
||||
let mediaLoadingClient = MockMediaLoadingClient()
|
||||
let mediaLoadingClient = SDKClientMock()
|
||||
mediaLoadingClient.getMediaThumbnailMediaSourceWidthHeightReturnValue = []
|
||||
let mediaLoader = MediaLoader(client: mediaLoadingClient)
|
||||
|
||||
let mediaSource = MediaSourceProxy(url: URL.documentsDirectory, mimeType: nil)
|
||||
@@ -47,107 +49,9 @@ final class MediaLoaderTests: XCTestCase {
|
||||
_ = try await mediaLoader.loadMediaThumbnailForSource(mediaSource, width: 100, height: 100)
|
||||
}
|
||||
|
||||
XCTAssertEqual(mediaLoadingClient.numberOfInvocations, 10)
|
||||
XCTAssertEqual(mediaLoadingClient.getMediaThumbnailMediaSourceWidthHeightCallsCount, 10)
|
||||
} catch {
|
||||
fatalError()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class MockMediaLoadingClient: ClientProtocol {
|
||||
private(set) var numberOfInvocations = 0
|
||||
|
||||
func getMediaContent(mediaSource: MatrixRustSDK.MediaSource) throws -> [UInt8] {
|
||||
numberOfInvocations += 1
|
||||
return []
|
||||
}
|
||||
|
||||
func getMediaThumbnail(mediaSource: MatrixRustSDK.MediaSource, width: UInt64, height: UInt64) throws -> [UInt8] {
|
||||
numberOfInvocations += 1
|
||||
return []
|
||||
}
|
||||
|
||||
// MARK: - Not implemented
|
||||
|
||||
func setDelegate(delegate: MatrixRustSDK.ClientDelegate?) { }
|
||||
|
||||
func login(username: String, password: String, initialDeviceName: String?, deviceId: String?) throws { }
|
||||
|
||||
func restoreSession(session: MatrixRustSDK.Session) throws { }
|
||||
|
||||
func session() throws -> MatrixRustSDK.Session { fatalError() }
|
||||
|
||||
func userId() throws -> String { fatalError() }
|
||||
|
||||
func displayName() throws -> String { fatalError() }
|
||||
|
||||
func setDisplayName(name: String) throws { }
|
||||
|
||||
func avatarUrl() throws -> String? { fatalError() }
|
||||
|
||||
func cachedAvatarUrl() throws -> String? { fatalError() }
|
||||
|
||||
func deviceId() throws -> String { fatalError() }
|
||||
|
||||
func accountData(eventType: String) throws -> String? { fatalError() }
|
||||
|
||||
func setAccountData(eventType: String, content: String) throws { fatalError() }
|
||||
|
||||
func uploadMedia(mimeType: String, data content: [UInt8]) throws -> String { fatalError() }
|
||||
|
||||
func getMediaFile(mediaSource: MatrixRustSDK.MediaSource, body: String?, mimeType: String) throws -> MatrixRustSDK.MediaFileHandle { fatalError() }
|
||||
|
||||
func getProfile(userId: String) throws -> MatrixRustSDK.UserProfile { fatalError() }
|
||||
|
||||
func getSessionVerificationController() throws -> MatrixRustSDK.SessionVerificationController { fatalError() }
|
||||
|
||||
func fullSlidingSync() throws -> MatrixRustSDK.SlidingSync { fatalError() }
|
||||
|
||||
func logout() throws { }
|
||||
|
||||
func hasFirstSynced() -> Bool { fatalError() }
|
||||
|
||||
func homeserver() -> String { fatalError() }
|
||||
|
||||
func isSoftLogout() -> Bool { fatalError() }
|
||||
|
||||
func isSyncing() -> Bool { fatalError() }
|
||||
|
||||
func rooms() -> [MatrixRustSDK.Room] { fatalError() }
|
||||
|
||||
func slidingSync() -> MatrixRustSDK.SlidingSyncBuilder { fatalError() }
|
||||
|
||||
func startSync(timelineLimit: UInt16?) { }
|
||||
|
||||
func createRoom(request: MatrixRustSDK.CreateRoomParameters) throws -> String { fatalError() }
|
||||
|
||||
func getDmRoom(userId: String) throws -> MatrixRustSDK.Room? {
|
||||
fatalError()
|
||||
}
|
||||
|
||||
func ignoreUser(userId: String) throws {
|
||||
fatalError()
|
||||
}
|
||||
|
||||
func unignoreUser(userId: String) throws {
|
||||
fatalError()
|
||||
}
|
||||
|
||||
// swiftlint:disable:next function_parameter_count
|
||||
func setPusher(identifiers: MatrixRustSDK.PusherIdentifiers,
|
||||
kind: MatrixRustSDK.PusherKind,
|
||||
appDisplayName: String,
|
||||
deviceDisplayName: String,
|
||||
profileTag: String?,
|
||||
lang: String) throws {
|
||||
fatalError()
|
||||
}
|
||||
|
||||
func searchUsers(searchTerm: String, limit: UInt64) throws -> MatrixRustSDK.SearchUsersResults { fatalError() }
|
||||
|
||||
func setNotificationDelegate(notificationDelegate: MatrixRustSDK.NotificationDelegate?) { }
|
||||
|
||||
func getNotificationItem(roomId: String, eventId: String) throws -> MatrixRustSDK.NotificationItem {
|
||||
fatalError()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ class UserDiscoveryServiceTest: XCTestCase {
|
||||
}
|
||||
|
||||
func testQueryShowingResults() async throws {
|
||||
clientProxy.searchUsersResult = .success(.init(results: [UserProfile.mockAlice], limited: true))
|
||||
clientProxy.searchUsersResult = .success(.init(results: [UserProfileProxy.mockAlice], limited: true))
|
||||
|
||||
let results = await (try? search(query: "AAA").get()) ?? []
|
||||
assertSearchResults(results, toBe: 1)
|
||||
@@ -79,17 +79,17 @@ class UserDiscoveryServiceTest: XCTestCase {
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private func assertSearchResults(_ results: [UserProfile], toBe count: Int) {
|
||||
private func assertSearchResults(_ results: [UserProfileProxy], toBe count: Int) {
|
||||
XCTAssertTrue(count >= 0)
|
||||
XCTAssertEqual(results.count, count)
|
||||
XCTAssertEqual(results.isEmpty, count == 0)
|
||||
}
|
||||
|
||||
private func search(query: String) async -> Result<[UserProfile], UserDiscoveryErrorType> {
|
||||
private func search(query: String) async -> Result<[UserProfileProxy], UserDiscoveryErrorType> {
|
||||
await service.searchProfiles(with: query)
|
||||
}
|
||||
|
||||
private var searchResults: [UserProfile] {
|
||||
private var searchResults: [UserProfileProxy] {
|
||||
[
|
||||
.mockAlice,
|
||||
.mockBob,
|
||||
|
||||
Reference in New Issue
Block a user