-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix/alert/UI tests: Fix and complete UI tests for AlertScreen #68
Conversation
Added `com.linkedin.dexmaker:dexmaker-mockito-inline` dependency to enable Mockito inline for androidTests
Mocked `NavigationActions` using the correct dependencies and passed it as argument to `AlertScreen` instead of placeholder `rememberNavController`. Added a call to `Mockito.verify` to test for the correct navigation on click.
Added tests to check that an invalid alert is not submitted: * createInvalidAlertNoProduct * createInvalidAlertNoUrgencyLevel * createInvalidAlertNoLocation
Checked for a location before submitting the alert. Checked for product and urgency level before submitting: I used states (`productIsSelected` and `urgencyIsSelected`) and their setting function (`setProductIsSelected` and `setUrgencyIsSelected`). Clicking on the submission button with an invalid alert now shows a `Toast` with corresponding error message and does not navigate anywhere.
Had removed it for testing purposed.
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.
LGTM.
Look at the code comments. You need to check the top bar is displayed and bottom bar too.
Forgot to mention, in the AlertScreenTest
, it would be better to set the content to AlertScreen
once for all tests in the setUp()
function.
app/src/androidTest/java/com/android/periodpals/ui/alert/AlertScreenTest.kt
Show resolved
Hide resolved
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.
Summary
Great work! This PR effectively fixes the dependencies issues in order for Mockito to work on Android Tests, and thoroughly tests AlertScreens
.
Important
Code Quality
AlertScreenTest
: check comment- (
build.gradle.kts
: this whole file should be cleaned (lots of commented / repeated code), but not the scope of this PR)
Suggestions
- Future improvements: when data class
Alert
is implemented, remove the two variablesproductIsSelected
andurgencyIsSelected
and check if the fields are non-empty instead
app/src/androidTest/java/com/android/periodpals/ui/alert/AlertScreenTest.kt
Show resolved
Hide resolved
Thanks for your review @agonzalez-r ! I'll answer to some things that you pointed out quickly:
Can you create an issue about this? We'll get to it when we have time.
I don't believe this is relevant as checking basic properties about field content should be done at the View level and not by the ViewModel or Model because of performance issues (see this Ed post) |
Extracted `composeTestRule.setContent { ... }` to the `@Before setUp` function to avoid code duplication. This only works if the `setContent` call is the last thing done in `setUp`.
Added checks for the presence of the TopAppBar and BottomNavigationBar, as well as a check to see that the goBack button is not present.
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.
LGTM ! :)
Fix and complete UI tests for AlertScreen
Description
This PR introduces new tests for the Alert screen and fixes the old ones. It also fixes the problems pointed out by said new tests. It closes issue #64 and fixes part of #63 .
Changes
Added dependencies to make mockito work in androidTests, and properly mocked
NavigationActions
. Added verification of correct navigation in the old tests and created new tests to check that nothing happens when trying to submit an invalid Alert.Invalid alerts are ones which don't have a period product, urgency level and location selected.
Files
Added
None
Modified
app/build.gradle.kts
andgradle/libs.versions.toml
: add the missing dependencyapp/src/androidTest/java/com/android/periodpals/ui/alert/AlertScreenTest.kt
: modified and added testsapp/src/main/java/com/android/periodpals/ui/alert/AlertScreen.kt
: fixed problems pointed out by new testsRemoved
None
Dependencies Added
com.linkedin.dexmaker:dexmaker-mockito-inline
to make mockito work with androidTests. Had to removelibs.mockito.android
for androidTests as a consequenceTesting
All UI tests for
AlertScreen
pass. They should be complete enough.