Fix various flakey unit tests (#1783)

* Fix flakey emoji provider tests

* Fix flakey RoomScreenViewModel tests

* Fix flakey HomeScreenViewModel tests

* Fix flakey RoomMemberListScreen tests, problem with bindings getting overriden and deferFulfillment cancellable not getting stored

* Fix flakey RoomNotificationSettingsScreen tests and crashes

* Fix flakey RoomMemberDetailsScreen tests

* Deprecate old `deferFulfillment` and `nextViewState` methods

* Convert more files to the new `deferFulfillment`

* Converted the rest of the tests to the new deferFulfillment

* Removed now unused `nextViewState` and `deferFulfillment`

* Remove automatic retries from unit tests

* Reset analytics flag after running unit tests

* Address PR comments

* Introduce a new `deferFulfillment(publisher, keyPath, transitionValues)` method and use it where appropiate
This commit is contained in:
Stefan Ceriu
2023-09-26 13:28:29 +03:00
committed by GitHub
parent 1f3898c69d
commit a05c3e3774
27 changed files with 841 additions and 519 deletions
@@ -31,15 +31,16 @@ class ReportContentScreenViewModelTests: XCTestCase {
senderID: senderID,
roomProxy: roomProxy)
let deferred = deferFulfillment(viewModel.actions.collect(2).first(), message: "2 actions should be published.")
// When reporting the content without ignoring the user.
viewModel.state.bindings.reasonText = reportReason
viewModel.state.bindings.ignoreUser = false
viewModel.context.send(viewAction: .submit)
let actions = try await deferred.fulfill()
XCTAssertEqual(actions, [.submitStarted, .submitFinished])
let deferred = deferFulfillment(viewModel.actions) { action in
action == .submitFinished
}
try await deferred.fulfill()
// Then the content should be reported, but the user should not be included.
XCTAssertEqual(roomProxy.reportContentReasonCallsCount, 1, "The content should always be reported.")
@@ -62,10 +63,13 @@ class ReportContentScreenViewModelTests: XCTestCase {
viewModel.state.bindings.reasonText = reportReason
viewModel.state.bindings.ignoreUser = true
let deferred = deferFulfillment(viewModel.actions.collect(2).first())
viewModel.context.send(viewAction: .submit)
let result = try await deferred.fulfill()
XCTAssertEqual(result, [.submitStarted, .submitFinished])
let deferred = deferFulfillment(viewModel.actions) { action in
action == .submitFinished
}
try await deferred.fulfill()
// Then the content should be reported, and the user should be ignored.
XCTAssertEqual(roomProxy.reportContentReasonCallsCount, 1, "The content should always be reported.")