Skip to content

Commit ad767d1

Browse files
committed
implemented mocking for NSE
1 parent a841316 commit ad767d1

File tree

12 files changed

+520
-28
lines changed

12 files changed

+520
-28
lines changed

ElementX.xcodeproj/project.pbxproj

Lines changed: 74 additions & 20 deletions
Large diffs are not rendered by default.
Lines changed: 252 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,252 @@
1+
// Generated using Sourcery 2.3.0 — https://github.com/krzysztofzablocki/Sourcery
2+
// DO NOT EDIT
3+
4+
// swiftlint:disable all
5+
@preconcurrency import Combine
6+
@preconcurrency import SwiftUI
7+
8+
@preconcurrency import MatrixRustSDK
9+
10+
import AnalyticsEvents
11+
import AVFoundation
12+
import CallKit
13+
import Foundation
14+
import LocalAuthentication
15+
import Photos
16+
17+
class NSEUserSessionMock: NSEUserSessionProtocol, @unchecked Sendable {
18+
var inviteAvatarsVisibilityCallsCount = 0
19+
var inviteAvatarsVisibilityCalled: Bool {
20+
return inviteAvatarsVisibilityCallsCount > 0
21+
}
22+
23+
var inviteAvatarsVisibility: InviteAvatars {
24+
get async {
25+
inviteAvatarsVisibilityCallsCount += 1
26+
if let inviteAvatarsVisibilityClosure = inviteAvatarsVisibilityClosure {
27+
return await inviteAvatarsVisibilityClosure()
28+
} else {
29+
return underlyingInviteAvatarsVisibility
30+
}
31+
}
32+
}
33+
var underlyingInviteAvatarsVisibility: InviteAvatars!
34+
var inviteAvatarsVisibilityClosure: (() async -> InviteAvatars)?
35+
var mediaPreviewVisibilityCallsCount = 0
36+
var mediaPreviewVisibilityCalled: Bool {
37+
return mediaPreviewVisibilityCallsCount > 0
38+
}
39+
40+
var mediaPreviewVisibility: MediaPreviews {
41+
get async {
42+
mediaPreviewVisibilityCallsCount += 1
43+
if let mediaPreviewVisibilityClosure = mediaPreviewVisibilityClosure {
44+
return await mediaPreviewVisibilityClosure()
45+
} else {
46+
return underlyingMediaPreviewVisibility
47+
}
48+
}
49+
}
50+
var underlyingMediaPreviewVisibility: MediaPreviews!
51+
var mediaPreviewVisibilityClosure: (() async -> MediaPreviews)?
52+
var threadsEnabled: Bool {
53+
get { return underlyingThreadsEnabled }
54+
set(value) { underlyingThreadsEnabled = value }
55+
}
56+
var underlyingThreadsEnabled: Bool!
57+
58+
//MARK: - notificationItemProxy
59+
60+
var notificationItemProxyRoomIDEventIDUnderlyingCallsCount = 0
61+
var notificationItemProxyRoomIDEventIDCallsCount: Int {
62+
get {
63+
if Thread.isMainThread {
64+
return notificationItemProxyRoomIDEventIDUnderlyingCallsCount
65+
} else {
66+
var returnValue: Int? = nil
67+
DispatchQueue.main.sync {
68+
returnValue = notificationItemProxyRoomIDEventIDUnderlyingCallsCount
69+
}
70+
71+
return returnValue!
72+
}
73+
}
74+
set {
75+
if Thread.isMainThread {
76+
notificationItemProxyRoomIDEventIDUnderlyingCallsCount = newValue
77+
} else {
78+
DispatchQueue.main.sync {
79+
notificationItemProxyRoomIDEventIDUnderlyingCallsCount = newValue
80+
}
81+
}
82+
}
83+
}
84+
var notificationItemProxyRoomIDEventIDCalled: Bool {
85+
return notificationItemProxyRoomIDEventIDCallsCount > 0
86+
}
87+
var notificationItemProxyRoomIDEventIDReceivedArguments: (roomID: String, eventID: String)?
88+
var notificationItemProxyRoomIDEventIDReceivedInvocations: [(roomID: String, eventID: String)] = []
89+
90+
var notificationItemProxyRoomIDEventIDUnderlyingReturnValue: NotificationItemProxyProtocol?
91+
var notificationItemProxyRoomIDEventIDReturnValue: NotificationItemProxyProtocol? {
92+
get {
93+
if Thread.isMainThread {
94+
return notificationItemProxyRoomIDEventIDUnderlyingReturnValue
95+
} else {
96+
var returnValue: NotificationItemProxyProtocol?? = nil
97+
DispatchQueue.main.sync {
98+
returnValue = notificationItemProxyRoomIDEventIDUnderlyingReturnValue
99+
}
100+
101+
return returnValue!
102+
}
103+
}
104+
set {
105+
if Thread.isMainThread {
106+
notificationItemProxyRoomIDEventIDUnderlyingReturnValue = newValue
107+
} else {
108+
DispatchQueue.main.sync {
109+
notificationItemProxyRoomIDEventIDUnderlyingReturnValue = newValue
110+
}
111+
}
112+
}
113+
}
114+
var notificationItemProxyRoomIDEventIDClosure: ((String, String) async -> NotificationItemProxyProtocol?)?
115+
116+
func notificationItemProxy(roomID: String, eventID: String) async -> NotificationItemProxyProtocol? {
117+
notificationItemProxyRoomIDEventIDCallsCount += 1
118+
notificationItemProxyRoomIDEventIDReceivedArguments = (roomID: roomID, eventID: eventID)
119+
DispatchQueue.main.async {
120+
self.notificationItemProxyRoomIDEventIDReceivedInvocations.append((roomID: roomID, eventID: eventID))
121+
}
122+
if let notificationItemProxyRoomIDEventIDClosure = notificationItemProxyRoomIDEventIDClosure {
123+
return await notificationItemProxyRoomIDEventIDClosure(roomID, eventID)
124+
} else {
125+
return notificationItemProxyRoomIDEventIDReturnValue
126+
}
127+
}
128+
//MARK: - roomForIdentifier
129+
130+
var roomForIdentifierUnderlyingCallsCount = 0
131+
var roomForIdentifierCallsCount: Int {
132+
get {
133+
if Thread.isMainThread {
134+
return roomForIdentifierUnderlyingCallsCount
135+
} else {
136+
var returnValue: Int? = nil
137+
DispatchQueue.main.sync {
138+
returnValue = roomForIdentifierUnderlyingCallsCount
139+
}
140+
141+
return returnValue!
142+
}
143+
}
144+
set {
145+
if Thread.isMainThread {
146+
roomForIdentifierUnderlyingCallsCount = newValue
147+
} else {
148+
DispatchQueue.main.sync {
149+
roomForIdentifierUnderlyingCallsCount = newValue
150+
}
151+
}
152+
}
153+
}
154+
var roomForIdentifierCalled: Bool {
155+
return roomForIdentifierCallsCount > 0
156+
}
157+
var roomForIdentifierReceivedRoomID: String?
158+
var roomForIdentifierReceivedInvocations: [String] = []
159+
160+
var roomForIdentifierUnderlyingReturnValue: Room?
161+
var roomForIdentifierReturnValue: Room? {
162+
get {
163+
if Thread.isMainThread {
164+
return roomForIdentifierUnderlyingReturnValue
165+
} else {
166+
var returnValue: Room?? = nil
167+
DispatchQueue.main.sync {
168+
returnValue = roomForIdentifierUnderlyingReturnValue
169+
}
170+
171+
return returnValue!
172+
}
173+
}
174+
set {
175+
if Thread.isMainThread {
176+
roomForIdentifierUnderlyingReturnValue = newValue
177+
} else {
178+
DispatchQueue.main.sync {
179+
roomForIdentifierUnderlyingReturnValue = newValue
180+
}
181+
}
182+
}
183+
}
184+
var roomForIdentifierClosure: ((String) -> Room?)?
185+
186+
func roomForIdentifier(_ roomID: String) -> Room? {
187+
roomForIdentifierCallsCount += 1
188+
roomForIdentifierReceivedRoomID = roomID
189+
DispatchQueue.main.async {
190+
self.roomForIdentifierReceivedInvocations.append(roomID)
191+
}
192+
if let roomForIdentifierClosure = roomForIdentifierClosure {
193+
return roomForIdentifierClosure(roomID)
194+
} else {
195+
return roomForIdentifierReturnValue
196+
}
197+
}
198+
}
199+
class NotificationItemProxyMock: NotificationItemProxyProtocol, @unchecked Sendable {
200+
var event: NotificationEvent?
201+
var senderID: String {
202+
get { return underlyingSenderID }
203+
set(value) { underlyingSenderID = value }
204+
}
205+
var underlyingSenderID: String!
206+
var roomID: String {
207+
get { return underlyingRoomID }
208+
set(value) { underlyingRoomID = value }
209+
}
210+
var underlyingRoomID: String!
211+
var receiverID: String {
212+
get { return underlyingReceiverID }
213+
set(value) { underlyingReceiverID = value }
214+
}
215+
var underlyingReceiverID: String!
216+
var senderDisplayName: String?
217+
var senderAvatarMediaSource: MediaSourceProxy?
218+
var roomDisplayName: String {
219+
get { return underlyingRoomDisplayName }
220+
set(value) { underlyingRoomDisplayName = value }
221+
}
222+
var underlyingRoomDisplayName: String!
223+
var roomAvatarMediaSource: MediaSourceProxy?
224+
var roomJoinedMembers: Int {
225+
get { return underlyingRoomJoinedMembers }
226+
set(value) { underlyingRoomJoinedMembers = value }
227+
}
228+
var underlyingRoomJoinedMembers: Int!
229+
var isRoomDirect: Bool {
230+
get { return underlyingIsRoomDirect }
231+
set(value) { underlyingIsRoomDirect = value }
232+
}
233+
var underlyingIsRoomDirect: Bool!
234+
var isRoomPrivate: Bool {
235+
get { return underlyingIsRoomPrivate }
236+
set(value) { underlyingIsRoomPrivate = value }
237+
}
238+
var underlyingIsRoomPrivate: Bool!
239+
var isNoisy: Bool {
240+
get { return underlyingIsNoisy }
241+
set(value) { underlyingIsNoisy = value }
242+
}
243+
var underlyingIsNoisy: Bool!
244+
var hasMention: Bool {
245+
get { return underlyingHasMention }
246+
set(value) { underlyingHasMention = value }
247+
}
248+
var underlyingHasMention: Bool!
249+
var threadRootEventID: String?
250+
251+
}
252+
// swiftlint:enable all
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//
2+
// Copyright 2025 Element Creations Ltd.
3+
//
4+
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
5+
// Please see LICENSE files in the repository root for full details.
6+
//
7+
8+
import Foundation
9+
import UIKit
10+
11+
struct NSEMediaProviderMock: MediaProviderProtocol {
12+
func loadFileFromSource(_ source: MediaSourceProxy, filename: String?) async -> Result<MediaFileHandleProxy, MediaProviderError> {
13+
fatalError("Not implemented")
14+
}
15+
16+
func loadImageRetryingOnReconnection(_ source: MediaSourceProxy, size: CGSize?) -> Task<UIImage, any Error> {
17+
fatalError("Not implemented")
18+
}
19+
20+
func imageFromSource(_ source: MediaSourceProxy?, size: CGSize?) -> UIImage? {
21+
fatalError("Not implemented")
22+
}
23+
24+
func loadImageFromSource(_ source: MediaSourceProxy, size: CGSize?) async -> Result<UIImage, MediaProviderError> {
25+
fatalError("Not implemented")
26+
}
27+
28+
func loadImageDataFromSource(_ source: MediaSourceProxy) async -> Result<Data, MediaProviderError> {
29+
fatalError("Not implemented")
30+
}
31+
32+
func loadThumbnailForSource(source: MediaSourceProxy, size: CGSize) async -> Result<Data, MediaProviderError> {
33+
fatalError("Not implemented")
34+
}
35+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//
2+
// Copyright 2025 Element Creations Ltd.
3+
//
4+
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
5+
// Please see LICENSE files in the repository root for full details.
6+
//
7+
8+
import MatrixRustSDK
9+
10+
struct NSEUserSessionMockConfiguration {
11+
var inviteAvatarsVisibility = InviteAvatars.on
12+
var mediaPreviewVisibility = MediaPreviews.on
13+
var threadsEnabled = true
14+
}
15+
16+
extension NSEUserSessionMock {
17+
convenience init(_ configuration: NSEUserSessionMockConfiguration) {
18+
self.init()
19+
20+
underlyingInviteAvatarsVisibility = configuration.inviteAvatarsVisibility
21+
underlyingMediaPreviewVisibility = configuration.mediaPreviewVisibility
22+
underlyingThreadsEnabled = configuration.threadsEnabled
23+
}
24+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//
2+
// Copyright 2025 Element Creations Ltd.
3+
//
4+
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
5+
// Please see LICENSE files in the repository root for full details.
6+
//
7+
8+
import Foundation
9+
import MatrixRustSDK
10+
11+
struct NotificationItemProxyMockConfiguration {
12+
var event: NotificationEvent? = {
13+
// This is likely the most common notification kind
14+
// So it's also the best to use as a default test
15+
let messageType = MessageType.text(content: TextMessageContent(body: "Hello world!", formatted: nil))
16+
let messageLikeContent = MessageLikeEventContent.roomMessage(messageType: messageType, inReplyToEventId: nil)
17+
let event = TimelineEventSDKMock()
18+
event.eventTypeReturnValue = TimelineEventType.messageLike(content: messageLikeContent)
19+
return .timeline(event: event)
20+
}()
21+
22+
var senderID: String = UUID().uuidString
23+
var roomID: String = UUID().uuidString
24+
var receiverID: String = UUID().uuidString
25+
var senderDisplayName: String?
26+
var senderAvatarMediaSource: MediaSourceProxy?
27+
var roomAvatarMediaSource: MediaSourceProxy?
28+
var roomDisplayName: String?
29+
var roomJoinedMembers = 2
30+
var isRoomDirect = false
31+
var isRoomPrivate = false
32+
var isNoisy = false
33+
var hasMention = false
34+
var threadRootEventID: String?
35+
}
36+
37+
extension NotificationItemProxyMock {
38+
convenience init(_ configuration: NotificationItemProxyMockConfiguration) {
39+
self.init()
40+
event = configuration.event
41+
underlyingSenderID = configuration.senderID
42+
underlyingRoomID = configuration.roomID
43+
underlyingReceiverID = configuration.receiverID
44+
senderDisplayName = configuration.senderDisplayName
45+
roomAvatarMediaSource = configuration.roomAvatarMediaSource
46+
underlyingRoomDisplayName = configuration.roomDisplayName
47+
underlyingRoomJoinedMembers = configuration.roomJoinedMembers
48+
underlyingIsRoomDirect = configuration.isRoomDirect
49+
underlyingIsRoomPrivate = configuration.isRoomPrivate
50+
underlyingIsNoisy = configuration.isNoisy
51+
underlyingHasMention = configuration.hasMention
52+
threadRootEventID = configuration.threadRootEventID
53+
}
54+
}

0 commit comments

Comments
 (0)