Skip to content

Commit b492607

Browse files
committed
include NSE code in ElementX to allow testing
1 parent ad767d1 commit b492607

File tree

11 files changed

+272
-368
lines changed

11 files changed

+272
-368
lines changed

ElementX.xcodeproj/project.pbxproj

Lines changed: 22 additions & 54 deletions
Large diffs are not rendered by default.

ElementX/Sources/Mocks/Generated/GeneratedMocks.swift

Lines changed: 235 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11556,13 +11556,248 @@ class MediaProviderMock: MediaProviderProtocol, @unchecked Sendable {
1155611556
}
1155711557
}
1155811558
}
11559+
class NSEUserSessionMock: NSEUserSessionProtocol, @unchecked Sendable {
11560+
var inviteAvatarsVisibilityCallsCount = 0
11561+
var inviteAvatarsVisibilityCalled: Bool {
11562+
return inviteAvatarsVisibilityCallsCount > 0
11563+
}
11564+
11565+
var inviteAvatarsVisibility: InviteAvatars {
11566+
get async {
11567+
inviteAvatarsVisibilityCallsCount += 1
11568+
if let inviteAvatarsVisibilityClosure = inviteAvatarsVisibilityClosure {
11569+
return await inviteAvatarsVisibilityClosure()
11570+
} else {
11571+
return underlyingInviteAvatarsVisibility
11572+
}
11573+
}
11574+
}
11575+
var underlyingInviteAvatarsVisibility: InviteAvatars!
11576+
var inviteAvatarsVisibilityClosure: (() async -> InviteAvatars)?
11577+
var mediaPreviewVisibilityCallsCount = 0
11578+
var mediaPreviewVisibilityCalled: Bool {
11579+
return mediaPreviewVisibilityCallsCount > 0
11580+
}
11581+
11582+
var mediaPreviewVisibility: MediaPreviews {
11583+
get async {
11584+
mediaPreviewVisibilityCallsCount += 1
11585+
if let mediaPreviewVisibilityClosure = mediaPreviewVisibilityClosure {
11586+
return await mediaPreviewVisibilityClosure()
11587+
} else {
11588+
return underlyingMediaPreviewVisibility
11589+
}
11590+
}
11591+
}
11592+
var underlyingMediaPreviewVisibility: MediaPreviews!
11593+
var mediaPreviewVisibilityClosure: (() async -> MediaPreviews)?
11594+
var threadsEnabled: Bool {
11595+
get { return underlyingThreadsEnabled }
11596+
set(value) { underlyingThreadsEnabled = value }
11597+
}
11598+
var underlyingThreadsEnabled: Bool!
11599+
11600+
//MARK: - notificationItemProxy
11601+
11602+
var notificationItemProxyRoomIDEventIDUnderlyingCallsCount = 0
11603+
var notificationItemProxyRoomIDEventIDCallsCount: Int {
11604+
get {
11605+
if Thread.isMainThread {
11606+
return notificationItemProxyRoomIDEventIDUnderlyingCallsCount
11607+
} else {
11608+
var returnValue: Int? = nil
11609+
DispatchQueue.main.sync {
11610+
returnValue = notificationItemProxyRoomIDEventIDUnderlyingCallsCount
11611+
}
11612+
11613+
return returnValue!
11614+
}
11615+
}
11616+
set {
11617+
if Thread.isMainThread {
11618+
notificationItemProxyRoomIDEventIDUnderlyingCallsCount = newValue
11619+
} else {
11620+
DispatchQueue.main.sync {
11621+
notificationItemProxyRoomIDEventIDUnderlyingCallsCount = newValue
11622+
}
11623+
}
11624+
}
11625+
}
11626+
var notificationItemProxyRoomIDEventIDCalled: Bool {
11627+
return notificationItemProxyRoomIDEventIDCallsCount > 0
11628+
}
11629+
var notificationItemProxyRoomIDEventIDReceivedArguments: (roomID: String, eventID: String)?
11630+
var notificationItemProxyRoomIDEventIDReceivedInvocations: [(roomID: String, eventID: String)] = []
11631+
11632+
var notificationItemProxyRoomIDEventIDUnderlyingReturnValue: NotificationItemProxyProtocol?
11633+
var notificationItemProxyRoomIDEventIDReturnValue: NotificationItemProxyProtocol? {
11634+
get {
11635+
if Thread.isMainThread {
11636+
return notificationItemProxyRoomIDEventIDUnderlyingReturnValue
11637+
} else {
11638+
var returnValue: NotificationItemProxyProtocol?? = nil
11639+
DispatchQueue.main.sync {
11640+
returnValue = notificationItemProxyRoomIDEventIDUnderlyingReturnValue
11641+
}
11642+
11643+
return returnValue!
11644+
}
11645+
}
11646+
set {
11647+
if Thread.isMainThread {
11648+
notificationItemProxyRoomIDEventIDUnderlyingReturnValue = newValue
11649+
} else {
11650+
DispatchQueue.main.sync {
11651+
notificationItemProxyRoomIDEventIDUnderlyingReturnValue = newValue
11652+
}
11653+
}
11654+
}
11655+
}
11656+
var notificationItemProxyRoomIDEventIDClosure: ((String, String) async -> NotificationItemProxyProtocol?)?
11657+
11658+
func notificationItemProxy(roomID: String, eventID: String) async -> NotificationItemProxyProtocol? {
11659+
notificationItemProxyRoomIDEventIDCallsCount += 1
11660+
notificationItemProxyRoomIDEventIDReceivedArguments = (roomID: roomID, eventID: eventID)
11661+
DispatchQueue.main.async {
11662+
self.notificationItemProxyRoomIDEventIDReceivedInvocations.append((roomID: roomID, eventID: eventID))
11663+
}
11664+
if let notificationItemProxyRoomIDEventIDClosure = notificationItemProxyRoomIDEventIDClosure {
11665+
return await notificationItemProxyRoomIDEventIDClosure(roomID, eventID)
11666+
} else {
11667+
return notificationItemProxyRoomIDEventIDReturnValue
11668+
}
11669+
}
11670+
//MARK: - roomForIdentifier
11671+
11672+
var roomForIdentifierUnderlyingCallsCount = 0
11673+
var roomForIdentifierCallsCount: Int {
11674+
get {
11675+
if Thread.isMainThread {
11676+
return roomForIdentifierUnderlyingCallsCount
11677+
} else {
11678+
var returnValue: Int? = nil
11679+
DispatchQueue.main.sync {
11680+
returnValue = roomForIdentifierUnderlyingCallsCount
11681+
}
11682+
11683+
return returnValue!
11684+
}
11685+
}
11686+
set {
11687+
if Thread.isMainThread {
11688+
roomForIdentifierUnderlyingCallsCount = newValue
11689+
} else {
11690+
DispatchQueue.main.sync {
11691+
roomForIdentifierUnderlyingCallsCount = newValue
11692+
}
11693+
}
11694+
}
11695+
}
11696+
var roomForIdentifierCalled: Bool {
11697+
return roomForIdentifierCallsCount > 0
11698+
}
11699+
var roomForIdentifierReceivedRoomID: String?
11700+
var roomForIdentifierReceivedInvocations: [String] = []
11701+
11702+
var roomForIdentifierUnderlyingReturnValue: Room?
11703+
var roomForIdentifierReturnValue: Room? {
11704+
get {
11705+
if Thread.isMainThread {
11706+
return roomForIdentifierUnderlyingReturnValue
11707+
} else {
11708+
var returnValue: Room?? = nil
11709+
DispatchQueue.main.sync {
11710+
returnValue = roomForIdentifierUnderlyingReturnValue
11711+
}
11712+
11713+
return returnValue!
11714+
}
11715+
}
11716+
set {
11717+
if Thread.isMainThread {
11718+
roomForIdentifierUnderlyingReturnValue = newValue
11719+
} else {
11720+
DispatchQueue.main.sync {
11721+
roomForIdentifierUnderlyingReturnValue = newValue
11722+
}
11723+
}
11724+
}
11725+
}
11726+
var roomForIdentifierClosure: ((String) -> Room?)?
11727+
11728+
func roomForIdentifier(_ roomID: String) -> Room? {
11729+
roomForIdentifierCallsCount += 1
11730+
roomForIdentifierReceivedRoomID = roomID
11731+
DispatchQueue.main.async {
11732+
self.roomForIdentifierReceivedInvocations.append(roomID)
11733+
}
11734+
if let roomForIdentifierClosure = roomForIdentifierClosure {
11735+
return roomForIdentifierClosure(roomID)
11736+
} else {
11737+
return roomForIdentifierReturnValue
11738+
}
11739+
}
11740+
}
1155911741
class NetworkMonitorMock: NetworkMonitorProtocol, @unchecked Sendable {
1156011742
var reachabilityPublisher: CurrentValuePublisher<NetworkMonitorReachability, Never> {
1156111743
get { return underlyingReachabilityPublisher }
1156211744
set(value) { underlyingReachabilityPublisher = value }
1156311745
}
1156411746
var underlyingReachabilityPublisher: CurrentValuePublisher<NetworkMonitorReachability, Never>!
1156511747

11748+
}
11749+
class NotificationItemProxyMock: NotificationItemProxyProtocol, @unchecked Sendable {
11750+
var event: NotificationEvent?
11751+
var senderID: String {
11752+
get { return underlyingSenderID }
11753+
set(value) { underlyingSenderID = value }
11754+
}
11755+
var underlyingSenderID: String!
11756+
var roomID: String {
11757+
get { return underlyingRoomID }
11758+
set(value) { underlyingRoomID = value }
11759+
}
11760+
var underlyingRoomID: String!
11761+
var receiverID: String {
11762+
get { return underlyingReceiverID }
11763+
set(value) { underlyingReceiverID = value }
11764+
}
11765+
var underlyingReceiverID: String!
11766+
var senderDisplayName: String?
11767+
var senderAvatarMediaSource: MediaSourceProxy?
11768+
var roomDisplayName: String {
11769+
get { return underlyingRoomDisplayName }
11770+
set(value) { underlyingRoomDisplayName = value }
11771+
}
11772+
var underlyingRoomDisplayName: String!
11773+
var roomAvatarMediaSource: MediaSourceProxy?
11774+
var roomJoinedMembers: Int {
11775+
get { return underlyingRoomJoinedMembers }
11776+
set(value) { underlyingRoomJoinedMembers = value }
11777+
}
11778+
var underlyingRoomJoinedMembers: Int!
11779+
var isRoomDirect: Bool {
11780+
get { return underlyingIsRoomDirect }
11781+
set(value) { underlyingIsRoomDirect = value }
11782+
}
11783+
var underlyingIsRoomDirect: Bool!
11784+
var isRoomPrivate: Bool {
11785+
get { return underlyingIsRoomPrivate }
11786+
set(value) { underlyingIsRoomPrivate = value }
11787+
}
11788+
var underlyingIsRoomPrivate: Bool!
11789+
var isNoisy: Bool {
11790+
get { return underlyingIsNoisy }
11791+
set(value) { underlyingIsNoisy = value }
11792+
}
11793+
var underlyingIsNoisy: Bool!
11794+
var hasMention: Bool {
11795+
get { return underlyingHasMention }
11796+
set(value) { underlyingHasMention = value }
11797+
}
11798+
var underlyingHasMention: Bool!
11799+
var threadRootEventID: String?
11800+
1156611801
}
1156711802
class NotificationManagerMock: NotificationManagerProtocol, @unchecked Sendable {
1156811803
weak var delegate: NotificationManagerDelegate?

NSE/Sources/Mocks/NotificationItemProxyMock.swift renamed to ElementX/Sources/Mocks/NotificationItemProxyMock.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ struct NotificationItemProxyMockConfiguration {
1515
let messageType = MessageType.text(content: TextMessageContent(body: "Hello world!", formatted: nil))
1616
let messageLikeContent = MessageLikeEventContent.roomMessage(messageType: messageType, inReplyToEventId: nil)
1717
let event = TimelineEventSDKMock()
18+
event.eventIdUnderlyingReturnValue = UUID().uuidString
1819
event.eventTypeReturnValue = TimelineEventType.messageLike(content: messageLikeContent)
1920
return .timeline(event: event)
2021
}()
@@ -25,7 +26,7 @@ struct NotificationItemProxyMockConfiguration {
2526
var senderDisplayName: String?
2627
var senderAvatarMediaSource: MediaSourceProxy?
2728
var roomAvatarMediaSource: MediaSourceProxy?
28-
var roomDisplayName: String?
29+
var roomDisplayName: String
2930
var roomJoinedMembers = 2
3031
var isRoomDirect = false
3132
var isRoomPrivate = false

ElementX/SupportingFiles/target.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,3 +261,10 @@ targets:
261261
- path: ../SupportingFiles
262262
- path: ../../Tools/Scripts/Templates/SimpleScreenExample/ElementX
263263
- path: ../../DevelopmentAssets/Media
264+
265+
# This is required for testing purposes... The problem with unit tests is that if you
266+
# try to `@testable import NSE` you can only get the definition of files, but due to a
267+
# limitation in how they work, they can only compile files that are part of the main test
268+
# target, so linking will fail. The solution is to just have the main app to reference the
269+
# extension code, and test it directly.
270+
- path: ../../NSE/Sources

0 commit comments

Comments
 (0)