Add xcDeferFulfillment to help with tests that have publishers. (#1278)

* Add xcAwaitDeferred to aid with tests that have publishers.

* Improve naming

* Address Comments

- Fix naming
- Add optional expectation message
- Use trailing closure syntax
This commit is contained in:
David Langley
2023-07-07 15:08:32 +01:00
committed by GitHub
parent 448db8a8e9
commit 83e27564d5
8 changed files with 92 additions and 24 deletions
@@ -213,9 +213,10 @@ class RoomScreenViewModelTests: XCTestCase {
let roomProxyMock = RoomProxyMock(with: .init(displayName: ""))
let roomMemberMock = RoomMemberProxyMock()
roomMemberMock.userID = "bob"
let expectation = XCTestExpectation(description: "Go to user details")
roomProxyMock.getMemberUserIDClosure = { _ in
try? await Task.sleep(for: .milliseconds(200))
return .success(roomMemberMock)
.success(roomMemberMock)
}
let viewModel = RoomScreenViewModel(timelineController: timelineController,
@@ -229,6 +230,7 @@ class RoomScreenViewModelTests: XCTestCase {
switch action {
case .displayRoomMemberDetails(let member):
XCTAssert(member === roomMemberMock)
expectation.fulfill()
default:
XCTFail("Did not received the expected action")
}
@@ -236,7 +238,8 @@ class RoomScreenViewModelTests: XCTestCase {
// Test
viewModel.context.send(viewAction: .tappedOnUser(userID: "bob"))
try? await Task.sleep(for: .milliseconds(300))
await fulfillment(of: [expectation])
XCTAssert(userIndicatorControllerMock.submitIndicatorDelayCallsCount == 1)
XCTAssert(userIndicatorControllerMock.retractIndicatorWithIdCallsCount == 1)
XCTAssert(roomProxyMock.getMemberUserIDCallsCount == 1)