mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 12:07:55 +00:00
Tidy up mock creation. (#5627)
* Use our standard XYZMock(.init()) pattern everywhere instead of XYZMock.default. * Remove the configuration parameter label on mock convenience inits. * Update the enterprise submodule.
This commit is contained in:
@@ -6,11 +6,17 @@
|
||||
//
|
||||
|
||||
extension AnalyticsServiceMock {
|
||||
static var `default`: AnalyticsServiceMock {
|
||||
let mock = AnalyticsServiceMock()
|
||||
mock.isEnabled = false
|
||||
mock.shouldShowAnalyticsPrompt = false
|
||||
mock.signpost = Signposter()
|
||||
return mock
|
||||
struct Configuration {
|
||||
var isEnabled = false
|
||||
var shouldShowAnalyticsPrompt = false
|
||||
var signpost = Signposter()
|
||||
}
|
||||
|
||||
convenience init(_ configuration: Configuration) {
|
||||
self.init()
|
||||
|
||||
isEnabled = configuration.isEnabled
|
||||
shouldShowAnalyticsPrompt = configuration.shouldShowAnalyticsPrompt
|
||||
signpost = configuration.signpost
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,18 +9,22 @@
|
||||
import UIKit
|
||||
|
||||
extension AppMediatorMock {
|
||||
static var `default`: AppMediatorMock {
|
||||
let mock = AppMediatorMock()
|
||||
struct Configuration {
|
||||
var appState = UIApplication.State.active
|
||||
var isCameraAuthorized = true
|
||||
var networkMonitor = NetworkMonitorMock(.init())
|
||||
}
|
||||
|
||||
convenience init(_ configuration: Configuration) {
|
||||
self.init()
|
||||
|
||||
mock.underlyingAppState = .active
|
||||
mock.requestAuthorizationIfNeededUnderlyingReturnValue = true
|
||||
mock.underlyingNetworkMonitor = NetworkMonitorMock.default
|
||||
underlyingAppState = configuration.appState
|
||||
requestAuthorizationIfNeededUnderlyingReturnValue = configuration.isCameraAuthorized
|
||||
underlyingNetworkMonitor = configuration.networkMonitor
|
||||
|
||||
let windowManagerMock = WindowManagerMock()
|
||||
windowManagerMock.closeAllSecondaryWindowsClosure = { }
|
||||
windowManagerMock.closeSecondaryWindowForTypeClosure = { _ in }
|
||||
mock.underlyingWindowManager = windowManagerMock
|
||||
|
||||
return mock
|
||||
underlyingWindowManager = windowManagerMock
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,37 +13,37 @@ import MatrixRustSDKMocks
|
||||
extension AuthenticationClientFactoryMock {
|
||||
struct Configuration {
|
||||
var homeserverClients = [
|
||||
"matrix.org": ClientSDKMock(configuration: .init()),
|
||||
"https://matrix-client.matrix.org": ClientSDKMock(configuration: .init()),
|
||||
"example.com": ClientSDKMock(configuration: .init(serverAddress: "example.com",
|
||||
homeserverURL: "https://matrix.example.com",
|
||||
slidingSyncVersion: .native,
|
||||
oAuthLoginURL: nil,
|
||||
supportsOAuthCreatePrompt: false,
|
||||
supportsPasswordLogin: true)),
|
||||
"company.com": ClientSDKMock(configuration: .init(serverAddress: "company.com",
|
||||
homeserverURL: "https://matrix.company.com",
|
||||
slidingSyncVersion: .native,
|
||||
oAuthLoginURL: "https://auth.company.com/login",
|
||||
supportsOAuthCreatePrompt: false,
|
||||
supportsPasswordLogin: false)),
|
||||
"server.net": ClientSDKMock(configuration: .init(serverAddress: "server.net",
|
||||
homeserverURL: "https://matrix.server.net",
|
||||
slidingSyncVersion: .native,
|
||||
oAuthLoginURL: nil,
|
||||
supportsOAuthCreatePrompt: false,
|
||||
supportsPasswordLogin: false)),
|
||||
"secure.gov": ClientSDKMock(configuration: .init(serverAddress: "secure.gov",
|
||||
homeserverURL: "https://ess.secure.gov",
|
||||
slidingSyncVersion: .native,
|
||||
oAuthLoginURL: "https://auth.secure.gov/login",
|
||||
supportsOAuthCreatePrompt: false,
|
||||
supportsPasswordLogin: false,
|
||||
elementWellKnown: "{\"version\":1,\"enforce_element_pro\":true}"))
|
||||
"matrix.org": ClientSDKMock(.init()),
|
||||
"https://matrix-client.matrix.org": ClientSDKMock(.init()),
|
||||
"example.com": ClientSDKMock(.init(serverAddress: "example.com",
|
||||
homeserverURL: "https://matrix.example.com",
|
||||
slidingSyncVersion: .native,
|
||||
oAuthLoginURL: nil,
|
||||
supportsOAuthCreatePrompt: false,
|
||||
supportsPasswordLogin: true)),
|
||||
"company.com": ClientSDKMock(.init(serverAddress: "company.com",
|
||||
homeserverURL: "https://matrix.company.com",
|
||||
slidingSyncVersion: .native,
|
||||
oAuthLoginURL: "https://auth.company.com/login",
|
||||
supportsOAuthCreatePrompt: false,
|
||||
supportsPasswordLogin: false)),
|
||||
"server.net": ClientSDKMock(.init(serverAddress: "server.net",
|
||||
homeserverURL: "https://matrix.server.net",
|
||||
slidingSyncVersion: .native,
|
||||
oAuthLoginURL: nil,
|
||||
supportsOAuthCreatePrompt: false,
|
||||
supportsPasswordLogin: false)),
|
||||
"secure.gov": ClientSDKMock(.init(serverAddress: "secure.gov",
|
||||
homeserverURL: "https://ess.secure.gov",
|
||||
slidingSyncVersion: .native,
|
||||
oAuthLoginURL: "https://auth.secure.gov/login",
|
||||
supportsOAuthCreatePrompt: false,
|
||||
supportsPasswordLogin: false,
|
||||
elementWellKnown: "{\"version\":1,\"enforce_element_pro\":true}"))
|
||||
]
|
||||
}
|
||||
|
||||
convenience init(configuration: Configuration) {
|
||||
convenience init(_ configuration: Configuration) {
|
||||
self.init()
|
||||
|
||||
makeClientHomeserverAddressSessionDirectoriesPassphraseClientSessionDelegateAppSettingsAppHooksClosure = { address, _, _, _, _, _ in
|
||||
|
||||
@@ -65,6 +65,6 @@ extension RoomInfoProxyMock {
|
||||
joinRule = .knock
|
||||
historyVisibility = .shared
|
||||
|
||||
powerLevels = RoomPowerLevelsProxyMock(configuration: .init())
|
||||
powerLevels = RoomPowerLevelsProxyMock(.init())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,7 +151,7 @@ extension ClientProxyMock {
|
||||
}
|
||||
}
|
||||
|
||||
userIdentityForFallBackToServerReturnValue = .success(UserIdentityProxyMock(configuration: .init()))
|
||||
userIdentityForFallBackToServerReturnValue = .success(UserIdentityProxyMock(.init()))
|
||||
|
||||
underlyingIsReportRoomSupported = true
|
||||
underlyingIsLiveKitRTCSupported = true
|
||||
|
||||
@@ -70,7 +70,7 @@ extension RoomInfoProxyMock {
|
||||
joinRule = .invite
|
||||
historyVisibility = .shared
|
||||
|
||||
powerLevels = RoomPowerLevelsProxyMock(configuration: .init())
|
||||
powerLevels = RoomPowerLevelsProxyMock(.init())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ struct JoinedRoomProxyMockConfiguration {
|
||||
var predecessor: PredecessorRoom?
|
||||
var successor: SuccessorRoom?
|
||||
|
||||
var powerLevelsConfiguration = RoomPowerLevelsProxyMockConfiguration()
|
||||
var powerLevelsConfiguration = RoomPowerLevelsProxyMock.Configuration()
|
||||
}
|
||||
|
||||
extension JoinedRoomProxyMock {
|
||||
@@ -97,7 +97,7 @@ extension JoinedRoomProxyMock {
|
||||
}
|
||||
updatePowerLevelsForUsersReturnValue = .success(())
|
||||
|
||||
let powerLevelsProxyMock = RoomPowerLevelsProxyMock(configuration: configuration.powerLevelsConfiguration)
|
||||
let powerLevelsProxyMock = RoomPowerLevelsProxyMock(configuration.powerLevelsConfiguration)
|
||||
|
||||
powerLevelsProxyMock.canUserUserIDSendStateEventClosure = { [weak self] userID, _ in
|
||||
.success(self?.membersPublisher.value.first { $0.userID == userID }?.role ?? .user != .user)
|
||||
@@ -196,7 +196,7 @@ extension RoomInfoProxyMock {
|
||||
joinRule = configuration.joinRule
|
||||
historyVisibility = configuration.historyVisibility
|
||||
|
||||
powerLevels = RoomPowerLevelsProxyMock(configuration: configuration.powerLevelsConfiguration)
|
||||
powerLevels = RoomPowerLevelsProxyMock(configuration.powerLevelsConfiguration)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -65,6 +65,6 @@ extension RoomInfoProxyMock {
|
||||
joinRule = .knock
|
||||
historyVisibility = .shared
|
||||
|
||||
powerLevels = RoomPowerLevelsProxyMock(configuration: .init())
|
||||
powerLevels = RoomPowerLevelsProxyMock(.init())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ extension MediaProviderMock {
|
||||
struct Configuration { }
|
||||
|
||||
// swiftlint:disable:next cyclomatic_complexity
|
||||
convenience init(configuration: Configuration) {
|
||||
convenience init(_ configuration: Configuration) {
|
||||
self.init()
|
||||
|
||||
imageFromSourceSizeClosure = { mediaSource, _ in
|
||||
|
||||
@@ -10,9 +10,13 @@ import Combine
|
||||
import Foundation
|
||||
|
||||
extension NetworkMonitorMock {
|
||||
static var `default`: NetworkMonitorMock {
|
||||
let mock = NetworkMonitorMock()
|
||||
mock.underlyingReachabilityPublisher = .init(.init(.reachable))
|
||||
return mock
|
||||
struct Configuration {
|
||||
var reachabilityPublisher = CurrentValuePublisher<NetworkMonitorReachability, Never>(.init(.reachable))
|
||||
}
|
||||
|
||||
convenience init(_ configuration: Configuration) {
|
||||
self.init()
|
||||
|
||||
underlyingReachabilityPublisher = configuration.reachabilityPublisher
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,9 +6,13 @@
|
||||
//
|
||||
|
||||
extension NotificationToneManagerMock {
|
||||
static var `default`: NotificationToneManagerMock {
|
||||
let mock = NotificationToneManagerMock()
|
||||
mock.customTonesReturnValue = []
|
||||
return mock
|
||||
struct Configuration {
|
||||
let customTones: [NotificationTone] = []
|
||||
}
|
||||
|
||||
convenience init(_ configuration: Configuration) {
|
||||
self.init()
|
||||
|
||||
customTonesReturnValue = configuration.customTones
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,12 +9,12 @@
|
||||
import Combine
|
||||
import Foundation
|
||||
|
||||
struct RoomDirectorySearchProxyMockConfiguration {
|
||||
let results: [RoomDirectorySearchResult]
|
||||
}
|
||||
|
||||
extension RoomDirectorySearchProxyMock {
|
||||
convenience init(configuration: RoomDirectorySearchProxyMockConfiguration) {
|
||||
struct Configuration {
|
||||
let results: [RoomDirectorySearchResult]
|
||||
}
|
||||
|
||||
convenience init(_ configuration: Configuration) {
|
||||
self.init()
|
||||
resultsPublisher = CurrentValueSubject(configuration.results).asCurrentValuePublisher()
|
||||
searchQueryReturnValue = .success(())
|
||||
|
||||
@@ -8,22 +8,22 @@
|
||||
|
||||
import MatrixRustSDK
|
||||
|
||||
struct RoomPowerLevelsProxyMockConfiguration {
|
||||
var canUserSendMessage = true
|
||||
var canUserSendState = false
|
||||
var canUserInvite = true
|
||||
var canUserRedactOther = false
|
||||
var canUserRedactOwn = true
|
||||
var canUserKick = false
|
||||
var canUserBan = false
|
||||
var canUserTriggerRoomNotification = false
|
||||
var canUserPin = true
|
||||
var canUserJoinCall = true
|
||||
var canUserEditRoomsAndPermissions = true
|
||||
}
|
||||
|
||||
extension RoomPowerLevelsProxyMock {
|
||||
convenience init(configuration: RoomPowerLevelsProxyMockConfiguration) {
|
||||
struct Configuration {
|
||||
var canUserSendMessage = true
|
||||
var canUserSendState = false
|
||||
var canUserInvite = true
|
||||
var canUserRedactOther = false
|
||||
var canUserRedactOwn = true
|
||||
var canUserKick = false
|
||||
var canUserBan = false
|
||||
var canUserTriggerRoomNotification = false
|
||||
var canUserPin = true
|
||||
var canUserJoinCall = true
|
||||
var canUserEditRoomsAndPermissions = true
|
||||
}
|
||||
|
||||
convenience init(_ configuration: Configuration) {
|
||||
self.init()
|
||||
|
||||
underlyingValues = RoomPowerLevelsValues.mock
|
||||
|
||||
@@ -37,7 +37,7 @@ extension ClientSDKMock {
|
||||
|
||||
enum MockError: Error { case generic }
|
||||
|
||||
convenience init(configuration: Configuration) {
|
||||
convenience init(_ configuration: Configuration) {
|
||||
self.init()
|
||||
|
||||
homeserverLoginDetailsReturnValue = HomeserverLoginDetailsSDKMock(configuration: configuration)
|
||||
|
||||
@@ -11,7 +11,7 @@ extension UserIdentityProxyMock {
|
||||
var verificationState: UserIdentityVerificationState = .notVerified
|
||||
}
|
||||
|
||||
convenience init(configuration: Configuration) {
|
||||
convenience init(_ configuration: Configuration) {
|
||||
self.init()
|
||||
|
||||
underlyingVerificationState = configuration.verificationState
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
//
|
||||
// Copyright 2025 Element Creations Ltd.
|
||||
// Copyright 2023-2025 New Vector Ltd.
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
||||
// Please see LICENSE files in the repository root for full details.
|
||||
//
|
||||
|
||||
import Combine
|
||||
import Foundation
|
||||
|
||||
extension UserIndicatorControllerMock {
|
||||
static var `default`: UserIndicatorControllerMock {
|
||||
let mock = UserIndicatorControllerMock()
|
||||
mock.submitIndicatorDelayClosure = { _, _ in }
|
||||
mock.retractIndicatorWithIdClosure = { _ in }
|
||||
mock.retractAllIndicatorsClosure = { }
|
||||
return mock
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ extension UserSessionMock {
|
||||
self.init()
|
||||
|
||||
clientProxy = configuration.clientProxy
|
||||
mediaProvider = MediaProviderMock(configuration: .init())
|
||||
mediaProvider = MediaProviderMock(.init())
|
||||
voiceMessageMediaManager = VoiceMessageMediaManagerMock()
|
||||
|
||||
sessionSecurityStatePublisher = CurrentValueSubject<SessionSecurityState, Never>(.init(verificationState: .verified, recoveryState: .enabled)).asCurrentValuePublisher()
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
extension UserSessionStoreMock {
|
||||
struct Configuration { }
|
||||
|
||||
convenience init(configuration: Configuration) {
|
||||
convenience init(_ configuration: Configuration) {
|
||||
self.init()
|
||||
|
||||
userSessionForSessionDirectoriesPassphraseReturnValue = .success(UserSessionMock(.init()))
|
||||
|
||||
Reference in New Issue
Block a user