test(GradeNowDialog): add UI tests for the GradeNowDialog.kt#20445
test(GradeNowDialog): add UI tests for the GradeNowDialog.kt#20445david-allison merged 1 commit intoankidroid:mainfrom
Conversation
|
First PR! 🚀 We sincerely appreciate that you have taken the time to propose a change to AnkiDroid! Please have patience with us as we are all volunteers - we will get to this as soon as possible. |
There was a problem hiding this comment.
Pull request overview
Adds Android instrumentation coverage for GradeNowDialog and removes the corresponding @NeedsTest markers in production code.
Changes:
- Removed
@NeedsTestannotations fromGradeNowDialog.kt. - Added
GradeNowDialogTestinstrumentation tests for dialog visibility and basic interactions.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
AnkiDroid/src/main/java/com/ichi2/anki/dialogs/GradeNowDialog.kt |
Removes @NeedsTest markers previously tracking missing UI coverage. |
AnkiDroid/src/androidTest/java/com/ichi2/anki/dialogs/GradeNowDialogTest.kt |
Adds Espresso tests for dialog title/options visibility, click-to-dismiss, and empty-selection behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
7f794d9 to
536df18
Compare
david-allison
left a comment
There was a problem hiding this comment.
We use unit tests, typically with Robolectric by default, could you move these tests to /test instead of /androidTest
working on it. Any other suggestions would be helpful as I don't have much experience with tests. |
536df18 to
43151d5
Compare
|
Hi @BinaryBhaskar 👋 I noticed this pr is related to the @NeedsTest issue (#13283 ) but the issue number isn't mentioned in the PR description. |
Thanks for the suggestion. ❤️ |
|
@david-allison |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
43151d5 to
e96ea60
Compare
|
Hi @BinaryBhaskar 👋 I noticed the failing check seems to be in the Codecov step, and the logs show a GPG verification error ( Not sure if its related to the changes , but sometimes rerunning the workflow or pushing an empty commit can fix it. |
e96ea60 to
95e00bf
Compare
|
@DoomsCoder Thanks, re-pushed and all the tests are fine now. |
Glad it helped!😊 |
david-allison
left a comment
There was a problem hiding this comment.
We have a few helpers in our tests to reduce verbosity.
Index: AnkiDroid/src/test/java/com/ichi2/anki/dialogs/GradeNowDialogTest.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/AnkiDroid/src/test/java/com/ichi2/anki/dialogs/GradeNowDialogTest.kt b/AnkiDroid/src/test/java/com/ichi2/anki/dialogs/GradeNowDialogTest.kt
--- a/AnkiDroid/src/test/java/com/ichi2/anki/dialogs/GradeNowDialogTest.kt (revision 95e00bf3d2229ef11e75930f9d47157b938d0d7d)
+++ b/AnkiDroid/src/test/java/com/ichi2/anki/dialogs/GradeNowDialogTest.kt (date 1773584546507)
@@ -37,109 +37,88 @@
/** Tests [GradeNowDialog] */
@RunWith(RobolectricTestRunner::class)
class GradeNowDialogTest : RobolectricTest() {
- private lateinit var activityScenario: ActivityScenario<CardBrowser>
-
- override fun setUp() {
- super.setUp()
-
- ensureCollectionLoadIsSynchronous()
-
- activityScenario =
- ActivityScenario.launch(CardBrowser::class.java).apply {
- moveToState(Lifecycle.State.RESUMED)
- }
- }
-
- override fun tearDown() {
- super.tearDown()
- activityScenario.close()
- }
-
@Test
fun dialogLoads() {
- val note = addBasicNote()
- val cardId = note.cards(col)[0].id
-
- lateinit var translatedTitle: String
+ val cardId = addBasicNote().firstCard().id
+
+ val cardBrowser = super.startRegularActivity<CardBrowser>()
- activityScenario.onActivity { activity ->
- translatedTitle =
- TR
- .actionsGradeNow()
- .toSentenceCase(activity, R.string.sentence_grade_now)
+ val translatedTitle =
+ TR
+ .actionsGradeNow()
+ .toSentenceCase(cardBrowser, R.string.sentence_grade_now)
- GradeNowDialog.showDialog(activity, listOf(cardId))
- }
+ GradeNowDialog.showDialog(cardBrowser, listOf(cardId))
onView(withText(translatedTitle))
.inRoot(isDialog())
.check(matches(isDisplayed()))
}
-
- @Test
- fun showsAllGradeOptions() {
- val note = addBasicNote()
- val cardId = note.cards(col)[0].id
-
- activityScenario.onActivity { activity ->
- GradeNowDialog.showDialog(activity, listOf(cardId))
- }
-
- onView(withText(TR.studyingAgain()))
- .inRoot(isDialog())
- .check(matches(isDisplayed()))
-
- onView(withText(TR.studyingHard()))
- .inRoot(isDialog())
- .check(matches(isDisplayed()))
-
- onView(withText(TR.studyingGood()))
- .inRoot(isDialog())
- .check(matches(isDisplayed()))
-
- onView(withText(TR.studyingEasy()))
- .inRoot(isDialog())
- .check(matches(isDisplayed()))
- }
-
- @Test
- fun clickingGradeDismissesDialog() {
- val note = addBasicNote()
- val cardId = note.cards(col)[0].id
-
- lateinit var translatedTitle: String
-
- activityScenario.onActivity { activity ->
- translatedTitle =
- TR
- .actionsGradeNow()
- .toSentenceCase(activity, R.string.sentence_grade_now)
-
- GradeNowDialog.showDialog(activity, listOf(cardId))
- }
-
- onView(withText(TR.studyingGood()))
- .inRoot(isDialog())
- .perform(click())
-
- onView(withText(translatedTitle))
- .check(doesNotExist())
- }
-
- @Test
- fun dialogNotShownIfNoCardsSelected() {
- lateinit var translatedTitle: String
-
- activityScenario.onActivity { activity ->
- translatedTitle =
- TR
- .actionsGradeNow()
- .toSentenceCase(activity, R.string.sentence_grade_now)
-
- GradeNowDialog.showDialog(activity, emptyList())
- }
-
- onView(withText(translatedTitle))
- .check(doesNotExist())
- }
+//
+// @Test
+// fun showsAllGradeOptions() {
+// val note = addBasicNote()
+// val cardId = note.cards(col)[0].id
+//
+// activityScenario.onActivity { activity ->
+// GradeNowDialog.showDialog(activity, listOf(cardId))
+// }
+//
+// onView(withText(TR.studyingAgain()))
+// .inRoot(isDialog())
+// .check(matches(isDisplayed()))
+//
+// onView(withText(TR.studyingHard()))
+// .inRoot(isDialog())
+// .check(matches(isDisplayed()))
+//
+// onView(withText(TR.studyingGood()))
+// .inRoot(isDialog())
+// .check(matches(isDisplayed()))
+//
+// onView(withText(TR.studyingEasy()))
+// .inRoot(isDialog())
+// .check(matches(isDisplayed()))
+// }
+//
+// @Test
+// fun clickingGradeDismissesDialog() {
+// val note = addBasicNote()
+// val cardId = note.cards(col)[0].id
+//
+// lateinit var translatedTitle: String
+//
+// activityScenario.onActivity { activity ->
+// translatedTitle =
+// TR
+// .actionsGradeNow()
+// .toSentenceCase(activity, R.string.sentence_grade_now)
+//
+// GradeNowDialog.showDialog(activity, listOf(cardId))
+// }
+//
+// onView(withText(TR.studyingGood()))
+// .inRoot(isDialog())
+// .perform(click())
+//
+// onView(withText(translatedTitle))
+// .check(doesNotExist())
+// }
+//
+// @Test
+// fun dialogNotShownIfNoCardsSelected() {
+// lateinit var translatedTitle: String
+//
+// activityScenario.onActivity { activity ->
+// translatedTitle =
+// TR
+// .actionsGradeNow()
+// .toSentenceCase(activity, R.string.sentence_grade_now)
+//
+// GradeNowDialog.showDialog(activity, emptyList())
+// }
+//
+// onView(withText(translatedTitle))
+// .check(doesNotExist())
+// }
}95e00bf to
a62f07a
Compare
|
@david-allison thanks for the review.. I've now updated the commit. you may review it again. |
david-allison
left a comment
There was a problem hiding this comment.
Beautiful, thanks so much
Purpose / Description
GradeNowDialog needed some unit tests to be implemented to check if UI handling and menu displaying with options work as intended.
Fixes
@NeedsTest in the GradeNowDialog.kt file, a part of issue no. #13283
Approach
Adds Unit Tests for the following:
Removed @NeedsTest from GradeNowDialog.kt
How Has This Been Tested?
Emulator: Android Studio Pixel 9 Pro
Checklist
Please, go through these checks before submitting the PR.