Optimize invites list (part 2) (#1268)

* Optimise invites list

* Fix failing tests

* Cleanup

* Add weak self

* Refactor ReportContentViewModelTests
This commit is contained in:
Alfonso Grillo
2023-07-11 10:08:27 +02:00
committed by GitHub
parent 5ae227179c
commit 98dabe8500
11 changed files with 120 additions and 88 deletions
@@ -96,6 +96,7 @@ class HomeScreenViewModelTests: XCTestCase {
func testLeaveRoomSuccess() async throws {
let mockRoomId = "1"
var correctResult = false
let expectation = expectation(description: #function)
viewModel.callback = { result in
switch result {
case .roomLeft(let roomIdentifier):
@@ -103,12 +104,13 @@ class HomeScreenViewModelTests: XCTestCase {
default:
break
}
expectation.fulfill()
}
let room: RoomProxyMock = .init(with: .init(id: mockRoomId, displayName: "Some room"))
room.leaveRoomClosure = { .success(()) }
clientProxy.roomForIdentifierMocks[mockRoomId] = room
context.send(viewAction: .confirmLeaveRoom(roomIdentifier: mockRoomId))
await Task.yield()
await fulfillment(of: [expectation])
XCTAssertNil(context.alertInfo)
XCTAssertTrue(correctResult)
}
@@ -49,7 +49,7 @@ class ReportContentScreenViewModelTests: XCTestCase {
XCTAssertNil(roomProxy.ignoreUserReceivedUserID, "The sender shouldn't have been ignored.")
}
func testReportIgnoringSender() async {
func testReportIgnoringSender() async throws {
// Given the report content view for some content.
let roomProxy = RoomProxyMock(with: .init(displayName: "test"))
roomProxy.reportContentReasonReturnValue = .success(())
@@ -61,9 +61,11 @@ class ReportContentScreenViewModelTests: XCTestCase {
// When reporting the content and also ignoring the user.
viewModel.state.bindings.reasonText = reportReason
viewModel.state.bindings.ignoreUser = true
let deferred = deferFulfillment(viewModel.actions.collect(2).first())
viewModel.context.send(viewAction: .submit)
_ = await viewModel.actions.values.first()
let result = try await deferred.fulfill()
XCTAssertEqual(result, [.submitStarted, .submitFinished])
// Then the content should be reported, and the user should be ignored.
XCTAssertEqual(roomProxy.reportContentReasonCallsCount, 1, "The content should always be reported.")
@@ -68,6 +68,7 @@ class RoomDetailsScreenViewModelTests: XCTestCase {
}
func testLeaveRoomSuccess() async {
let expectation = expectation(description: #function)
roomProxyMock.leaveRoomClosure = {
.success(())
}
@@ -78,18 +79,23 @@ class RoomDetailsScreenViewModelTests: XCTestCase {
default:
XCTFail("leftRoom expected")
}
expectation.fulfill()
}
context.send(viewAction: .confirmLeave)
await Task.yield()
await fulfillment(of: [expectation])
XCTAssertEqual(roomProxyMock.leaveRoomCallsCount, 1)
}
func testLeaveRoomError() async {
let expectation = expectation(description: #function)
roomProxyMock.leaveRoomClosure = {
.failure(.failedLeavingRoom)
defer {
expectation.fulfill()
}
return .failure(.failedLeavingRoom)
}
context.send(viewAction: .confirmLeave)
await context.nextViewState()
await fulfillment(of: [expectation])
XCTAssertEqual(roomProxyMock.leaveRoomCallsCount, 1)
XCTAssertNotNil(context.alertInfo)
}
@@ -178,6 +178,7 @@ class RoomScreenViewModelTests: XCTestCase {
func testGoToUserDetailsSuccessNoDelay() async {
// Setup
let expectation = expectation(description: #function)
let timelineController = MockRoomTimelineController()
let roomProxyMock = RoomProxyMock(with: .init(displayName: ""))
let roomMemberMock = RoomMemberProxyMock()
@@ -197,11 +198,12 @@ class RoomScreenViewModelTests: XCTestCase {
default:
XCTFail("Did not received the expected action")
}
expectation.fulfill()
}
// Test
viewModel.context.send(viewAction: .tappedOnUser(userID: "bob"))
await Task.yield()
await fulfillment(of: [expectation])
XCTAssert(userIndicatorControllerMock.submitIndicatorDelayCallsCount == 1)
XCTAssert(roomProxyMock.getMemberUserIDCallsCount == 1)
XCTAssertEqual(roomProxyMock.getMemberUserIDReceivedUserID, "bob")
@@ -288,7 +290,7 @@ class RoomScreenViewModelTests: XCTestCase {
// Test
viewModel.context.send(viewAction: .retrySend(transactionID: "test retry send id"))
await Task.yield()
try? await Task.sleep(for: .microseconds(500))
XCTAssert(roomProxyMock.retrySendTransactionIDCallsCount == 1)
XCTAssert(roomProxyMock.retrySendTransactionIDReceivedInvocations == ["test retry send id"])
}
@@ -325,7 +327,7 @@ class RoomScreenViewModelTests: XCTestCase {
// Test
viewModel.context.send(viewAction: .cancelSend(transactionID: "test cancel send id"))
await Task.yield()
try? await Task.sleep(for: .microseconds(500))
XCTAssert(roomProxyMock.cancelSendTransactionIDCallsCount == 1)
XCTAssert(roomProxyMock.cancelSendTransactionIDReceivedInvocations == ["test cancel send id"])
}