waitConfirmation implementation (#5130)

* `waitConfirmation` implementation

* even better docs

* made the body not async since the context of usage did not really require it

* pr suggestions
This commit is contained in:
Mauro
2026-02-23 14:24:19 +01:00
committed by GitHub
parent 546a71df0c
commit 6f1720da89
8 changed files with 262 additions and 77 deletions
@@ -25,27 +25,18 @@ struct EmojiPickerScreenViewModelTests {
let reaction = "👋"
let deferred = deferFulfillment(viewModel.actions) { $0 == .dismiss }
try await confirmation { confirmation in
var toggleReactionCalled = false
try await waitForConfirmation(timeout: .seconds(5)) { confirmation in
timelineProxy.toggleReactionToClosure = { toggledReaction, _ in
defer {
confirmation()
toggleReactionCalled = true
}
defer { confirmation() }
#expect(toggledReaction == reaction)
return .success(())
}
context.send(viewAction: .emojiTapped(emoji: .init(id: "wave", value: reaction)))
try await deferred.fulfill()
// Since the reaction is called asynchronously after dismissing the picker
// We need to actively wait for the function to be called before fulfilling the test.
while !toggleReactionCalled {
await Task.yield()
}
}
try await deferred.fulfill()
}
// MARK: - Helpers