-
Notifications
You must be signed in to change notification settings - Fork 28
[#139] Add a validation to enable/disable the save button of the Edit Profile view #143
base: develop
Are you sure you want to change the base?
Conversation
@@ -79,7 +86,7 @@ struct ProfileEditor: View { | |||
self.profileViewModel.inActivity = true | |||
// make network call to update profile | |||
self.updateProfile() | |||
}) | |||
}.disabled(self.canSave == false)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can do something like .disabled(editProfileData.name.isEmpty)
var canSave:Bool { | ||
guard let name = $editProfileData.name.wrappedValue, name.isEmpty == false else { | ||
return false | ||
} | ||
return true | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We won't need this code then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i made this way thinking about future proof, if later need to add another required field or another validation to enable/disable the button.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay. In that case, we can define this computed property like this: 'return editProfileData.name.isEmpty'
Second, please add a unit test for this new computed property.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
- make canSave computed property more clean
func testCanSaveProfileWithoutNameAndFail() throws { | ||
// Profile Service | ||
let profileService: ProfileService = ProfileAPI(urlSession: urlSession) | ||
|
||
// View Model | ||
let sampleData = ProfileModel.ProfileData(id: 0, name: "", username: "", email: "") | ||
let profileVM = ProfileViewModel() | ||
profileVM.saveProfile(profile: sampleData) | ||
|
||
// Profile Editor View | ||
let profileEditor = ProfileEditor(profileService: profileService, profileViewModel: profileVM) | ||
|
||
XCTAssertFalse(profileEditor.canSave) | ||
} | ||
|
||
func testCanSaveProfileWithNameAndSucceed() throws { | ||
// Profile Service | ||
let profileService: ProfileService = ProfileAPI(urlSession: urlSession) | ||
|
||
// View Model | ||
let sampleData = ProfileModel.ProfileData(id: 0, name: "name", username: "", email: "") | ||
let profileVM = ProfileViewModel() | ||
profileVM.saveProfile(profile: sampleData) | ||
|
||
// Profile Editor View | ||
let profileEditor = ProfileEditor(profileService: profileService, profileViewModel: profileVM) | ||
|
||
XCTAssertTrue(profileEditor.canSave) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably don't need a throwing function. Also, can we improve the naming of these test functions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok. i changed the name based on another test function that already exists
…e save button on the edit profile view and merge into a single method the scenarios
Please upload smaller files for the screenshots. |
@@ -12,6 +12,10 @@ struct ProfileEditor: View { | |||
@State var editProfileData = ProfileViewModel().getEditProfileData() | |||
@ObservedObject var profileViewModel = ProfileViewModel() | |||
|
|||
var canSave:Bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change name to enableSaveButton/disableSaveButton. More descriptive.
Description
Add a validation to enable/disable the save button of the Edit Profile view based on the state of the name field.
Fixes #139
Type of Change:
Code/Quality Assurance Only
How Has This Been Tested?
In the Edit Profile view, empty the name field and the save button should be disabled.
Checklist:
Code/Quality Assurance Only