Skip to content

Farrish code review2#7

Open
jakeFarrish wants to merge 2 commits intomasterfrom
Farrish_CodeReview2
Open

Farrish code review2#7
jakeFarrish wants to merge 2 commits intomasterfrom
Farrish_CodeReview2

Conversation

@jakeFarrish
Copy link
Copy Markdown
Collaborator

Analysis of the program: RoomRemix2 is an interior design program that allows users to visually construct a rooms layout by adding, removing, and modify furniture in order to plan out functional living spaces.

Was the program available in UC GitHub on time? : Yes

Is the program documented/commented well enough for you to understand?: Yes

Does the program compile?: Yes

Rationale behind your changes: I noticed when logging into the application that the username prompt specifically asks for email for registration, but any string could be inputted and was accepted as the username. If the username is meant to be email specific then inputted strings should be checked for valid email format. I added a regular expression to the login function that checks for valid email format. I also added a test that checks if login data change is properly registered, and a test that checks if invalid username generates a username error. With these changes it will be possible to modify the username in login main activity so that only email formatted strings are accepted as a username, and will throw appropriate errors if the username is not an email. This will help keep the UI prompt consistent with accepted changed data inputs that are added to the database and help ensure that only emails are accepted as the username input for registration.

Reference:
https://developermemos.com/posts/validating-email-addresses-kotlin
https://www.stackhawk.com/blog/guide-to-security-in-kotlin/

Links to my Sprint 2 commits:

jakeFarrish/MedMapper@bdb9c17
jakeFarrish/MedMapper@911a129
jakeFarrish/MedMapper@f7a236a
jakeFarrish/MedMapper@9494fe0

Three specific technical concepts I learned:

I learned about regular expressions, which are good tools to use for pattern matching and text manipulation. Regular expressions can be used to make sure that string inputs match specific criteria, which can be useful when dealing with username and password formatting.

I learned about Observer, an interface used to observe changes in a LiveData object. I implemented observer to view changes to the LiveData username/password objects in the unit tests that were added.

I learned more about data binding, in this case login activity binding of UI components to the corresponding LoginActivity variables used in the LoginActivity logic.

Added instrumented tests for MainActivity
Added required dependencies for Mockito and updated other dependencies.
Added login data changed test
Added invalid username error generation test
Comment thread app/build.gradle
Comment on lines -40 to +54
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.core:core-ktx:1.9.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.8.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.core:core-ktx:+'
implementation 'androidx.annotation:annotation:1.3.0'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.4.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.1'
implementation 'androidx.core:core-ktx:1.9.0'
implementation 'androidx.annotation:annotation:1.6.0'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.5.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.mockito:mockito-core:3.12.4'
testImplementation 'androidx.arch.core:core-testing:2.2.0'
testImplementation 'org.mockito:mockito-inline:2.13.0'
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Careful when updating dependencies in an Android project. Many times, dependencies have dependencies on each other. Upgrading one can create a game of Whack-A-Mole.

Comment on lines +31 to +52
class MainActivityTest {
@Test
fun onClick_drawButtonBlack() {
ActivityScenario.launch(MainActivity::class.java)
onView(withId(draw)).perform(click())
assert(DrawView.currentColor == Color.BLACK)
}
@Test
fun onClick_eraserButtonWhite(){
ActivityScenario.launch(MainActivity::class.java)
onView(withId(eraser)).perform(click())
assert(DrawView.currentColor == Color.WHITE)
}
@Test
fun onClick_deleteButtonWorks(){
ActivityScenario.launch(MainActivity::class.java)
DrawView.pathList.add(Path())
DrawView.colorList.add(Color.BLACK)
onView(withId(delete)).perform(click())
assert(DrawView.pathList.isEmpty())
assert(DrawView.colorList.isEmpty())
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better unit test coverage is always a good idea.

Be cautious with UI tests, as they tend to be brittle. One small UI change can invalidate an entire series of tests.

Comment on lines +22 to +25
fun isValidEmail(email: String): Boolean {
val emailRegex = Regex("^\\w+([.-]?\\w+)*@\\w+([.-]?\\w+)*(\\.\\w{2,})+\$")
return email.matches(emailRegex)
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regex are a great way to validate user input!

@discospiff
Copy link
Copy Markdown

Good suggestions here.

  • Enhanced unit test code coverage
  • Use regex to validate user input
    I recommend that the group review these changes carefully, and consider merging this branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants