Skip to content
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

Merged
merged 10 commits into from
Oct 28, 2024

Conversation

charliemangano
Copy link
Contributor

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 and gradle/libs.versions.toml: add the missing dependency
  • app/src/androidTest/java/com/android/periodpals/ui/alert/AlertScreenTest.kt: modified and added tests
  • app/src/main/java/com/android/periodpals/ui/alert/AlertScreen.kt: fixed problems pointed out by new tests

Removed

None

Dependencies Added

Testing

All UI tests for AlertScreen pass. They should be complete enough.

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.
@charliemangano charliemangano added the bug Something isn't working label Oct 27, 2024
@charliemangano charliemangano self-assigned this Oct 27, 2024
@charliemangano charliemangano linked an issue Oct 27, 2024 that may be closed by this pull request
2 tasks
@charliemangano charliemangano marked this pull request as ready for review October 27, 2024 17:53
Had removed it for testing purposed.
@francelu francelu self-requested a review October 27, 2024 22:07
@charliemangano charliemangano mentioned this pull request Oct 28, 2024
11 tasks
Copy link
Contributor

@francelu francelu left a 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.

Copy link
Member

@agonzalez-r agonzalez-r left a 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 variables productIsSelected and urgencyIsSelected and check if the fields are non-empty instead

@charliemangano
Copy link
Contributor Author

Thanks for your review @agonzalez-r ! I'll answer to some things that you pointed out quickly:

  • (build.gradle.kts: this whole file should be cleaned (lots of commented / repeated code), but not the scope of this PR)

Can you create an issue about this? We'll get to it when we have time.

  • Future improvements: when data class Alert is implemented, remove the two variables productIsSelected and urgencyIsSelected and check if the fields are non-empty instead

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.
Copy link
Contributor

@francelu francelu left a comment

Choose a reason for hiding this comment

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

LGTM ! :)

@charliemangano charliemangano merged commit 2eea42f into main Oct 28, 2024
2 checks passed
@charliemangano charliemangano deleted the fix/alert/ui-tests branch October 28, 2024 15:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix UI tests for M1: Alert
3 participants