Updates following self review.

This commit is contained in:
Doug
2022-03-17 19:08:25 +00:00
parent dc57bcd55c
commit bad0648b7e
17 changed files with 86 additions and 61 deletions
@@ -84,13 +84,8 @@ final class OnboardingDisplayNameCoordinator: Coordinator, Presentable {
waitingIndicator = indicatorPresenter.present(.loading(label: VectorL10n.saving, isInteractionBlocking: true))
}
private func stopWaiting(error: Error? = nil) {
waitingIndicator?.cancel()
private func stopWaiting() {
waitingIndicator = nil
if let error = error {
onboardingDisplayNameViewModel.update(with: error)
}
}
private func setDisplayName(_ displayName: String) {
@@ -102,7 +97,8 @@ final class OnboardingDisplayNameCoordinator: Coordinator, Presentable {
self.completion?(self.parameters.userSession)
} failure: { [weak self] error in
guard let self = self else { return }
self.stopWaiting(error: error)
self.stopWaiting()
self.onboardingDisplayNameViewModel.processError(error as NSError?)
}
}
}
@@ -52,14 +52,13 @@ class OnboardingDisplayNameViewModel: OnboardingDisplayNameViewModelType, Onboar
}
}
func update(with error: Error) {
if let error = error as NSError? {
state.bindings.alertInfo = AlertInfo(error: error)
}
func processError(_ error: NSError?) {
state.bindings.alertInfo = AlertInfo(error: error)
}
// MARK: - Private
/// Checks for a display name that exceeds 256 characters and updates the footer error if needed.
private func validateDisplayName() {
if state.bindings.displayName.count > 256 {
guard state.validationErrorMessage == nil else { return }
@@ -22,5 +22,7 @@ protocol OnboardingDisplayNameViewModelProtocol {
@available(iOS 14, *)
var context: OnboardingDisplayNameViewModelType.Context { get }
func update(with error: Error)
/// Update the view model to show that an error has occurred.
/// - Parameter error: The error to be displayed or `nil` to display a generic alert.
func processError(_ error: NSError?)
}
@@ -49,6 +49,10 @@ class OnboardingDisplayNameUITests: MockScreenTest {
let footer = app.staticTexts["textFieldFooter"]
XCTAssertTrue(footer.exists, "The textfield's footer should always be shown.")
XCTAssertEqual(footer.label, VectorL10n.onboardingDisplayNameHint, "The footer should display a hint when no text is set.")
let saveButton = app.buttons["saveButton"]
XCTAssertTrue(saveButton.exists, "There should be a save button.")
XCTAssertFalse(saveButton.isEnabled, "The save button should not be enabled.")
}
func verifyDisplayName(displayName: String) {
@@ -57,6 +61,10 @@ class OnboardingDisplayNameUITests: MockScreenTest {
XCTAssertEqual(textField.value as? String, displayName, "When a name has been set, it should show in the textfield.")
XCTAssertEqual(textField.placeholderValue, VectorL10n.onboardingDisplayNamePlaceholder, "The textfield's placeholder should be set.")
let saveButton = app.buttons["saveButton"]
XCTAssertTrue(saveButton.exists, "There should be a save button.")
XCTAssertTrue(saveButton.isEnabled, "The save button should be enabled.")
let footer = app.staticTexts["textFieldFooter"]
XCTAssertTrue(footer.exists, "The textfield's footer should always be shown.")
XCTAssertEqual(footer.label, VectorL10n.onboardingDisplayNameHint, "The footer should display a hint when an acceptable name is entered.")
@@ -71,5 +79,9 @@ class OnboardingDisplayNameUITests: MockScreenTest {
let footer = app.staticTexts["textFieldFooter"]
XCTAssertTrue(footer.exists, "The textfield's footer should always be shown.")
XCTAssertEqual(footer.label, VectorL10n.onboardingDisplayNameMaxLength, "The footer should display an error when the display name is too long.")
let saveButton = app.buttons["saveButton"]
XCTAssertTrue(saveButton.exists, "There should be a save button.")
XCTAssertFalse(saveButton.isEnabled, "The save button should not be enabled.")
}
}
@@ -21,10 +21,6 @@ import Combine
@available(iOS 14.0, *)
class OnboardingDisplayNameViewModelTests: XCTestCase {
private enum Constants {
static let displayName = "Alice"
}
var viewModel: OnboardingDisplayNameViewModel!
var context: OnboardingDisplayNameViewModelType.Context!
@@ -111,7 +111,8 @@ struct OnboardingDisplayNameScreen: View {
viewModel.send(viewAction: .save)
}
.buttonStyle(PrimaryActionButtonStyle())
.disabled(viewModel.displayName.isEmpty)
.disabled(viewModel.displayName.isEmpty || viewModel.viewState.validationErrorMessage != nil)
.accessibilityIdentifier("saveButton")
Button { viewModel.send(viewAction: .skip) } label: {
Text(VectorL10n.onboardingPersonalizationSkip)