Fix more unit tests. (#1406)

- Randomise test order.
- Use deferred fulfilment in more places.
- Make sure to change something before awaiting the fulfilment.
- Build a fresh AppSettings after reset().
- Retry tests on failure.
This commit is contained in:
Doug
2023-07-27 12:38:48 +01:00
committed by GitHub
parent 1529b5b8ca
commit 8f2904701b
9 changed files with 92 additions and 75 deletions
@@ -248,7 +248,7 @@ class RoomScreenViewModelTests: XCTestCase {
XCTAssertEqual(roomProxyMock.getMemberUserIDReceivedUserID, "bob")
}
func testGoToUserDetailsFailure() async {
func testGoToUserDetailsFailure() async throws {
// Setup
let timelineController = MockRoomTimelineController()
let roomProxyMock = RoomProxyMock(with: .init(displayName: ""))
@@ -269,14 +269,16 @@ class RoomScreenViewModelTests: XCTestCase {
}
// Test
let deferred = deferFulfillment(viewModel.context.$viewState.collect(2).first(),
message: "The existing view state plus one new one should be published.")
viewModel.context.send(viewAction: .tappedOnUser(userID: "bob"))
await viewModel.context.nextViewState()
try await deferred.fulfill()
XCTAssertFalse(viewModel.state.bindings.alertInfo.isNil)
XCTAssert(roomProxyMock.getMemberUserIDCallsCount == 1)
XCTAssertEqual(roomProxyMock.getMemberUserIDReceivedUserID, "bob")
}
func testRetrySend() async {
func testRetrySend() async throws {
// Setup
let timelineController = MockRoomTimelineController()
let roomProxyMock = RoomProxyMock(with: .init(displayName: ""))