mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:55:59 +00:00
Leave Room (#699)
* created the row in the view and the alert, and added the new function to the RoomProxy * fixed an issue with the alert function * handling the navigation * fixed a bug with the detail coordinators being dismissed incorrectly when inside a stack * implementation completed * replaced UI screenshots * added a test for the fixed bug of the coordinators * trying to increase the wait time for the expectation * improved the test * improved the buttons UI * uploading artifacts for unit tests * added result bundle true * improved the tests * added a new test * pr suggestions * updating mock * PR suggestions * improved tests * fixed UI tests * pr should be ready now * removed testing code * reduced complexity * fixed test * added a an assert to the new test case * more tests and messages cases * pr comments addressed * completed
This commit is contained in:
@@ -255,6 +255,32 @@ class NavigationSplitCoordinatorTests: XCTestCase {
|
||||
}
|
||||
waitForExpectations(timeout: 1.0)
|
||||
}
|
||||
|
||||
func testSetRootDetailToNilAfterPoppingToRoot() {
|
||||
navigationSplitCoordinator = NavigationSplitCoordinator(placeholderCoordinator: SomeTestCoordinator())
|
||||
let sidebarCoordinator = NavigationStackCoordinator()
|
||||
sidebarCoordinator.setRootCoordinator(SomeTestCoordinator())
|
||||
|
||||
let detailCoordinator = NavigationStackCoordinator()
|
||||
detailCoordinator.setRootCoordinator(SomeTestCoordinator())
|
||||
detailCoordinator.push(SomeTestCoordinator())
|
||||
|
||||
navigationSplitCoordinator.setSidebarCoordinator(sidebarCoordinator)
|
||||
navigationSplitCoordinator.setDetailCoordinator(detailCoordinator)
|
||||
|
||||
let expectation = expectation(description: "Details coordinator should be nil, and the compact layout revert to the sidebar root")
|
||||
DispatchQueue.main.async {
|
||||
detailCoordinator.popToRoot(animated: true)
|
||||
self.navigationSplitCoordinator.setDetailCoordinator(nil)
|
||||
DispatchQueue.main.async {
|
||||
XCTAssertNil(self.navigationSplitCoordinator.detailCoordinator)
|
||||
self.assertCoordinatorsEqual(self.navigationSplitCoordinator.compactLayoutRootCoordinator, sidebarCoordinator.rootCoordinator)
|
||||
XCTAssertTrue(self.navigationSplitCoordinator.compactLayoutStackModules.isEmpty)
|
||||
expectation.fulfill()
|
||||
}
|
||||
}
|
||||
waitForExpectations(timeout: 1.0)
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ import XCTest
|
||||
@MainActor
|
||||
class ReportContentScreenViewModelTests: XCTestCase {
|
||||
func testInitialState() {
|
||||
let viewModel = ReportContentViewModel(itemID: "test-id", roomProxy: MockRoomProxy(displayName: "test"))
|
||||
let viewModel = ReportContentViewModel(itemID: "test-id", roomProxy: RoomProxyMock(with: .init(displayName: "test")))
|
||||
let context = viewModel.context
|
||||
|
||||
XCTAssertEqual(context.reasonText, "")
|
||||
|
||||
@@ -19,4 +19,65 @@ import XCTest
|
||||
@testable import ElementX
|
||||
|
||||
@MainActor
|
||||
class RoomDetailsScreenViewModelTests: XCTestCase { }
|
||||
class RoomDetailsScreenViewModelTests: XCTestCase {
|
||||
var viewModel: RoomDetailsViewModelProtocol!
|
||||
var roomProxyMock: RoomProxyMock!
|
||||
var context: RoomDetailsViewModelType.Context { viewModel.context }
|
||||
|
||||
override func setUp() {
|
||||
roomProxyMock = RoomProxyMock(with: .init(displayName: "Test"))
|
||||
viewModel = RoomDetailsViewModel(roomProxy: roomProxyMock, mediaProvider: MockMediaProvider())
|
||||
}
|
||||
|
||||
func testLeaveRoomTappedWhenPublic() async {
|
||||
roomProxyMock = RoomProxyMock(with: .init(displayName: "Test", isPublic: true, members: [.mockBob, .mockAlice]))
|
||||
viewModel = RoomDetailsViewModel(roomProxy: roomProxyMock, mediaProvider: MockMediaProvider())
|
||||
context.send(viewAction: .processTapLeave)
|
||||
await Task.yield()
|
||||
XCTAssertEqual(context.leaveRoomAlertItem?.state, .public)
|
||||
XCTAssertEqual(context.leaveRoomAlertItem?.subtitle, ElementL10n.roomDetailsLeaveRoomAlertSubtitle)
|
||||
}
|
||||
|
||||
func testLeavRoomTappedWhenRoomNotPublic() async {
|
||||
roomProxyMock = RoomProxyMock(with: .init(displayName: "Test", isPublic: false, members: [.mockBob, .mockAlice]))
|
||||
viewModel = RoomDetailsViewModel(roomProxy: roomProxyMock, mediaProvider: MockMediaProvider())
|
||||
context.send(viewAction: .processTapLeave)
|
||||
await Task.yield()
|
||||
XCTAssertEqual(context.leaveRoomAlertItem?.state, .private)
|
||||
XCTAssertEqual(context.leaveRoomAlertItem?.subtitle, ElementL10n.roomDetailsLeavePrivateRoomAlertSubtitle)
|
||||
}
|
||||
|
||||
func testLeaveRoomTappedWithLessThanTwoMembers() async {
|
||||
context.send(viewAction: .processTapLeave)
|
||||
await Task.yield()
|
||||
XCTAssertEqual(context.leaveRoomAlertItem?.state, .empty)
|
||||
XCTAssertEqual(context.leaveRoomAlertItem?.subtitle, ElementL10n.roomDetailsLeaveEmptyRoomAlertSubtitle)
|
||||
}
|
||||
|
||||
func testLeaveRoomSuccess() async {
|
||||
roomProxyMock.leaveRoomClosure = {
|
||||
.success(())
|
||||
}
|
||||
viewModel.callback = { action in
|
||||
switch action {
|
||||
case .leftRoom:
|
||||
break
|
||||
default:
|
||||
XCTFail("leftRoom expected")
|
||||
}
|
||||
}
|
||||
context.send(viewAction: .confirmLeave)
|
||||
await Task.yield()
|
||||
XCTAssertEqual(roomProxyMock.leaveRoomCallsCount, 1)
|
||||
}
|
||||
|
||||
func testLeaveRoomError() async {
|
||||
roomProxyMock.leaveRoomClosure = {
|
||||
.failure(.failedLeavingRoom)
|
||||
}
|
||||
context.send(viewAction: .confirmLeave)
|
||||
await Task.yield()
|
||||
XCTAssertEqual(roomProxyMock.leaveRoomCallsCount, 1)
|
||||
XCTAssertNotNil(context.alertInfo)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user