mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:55:59 +00:00
Fix unit and UI tests. (#460)
* Fix race condition on session verification tests. * Fix clear button on text field. * Add a timeout to UI test signalling. * Use snapshot testing for login screen.
This commit is contained in:
+1
-1
@@ -22,7 +22,7 @@ struct MockSessionVerificationControllerProxy: SessionVerificationControllerProx
|
||||
var callbacks = PassthroughSubject<SessionVerificationControllerProxyCallback, Never>()
|
||||
|
||||
var isVerified = false
|
||||
var requestDelay: Duration = .seconds(2)
|
||||
var requestDelay: Duration = .seconds(1)
|
||||
|
||||
func requestVerification() async -> Result<Void, SessionVerificationControllerProxyError> {
|
||||
Task.detached {
|
||||
|
||||
@@ -253,7 +253,9 @@ class MockScreen: Identifiable {
|
||||
navigationStackCoordinator.setRootCoordinator(coordinator)
|
||||
return navigationStackCoordinator
|
||||
case .sessionVerification:
|
||||
let parameters = SessionVerificationCoordinatorParameters(sessionVerificationControllerProxy: MockSessionVerificationControllerProxy())
|
||||
var sessionVerificationControllerProxy = MockSessionVerificationControllerProxy()
|
||||
sessionVerificationControllerProxy.requestDelay = .seconds(2)
|
||||
let parameters = SessionVerificationCoordinatorParameters(sessionVerificationControllerProxy: sessionVerificationControllerProxy)
|
||||
return SessionVerificationCoordinator(parameters: parameters)
|
||||
case .userSessionScreen:
|
||||
let navigationSplitCoordinator = NavigationSplitCoordinator(placeholderCoordinator: SplashScreenCoordinator())
|
||||
|
||||
@@ -39,6 +39,8 @@ enum UITestsSignalError: Error {
|
||||
case notConnected
|
||||
/// Attempted to receive multiple signals at once.
|
||||
case awaitingAnotherSignal
|
||||
/// Receiving the next signal timed out.
|
||||
case timeout
|
||||
/// A network error occurred.
|
||||
case nwError(NWError)
|
||||
/// An unexpected signal was received. This error isn't used internally.
|
||||
@@ -123,6 +125,12 @@ enum UITestsSignalling {
|
||||
private let connection: NWConnection
|
||||
/// A continuation to call each time a signal is received.
|
||||
private var nextMessageContinuation: CheckedContinuation<UITestsSignal, Error>?
|
||||
/// A task to handle the timeout when receiving a signal.
|
||||
private var nextMessageTimeoutTask: Task<Void, Never>? {
|
||||
didSet {
|
||||
oldValue?.cancel()
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates a new signalling `Connection`.
|
||||
init() {
|
||||
@@ -165,6 +173,7 @@ enum UITestsSignalling {
|
||||
if let nextMessageContinuation {
|
||||
nextMessageContinuation.resume(throwing: UITestsSignalError.cancelled)
|
||||
self.nextMessageContinuation = nil
|
||||
nextMessageTimeoutTask = nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -182,6 +191,20 @@ enum UITestsSignalling {
|
||||
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
self.nextMessageContinuation = continuation
|
||||
|
||||
// Add a 30 second timeout to stop tests from hanging
|
||||
self.nextMessageTimeoutTask = Task { [weak self] in
|
||||
guard let self else { return }
|
||||
try? await Task.sleep(for: .seconds(30))
|
||||
|
||||
guard !Task.isCancelled,
|
||||
let nextMessageContinuation = self.nextMessageContinuation
|
||||
else { return }
|
||||
|
||||
nextMessageContinuation.resume(throwing: UITestsSignalError.timeout)
|
||||
self.nextMessageContinuation = nil
|
||||
self.nextMessageTimeoutTask = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,12 +221,14 @@ enum UITestsSignalling {
|
||||
let error: UITestsSignalError = error.map { .nwError($0) } ?? .unknown
|
||||
self.nextMessageContinuation?.resume(with: .failure(error))
|
||||
self.nextMessageContinuation = nil
|
||||
self.nextMessageTimeoutTask = nil
|
||||
return
|
||||
}
|
||||
|
||||
if signal != .connect {
|
||||
self.nextMessageContinuation?.resume(returning: signal)
|
||||
self.nextMessageContinuation = nil
|
||||
self.nextMessageTimeoutTask = nil
|
||||
}
|
||||
|
||||
self.receiveNextMessage()
|
||||
|
||||
Reference in New Issue
Block a user