Add Block user to Report Content screen. (#742)

This commit is contained in:
Doug
2023-04-03 10:21:24 +01:00
committed by GitHub
parent 7d1ab997ce
commit 220138d492
33 changed files with 220 additions and 130 deletions
@@ -20,10 +20,52 @@ import XCTest
@MainActor
class ReportContentScreenViewModelTests: XCTestCase {
func testInitialState() {
let viewModel = ReportContentViewModel(itemID: "test-id", roomProxy: RoomProxyMock(with: .init(displayName: "test")))
let context = viewModel.context
XCTAssertEqual(context.reasonText, "")
let itemID = "test-id"
let senderID = "@meany:server.com"
let reportReason = "I don't like it."
func testReportContent() async {
// Given the report content view for some content.
let roomProxy = RoomProxyMock(with: .init(displayName: "test"))
roomProxy.reportContentReasonReturnValue = .success(())
let viewModel = ReportContentViewModel(itemID: itemID,
senderID: senderID,
roomProxy: roomProxy)
// When reporting the content without ignoring the user.
viewModel.state.bindings.reasonText = reportReason
viewModel.state.bindings.ignoreUser = false
viewModel.context.send(viewAction: .submit)
await Task.yield()
// Then the content should be reported, but the user should not be included.
XCTAssertEqual(roomProxy.reportContentReasonCallsCount, 1, "The content should always be reported.")
XCTAssertEqual(roomProxy.reportContentReasonReceivedArguments?.eventID, itemID, "The event ID should match the content being reported.")
XCTAssertEqual(roomProxy.reportContentReasonReceivedArguments?.reason, reportReason, "The reason should match the user input.")
XCTAssertEqual(roomProxy.ignoreUserCallsCount, 0, "A call to ignore a user should not have been made.")
XCTAssertNil(roomProxy.ignoreUserReceivedUserID, "The sender shouldn't have been ignored.")
}
func testReportIgnoringSender() async {
// Given the report content view for some content.
let roomProxy = RoomProxyMock(with: .init(displayName: "test"))
roomProxy.reportContentReasonReturnValue = .success(())
roomProxy.ignoreUserReturnValue = .success(())
let viewModel = ReportContentViewModel(itemID: itemID,
senderID: senderID,
roomProxy: roomProxy)
// When reporting the content and also ignoring the user.
viewModel.state.bindings.reasonText = reportReason
viewModel.state.bindings.ignoreUser = true
viewModel.context.send(viewAction: .submit)
await Task.yield()
// Then the content should be reported, and the user should be ignored.
XCTAssertEqual(roomProxy.reportContentReasonCallsCount, 1, "The content should always be reported.")
XCTAssertEqual(roomProxy.reportContentReasonReceivedArguments?.eventID, itemID, "The event ID should match the content being reported.")
XCTAssertEqual(roomProxy.reportContentReasonReceivedArguments?.reason, reportReason, "The reason should match the user input.")
XCTAssertEqual(roomProxy.ignoreUserCallsCount, 1, "A call should have been made to ignore the sender.")
XCTAssertEqual(roomProxy.ignoreUserReceivedUserID, senderID, "The ignored user ID should match the sender.")
}
}