mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 12:07:55 +00:00
Adopt StateStoreViewModelV2 in more screens. (#4275)
* Use StateStoreViewModelV2 in AnalyticsPromptScreen.
* Use StateStoreViewModelV2 in UserProfileScreen.
* Use StateStoreViewModelV2 in MediaUploadPreviewScreen.
* Use StateStoreViewModelV2 in the Roles & Permissions screens.
* Add the asyncStream variant of deferFailure.
* Use StateStoreViewModelV2 in BlockedUsersScreen.
* Use StateStoreViewModelV2 in ManageRoomMemberSheet.
* Use StateStoreViewModelV2 in ResolveVerifiedUserSendFailureScreen.
* Use StateStoreViewModelV2 in ReportContentScreen.
* Use StateStoreViewModelV2 in ReportRoomScreen.
* Use StateStoreViewModelV2 in StaticLocationScreen.
* Use StateStoreViewModelV2 in EmojiPickerScreen.
* Use StateStoreViewModelV2 in PollFormScreen.
* Use StateStoreViewModelV2 in DeclineAndBlockScreen.
* Use StateStoreViewModelV2 in RoomDetailsScreen.
* Fix a random compilation error that just popped up 🤷♂️
* Fix expectation message.
This commit is contained in:
@@ -158,6 +158,36 @@ extension XCTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
/// XCTest utility that assists in subscribing to an async stream and deferring the failure for a particular value until some other actions have been performed.
|
||||
/// - Parameters:
|
||||
/// - asyncStream: The stream to wait on.
|
||||
/// - timeout: A timeout after which we give up.
|
||||
/// - message: An optional custom expectation message
|
||||
/// - until: callback that evaluates outputs until some condition is reached
|
||||
/// - Returns: The deferred fulfilment to be executed after some actions. The stream's result is not returned from this fulfilment.
|
||||
func deferFailure<Value>(_ asyncStream: AsyncStream<Value>,
|
||||
timeout: TimeInterval,
|
||||
message: String? = nil,
|
||||
until condition: @escaping (Value) -> Bool) -> DeferredFulfillment<Void> {
|
||||
let expectation = expectation(description: message ?? "Awaiting stream")
|
||||
expectation.isInverted = true
|
||||
var hasFulfilled = false
|
||||
|
||||
let task = Task {
|
||||
for await value in asyncStream {
|
||||
if condition(value), !hasFulfilled {
|
||||
expectation.fulfill()
|
||||
hasFulfilled = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return DeferredFulfillment<Void> {
|
||||
await self.fulfillment(of: [expectation], timeout: timeout)
|
||||
task.cancel()
|
||||
}
|
||||
}
|
||||
|
||||
struct DeferredFulfillment<T> {
|
||||
let closure: () async throws -> T
|
||||
@discardableResult func fulfill() async throws -> T {
|
||||
|
||||
Reference in New Issue
Block a user