Leave Room (#699)

* created the row in the view and the alert, and added the new function to the RoomProxy

* fixed an issue with the alert function

* handling the navigation

* fixed a bug with the detail coordinators being dismissed incorrectly when inside a stack

* implementation completed

* replaced UI screenshots

* added a test for the fixed bug of the coordinators

* trying to increase the wait time for the expectation

* improved the test

* improved the buttons UI

* uploading artifacts for unit tests

* added result bundle true

* improved the tests

* added a new test

* pr suggestions

* updating mock

* PR suggestions

* improved tests

* fixed UI tests

* pr should be ready now

* removed testing code

* reduced complexity

* fixed test

* added a an assert to the new test case

* more tests and messages cases

* pr comments addressed

* completed
This commit is contained in:
Mauro
2023-03-17 14:57:08 +01:00
committed by GitHub
parent 7544619a55
commit 61d42a24ba
35 changed files with 719 additions and 155 deletions
@@ -3,6 +3,7 @@
// swiftlint:disable all
import Combine
import Foundation
import MatrixRustSDK
class BugReportServiceMock: BugReportServiceProtocol {
var crashedLastRun: Bool {
@@ -49,6 +50,322 @@ class BugReportServiceMock: BugReportServiceProtocol {
}
}
}
class RoomProxyMock: RoomProxyProtocol {
var id: String {
get { return underlyingId }
set(value) { underlyingId = value }
}
var underlyingId: String!
var isDirect: Bool {
get { return underlyingIsDirect }
set(value) { underlyingIsDirect = value }
}
var underlyingIsDirect: Bool!
var isPublic: Bool {
get { return underlyingIsPublic }
set(value) { underlyingIsPublic = value }
}
var underlyingIsPublic: Bool!
var isSpace: Bool {
get { return underlyingIsSpace }
set(value) { underlyingIsSpace = value }
}
var underlyingIsSpace: Bool!
var isEncrypted: Bool {
get { return underlyingIsEncrypted }
set(value) { underlyingIsEncrypted = value }
}
var underlyingIsEncrypted: Bool!
var isTombstoned: Bool {
get { return underlyingIsTombstoned }
set(value) { underlyingIsTombstoned = value }
}
var underlyingIsTombstoned: Bool!
var canonicalAlias: String?
var alternativeAliases: [String] = []
var hasUnreadNotifications: Bool {
get { return underlyingHasUnreadNotifications }
set(value) { underlyingHasUnreadNotifications = value }
}
var underlyingHasUnreadNotifications: Bool!
var name: String?
var displayName: String?
var topic: String?
var avatarURL: URL?
//MARK: - loadAvatarURLForUserId
var loadAvatarURLForUserIdCallsCount = 0
var loadAvatarURLForUserIdCalled: Bool {
return loadAvatarURLForUserIdCallsCount > 0
}
var loadAvatarURLForUserIdReceivedUserId: String?
var loadAvatarURLForUserIdReceivedInvocations: [String] = []
var loadAvatarURLForUserIdReturnValue: Result<URL?, RoomProxyError>!
var loadAvatarURLForUserIdClosure: ((String) async -> Result<URL?, RoomProxyError>)?
func loadAvatarURLForUserId(_ userId: String) async -> Result<URL?, RoomProxyError> {
loadAvatarURLForUserIdCallsCount += 1
loadAvatarURLForUserIdReceivedUserId = userId
loadAvatarURLForUserIdReceivedInvocations.append(userId)
if let loadAvatarURLForUserIdClosure = loadAvatarURLForUserIdClosure {
return await loadAvatarURLForUserIdClosure(userId)
} else {
return loadAvatarURLForUserIdReturnValue
}
}
//MARK: - loadDisplayNameForUserId
var loadDisplayNameForUserIdCallsCount = 0
var loadDisplayNameForUserIdCalled: Bool {
return loadDisplayNameForUserIdCallsCount > 0
}
var loadDisplayNameForUserIdReceivedUserId: String?
var loadDisplayNameForUserIdReceivedInvocations: [String] = []
var loadDisplayNameForUserIdReturnValue: Result<String?, RoomProxyError>!
var loadDisplayNameForUserIdClosure: ((String) async -> Result<String?, RoomProxyError>)?
func loadDisplayNameForUserId(_ userId: String) async -> Result<String?, RoomProxyError> {
loadDisplayNameForUserIdCallsCount += 1
loadDisplayNameForUserIdReceivedUserId = userId
loadDisplayNameForUserIdReceivedInvocations.append(userId)
if let loadDisplayNameForUserIdClosure = loadDisplayNameForUserIdClosure {
return await loadDisplayNameForUserIdClosure(userId)
} else {
return loadDisplayNameForUserIdReturnValue
}
}
//MARK: - addTimelineListener
var addTimelineListenerListenerCallsCount = 0
var addTimelineListenerListenerCalled: Bool {
return addTimelineListenerListenerCallsCount > 0
}
var addTimelineListenerListenerReceivedListener: TimelineListener?
var addTimelineListenerListenerReceivedInvocations: [TimelineListener] = []
var addTimelineListenerListenerReturnValue: Result<[TimelineItem], RoomProxyError>!
var addTimelineListenerListenerClosure: ((TimelineListener) -> Result<[TimelineItem], RoomProxyError>)?
func addTimelineListener(listener: TimelineListener) -> Result<[TimelineItem], RoomProxyError> {
addTimelineListenerListenerCallsCount += 1
addTimelineListenerListenerReceivedListener = listener
addTimelineListenerListenerReceivedInvocations.append(listener)
if let addTimelineListenerListenerClosure = addTimelineListenerListenerClosure {
return addTimelineListenerListenerClosure(listener)
} else {
return addTimelineListenerListenerReturnValue
}
}
//MARK: - removeTimelineListener
var removeTimelineListenerCallsCount = 0
var removeTimelineListenerCalled: Bool {
return removeTimelineListenerCallsCount > 0
}
var removeTimelineListenerClosure: (() -> Void)?
func removeTimelineListener() {
removeTimelineListenerCallsCount += 1
removeTimelineListenerClosure?()
}
//MARK: - paginateBackwards
var paginateBackwardsRequestSizeUntilNumberOfItemsCallsCount = 0
var paginateBackwardsRequestSizeUntilNumberOfItemsCalled: Bool {
return paginateBackwardsRequestSizeUntilNumberOfItemsCallsCount > 0
}
var paginateBackwardsRequestSizeUntilNumberOfItemsReceivedArguments: (requestSize: UInt, untilNumberOfItems: UInt)?
var paginateBackwardsRequestSizeUntilNumberOfItemsReceivedInvocations: [(requestSize: UInt, untilNumberOfItems: UInt)] = []
var paginateBackwardsRequestSizeUntilNumberOfItemsReturnValue: Result<Void, RoomProxyError>!
var paginateBackwardsRequestSizeUntilNumberOfItemsClosure: ((UInt, UInt) async -> Result<Void, RoomProxyError>)?
func paginateBackwards(requestSize: UInt, untilNumberOfItems: UInt) async -> Result<Void, RoomProxyError> {
paginateBackwardsRequestSizeUntilNumberOfItemsCallsCount += 1
paginateBackwardsRequestSizeUntilNumberOfItemsReceivedArguments = (requestSize: requestSize, untilNumberOfItems: untilNumberOfItems)
paginateBackwardsRequestSizeUntilNumberOfItemsReceivedInvocations.append((requestSize: requestSize, untilNumberOfItems: untilNumberOfItems))
if let paginateBackwardsRequestSizeUntilNumberOfItemsClosure = paginateBackwardsRequestSizeUntilNumberOfItemsClosure {
return await paginateBackwardsRequestSizeUntilNumberOfItemsClosure(requestSize, untilNumberOfItems)
} else {
return paginateBackwardsRequestSizeUntilNumberOfItemsReturnValue
}
}
//MARK: - sendReadReceipt
var sendReadReceiptForCallsCount = 0
var sendReadReceiptForCalled: Bool {
return sendReadReceiptForCallsCount > 0
}
var sendReadReceiptForReceivedEventID: String?
var sendReadReceiptForReceivedInvocations: [String] = []
var sendReadReceiptForReturnValue: Result<Void, RoomProxyError>!
var sendReadReceiptForClosure: ((String) async -> Result<Void, RoomProxyError>)?
func sendReadReceipt(for eventID: String) async -> Result<Void, RoomProxyError> {
sendReadReceiptForCallsCount += 1
sendReadReceiptForReceivedEventID = eventID
sendReadReceiptForReceivedInvocations.append(eventID)
if let sendReadReceiptForClosure = sendReadReceiptForClosure {
return await sendReadReceiptForClosure(eventID)
} else {
return sendReadReceiptForReturnValue
}
}
//MARK: - sendMessage
var sendMessageInReplyToCallsCount = 0
var sendMessageInReplyToCalled: Bool {
return sendMessageInReplyToCallsCount > 0
}
var sendMessageInReplyToReceivedArguments: (message: String, eventID: String?)?
var sendMessageInReplyToReceivedInvocations: [(message: String, eventID: String?)] = []
var sendMessageInReplyToReturnValue: Result<Void, RoomProxyError>!
var sendMessageInReplyToClosure: ((String, String?) async -> Result<Void, RoomProxyError>)?
func sendMessage(_ message: String, inReplyTo eventID: String?) async -> Result<Void, RoomProxyError> {
sendMessageInReplyToCallsCount += 1
sendMessageInReplyToReceivedArguments = (message: message, eventID: eventID)
sendMessageInReplyToReceivedInvocations.append((message: message, eventID: eventID))
if let sendMessageInReplyToClosure = sendMessageInReplyToClosure {
return await sendMessageInReplyToClosure(message, eventID)
} else {
return sendMessageInReplyToReturnValue
}
}
//MARK: - sendReaction
var sendReactionToCallsCount = 0
var sendReactionToCalled: Bool {
return sendReactionToCallsCount > 0
}
var sendReactionToReceivedArguments: (reaction: String, eventID: String)?
var sendReactionToReceivedInvocations: [(reaction: String, eventID: String)] = []
var sendReactionToReturnValue: Result<Void, RoomProxyError>!
var sendReactionToClosure: ((String, String) async -> Result<Void, RoomProxyError>)?
func sendReaction(_ reaction: String, to eventID: String) async -> Result<Void, RoomProxyError> {
sendReactionToCallsCount += 1
sendReactionToReceivedArguments = (reaction: reaction, eventID: eventID)
sendReactionToReceivedInvocations.append((reaction: reaction, eventID: eventID))
if let sendReactionToClosure = sendReactionToClosure {
return await sendReactionToClosure(reaction, eventID)
} else {
return sendReactionToReturnValue
}
}
//MARK: - editMessage
var editMessageOriginalCallsCount = 0
var editMessageOriginalCalled: Bool {
return editMessageOriginalCallsCount > 0
}
var editMessageOriginalReceivedArguments: (newMessage: String, eventID: String)?
var editMessageOriginalReceivedInvocations: [(newMessage: String, eventID: String)] = []
var editMessageOriginalReturnValue: Result<Void, RoomProxyError>!
var editMessageOriginalClosure: ((String, String) async -> Result<Void, RoomProxyError>)?
func editMessage(_ newMessage: String, original eventID: String) async -> Result<Void, RoomProxyError> {
editMessageOriginalCallsCount += 1
editMessageOriginalReceivedArguments = (newMessage: newMessage, eventID: eventID)
editMessageOriginalReceivedInvocations.append((newMessage: newMessage, eventID: eventID))
if let editMessageOriginalClosure = editMessageOriginalClosure {
return await editMessageOriginalClosure(newMessage, eventID)
} else {
return editMessageOriginalReturnValue
}
}
//MARK: - redact
var redactCallsCount = 0
var redactCalled: Bool {
return redactCallsCount > 0
}
var redactReceivedEventID: String?
var redactReceivedInvocations: [String] = []
var redactReturnValue: Result<Void, RoomProxyError>!
var redactClosure: ((String) async -> Result<Void, RoomProxyError>)?
func redact(_ eventID: String) async -> Result<Void, RoomProxyError> {
redactCallsCount += 1
redactReceivedEventID = eventID
redactReceivedInvocations.append(eventID)
if let redactClosure = redactClosure {
return await redactClosure(eventID)
} else {
return redactReturnValue
}
}
//MARK: - reportContent
var reportContentReasonCallsCount = 0
var reportContentReasonCalled: Bool {
return reportContentReasonCallsCount > 0
}
var reportContentReasonReceivedArguments: (eventID: String, reason: String?)?
var reportContentReasonReceivedInvocations: [(eventID: String, reason: String?)] = []
var reportContentReasonReturnValue: Result<Void, RoomProxyError>!
var reportContentReasonClosure: ((String, String?) async -> Result<Void, RoomProxyError>)?
func reportContent(_ eventID: String, reason: String?) async -> Result<Void, RoomProxyError> {
reportContentReasonCallsCount += 1
reportContentReasonReceivedArguments = (eventID: eventID, reason: reason)
reportContentReasonReceivedInvocations.append((eventID: eventID, reason: reason))
if let reportContentReasonClosure = reportContentReasonClosure {
return await reportContentReasonClosure(eventID, reason)
} else {
return reportContentReasonReturnValue
}
}
//MARK: - members
var membersCallsCount = 0
var membersCalled: Bool {
return membersCallsCount > 0
}
var membersReturnValue: Result<[RoomMemberProxy], RoomProxyError>!
var membersClosure: (() async -> Result<[RoomMemberProxy], RoomProxyError>)?
func members() async -> Result<[RoomMemberProxy], RoomProxyError> {
membersCallsCount += 1
if let membersClosure = membersClosure {
return await membersClosure()
} else {
return membersReturnValue
}
}
//MARK: - retryDecryption
var retryDecryptionForCallsCount = 0
var retryDecryptionForCalled: Bool {
return retryDecryptionForCallsCount > 0
}
var retryDecryptionForReceivedSessionID: String?
var retryDecryptionForReceivedInvocations: [String] = []
var retryDecryptionForClosure: ((String) async -> Void)?
func retryDecryption(for sessionID: String) async {
retryDecryptionForCallsCount += 1
retryDecryptionForReceivedSessionID = sessionID
retryDecryptionForReceivedInvocations.append(sessionID)
await retryDecryptionForClosure?(sessionID)
}
//MARK: - leaveRoom
var leaveRoomCallsCount = 0
var leaveRoomCalled: Bool {
return leaveRoomCallsCount > 0
}
var leaveRoomReturnValue: Result<Void, RoomProxyError>!
var leaveRoomClosure: (() async -> Result<Void, RoomProxyError>)?
func leaveRoom() async -> Result<Void, RoomProxyError> {
leaveRoomCallsCount += 1
if let leaveRoomClosure = leaveRoomClosure {
return await leaveRoomClosure()
} else {
return leaveRoomReturnValue
}
}
}
class SessionVerificationControllerProxyMock: SessionVerificationControllerProxyProtocol {
var callbacks: PassthroughSubject<SessionVerificationControllerProxyCallback, Never> {
get { return underlyingCallbacks }
@@ -0,0 +1,61 @@
//
// Copyright 2023 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
import Foundation
struct RoomProxyMockConfiguration {
var id = UUID().uuidString
let name: String? = nil
let displayName: String?
var topic: String?
var avatarURL: URL?
var isDirect = Bool.random()
var isSpace = Bool.random()
var isPublic = Bool.random()
var isEncrypted = Bool.random()
var isTombstoned = Bool.random()
var canonicalAlias: String?
var alternativeAliases: [String] = []
var hasUnreadNotifications = Bool.random()
var members: [RoomMemberProxy]?
}
extension RoomProxyMock {
convenience init(with configuration: RoomProxyMockConfiguration) {
self.init()
id = configuration.id
name = configuration.name
displayName = configuration.displayName
topic = configuration.topic
avatarURL = configuration.avatarURL
isDirect = configuration.isDirect
isSpace = configuration.isSpace
isPublic = configuration.isPublic
isEncrypted = configuration.isEncrypted
isTombstoned = configuration.isTombstoned
canonicalAlias = configuration.canonicalAlias
alternativeAliases = configuration.alternativeAliases
hasUnreadNotifications = configuration.hasUnreadNotifications
membersClosure = {
if let members = configuration.members {
return .success(members)
}
return .failure(.failedRetrievingMembers)
}
}
}