Anki-Android icon indicating copy to clipboard operation
Anki-Android copied to clipboard

Test : Check Snackbar is displayed when the deck is created

Open neeldoshii opened this issue 10 months ago • 3 comments

Purpose / Description

This test checks whether the toast is shown to user after the deck has been created.

Fix

https://github.com/ankidroid/Anki-Android/blob/1c5a6b3c220d67a75dd4b4d78e1fc8a6cc4b4789/AnkiDroid/src/main/java/com/ichi2/anki/dialogs/CreateDeckDialog.kt#L50

Note : I am currently new towards writing test feel free to pin out or recommend the mistakes or advise while testing.

neeldoshii avatar Mar 31 '24 14:03 neeldoshii

Few Doubts: @david-allison

  1. @NeedsTest("Ensure a toast is shown on a successful action") I am not sure is this right or wrong. From what i observed creating a deck or renaming a deck we are showing snackbar not toast. I did wrote the unit test (robolectric) for checking whether it showed toast or not but it was giving me null everytime so i later got to know that we are calling snackbar on successful creation. Just like ShadowToast do we have ShadowSnackbar which does the work?

For now I have just fixed my old instrument test.

neeldoshii avatar Apr 02 '24 21:04 neeldoshii

If you annotate (git blame), you'll see the @NeedsTest was added in 2022 and you'll see the full context of why we wanted a test

  • https://github.com/ankidroid/Anki-Android/pull/12139

Screenshot 2024-04-03 at 14 02 09


Then look at the history of the class to understand how things have changed over time

See from the git history for the file: be85b46869c1fd2b943861fb65e66002721f274c (ShowSnackbarInsteadOfToast)


The intention of the @NeedsTest is that a user is provided feedback when an action is made.

So test for snackbars, not toasts, and as above, use /test/ rather than /androidTest

david-allison avatar Apr 03 '24 13:04 david-allison

Hi Maintainers, I am unsure of how can I check if the Snackbar is displayed or not in Roboelectric? There used to be shadowsnackbar but its now deprecated.

Can you share me what method do we have to test snackbar or any resource link?

neeldoshii avatar Apr 04 '24 19:04 neeldoshii

This should be in /test/, not in /androidTest

Closing this as stale to reduce our number of pending PRs. I was going to fix this up, but it needs a rewrite.

Feel free to recreate when this is done

david-allison avatar May 21 '24 18:05 david-allison