Add the same unsaved changes alerts that Android has. (#4803)

* Add an alert to Discard or Save when there are unsaved changes on the RoomDetailsEditScreen.

* Add an alert to Discard or Save when there are unsaved changes on the UserDetailsEditScreen.

* Add an alert to Discard or Save when there are unsaved changes on the SecurityAndPrivacyScreen.

* Update strings.
This commit is contained in:
Doug
2025-12-01 13:02:50 +00:00
committed by GitHub
parent a16f6ad3e4
commit 7496f30966
22 changed files with 409 additions and 96 deletions
@@ -71,7 +71,7 @@ class RoomDetailsEditScreenViewModelTests: XCTestCase {
XCTAssertFalse(context.viewState.canSave)
}
func testSaveShowsSheet() {
func testAvatarPickerShowsSheet() {
setupViewModel(roomProxyConfiguration: .init(name: "Some room", members: [.mockMeAdmin]))
context.name = "name"
XCTAssertFalse(context.showMediaSheet)
@@ -93,6 +93,47 @@ class RoomDetailsEditScreenViewModelTests: XCTestCase {
XCTAssertEqual(action, .saveFinished)
}
func testCancelWithoutChanges() async throws {
setupViewModel(roomProxyConfiguration: .init(name: "Some room", members: [.mockMeAdmin]))
XCTAssertFalse(context.viewState.canSave)
XCTAssertNil(context.alertInfo)
var deferred = deferFulfillment(viewModel.actions) { $0 == .cancel }
context.send(viewAction: .cancel)
try await deferred.fulfill()
XCTAssertNil(context.alertInfo)
}
func testCancelWithChangesAndDiscard() async throws {
setupViewModel(roomProxyConfiguration: .init(name: "Some room", members: [.mockMeAdmin]))
context.name = "name"
XCTAssertTrue(context.viewState.canSave)
XCTAssertNil(context.alertInfo)
context.send(viewAction: .cancel)
XCTAssertNotNil(context.alertInfo)
let deferred = deferFulfillment(viewModel.actions) { $0 == .cancel }
context.alertInfo?.secondaryButton?.action?() // Discard
try await deferred.fulfill()
}
func testCancelWithChangesAndSave() async throws {
setupViewModel(roomProxyConfiguration: .init(name: "Some room", members: [.mockMeAdmin]))
context.name = "name"
XCTAssertTrue(context.viewState.canSave)
XCTAssertNil(context.alertInfo)
context.send(viewAction: .cancel)
XCTAssertNotNil(context.alertInfo)
let deferred = deferFulfillment(viewModel.actions) { $0 == .saveFinished }
context.alertInfo?.primaryButton.action?() // Save
try await deferred.fulfill()
}
func testErrorShownOnFailedFetchOfMedia() async throws {
setupViewModel(roomProxyConfiguration: .init(name: "Some room", members: [.mockMeAdmin]))
viewModel.didSelectMediaUrl(url: .picturesDirectory)