test(DeckPicker): implement FAB visibility and expansion tests for DeckPickerFloatingActionMenu#20772
Conversation
david-allison
left a comment
There was a problem hiding this comment.
Prefer unit tests over Android tests
I have looked into converting this for unit test using Robolectric. But floatingActionMenu is private in DeckPicker so I can't directly call hideFloatingActionButton() or showFloatingActionButton() to set up test state. Could you advise on the best approach should I make these methods accessible for testing, or is there a different entry point you have in mind? |
|
|
Hi, |
|
Sorry, I won't have the capacity to dive into this one. |
No worries at all, |
|
And I have done further investigation: I explored testing DeckPickerFloatingActionMenu in isolation but showFloatingActionButton is private and constructor requires ActivityHomescreenBinding and DeckPicker making isolation difficult too. Would making showFloatingActionButton internal with @VisibleForTesting be acceptable? |
|
Hi @MandeepT19 , regarding the @NeedsTest annotation, this part of the cleanup tracked in issue #13283. As @david-allison noted in the main issue, we should prioritise unit test over Android instrumented tests to keep the build fast. Could you take quick look and maybe link that issue in your PR description? |
|
Thanks @DoomsCoder, |
|
Hi @david-allison, In the previous blocker it was Two tests now pass on JVM without an emulator: I have also marked floatingActionMenu as internal with |
d23be82 to
e3766e0
Compare
e3766e0 to
e0ac735
Compare
|
Hello 👋, this PR has had no activity for more than 2 weeks and needs a reply from the author. If you think this is a mistake please comment and ping a maintainer to get this merged ASAP! Thanks for contributing! You have 7 days until this gets closed automatically |
|
Hi @david-allison, Just a reminder for getting this reviewed, if you you are free for it as its been nearly 2 weeks since the code is updated with instructions |
|
Sorry for the delay (in future, please ping, I have far too many reviews, but it's unusual to be waiting more than a couple of days), but I don't understand. This doesn't seem to test either of the methods:
The implementation of these tests are available: a3ce935 |
Purpose / Description
Implements the unit tests requested by the @NeedsTest("reimplement: doubleTapAddsNote; singleTapTogglesFab") annotation on DeckPickerFloatingActionMenu.
Fixes
Part of #13283
@NeedsTest("reimplement: doubleTapAddsNote; singleTapTogglesFab") annotation in DeckPickerFloatingActionMenuTest
Approach
Identified that
@Config(application = EmptyApplication::class)was preventing AnkiDroidApp.isInitialized from being true which caused showedActivityFailedScreen to exit onCreate early. Removing EmptyApplication from@Configfixed this. Added two Robolectric unit tests in /test and marked floatingActionMenu as internal with@VisibleForTestingin DeckPicker.kt as suggested.showFloatingActionButtonMakesFabVisible verifies FAB is VISIBLE after showFloatingActionButton() is called
hideFloatingActionButtonMakesFabGone verifies FAB is GONE after hideFloatingActionButton() is called
Note: The doubleTapAddsNote is not covered here as there is no double tap test utility exists in the current test infrastructure and I am open to guidance if needed.
How Has This Been Tested?
Both tests pass via Robolectric on JVM without needing an emulator.
Checklist
Please, go through these checks before submitting the PR.