Issue with completion feedback after studying unburied cards from Congrats

Aperta
#23,751 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
android, kotlin
Ambito
mobile, testing

Direzione di ricerca

The body is a patch adding AnkiDroid/src/test/java/com/ichi2/anki/UnburyStudyCompletionTest.kt, marked @ExistingIssue. Start by running that test, then follow the chain it drives: CongratsPage's "unbury" bridge command, StudyOptionsActivity forwarding the result, and Reviewer finishing. Done means the second review reopens CongratsPage and the @ExistingIssue annotation can be removed.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

code-scan Needs Triage
Subject: [PATCH] [EXISTING] Show completion feedback after studying unburied cards from Congrats
---
Index: AnkiDroid/src/test/java/com/ichi2/anki/UnburyStudyCompletionTest.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/AnkiDroid/src/test/java/com/ichi2/anki/UnburyStudyCompletionTest.kt b/AnkiDroid/src/test/java/com/ichi2/anki/UnburyStudyCompletionTest.kt
new file mode 100644
--- /dev/null	(revision 7d325623fefa9fdcc5fe0099b9c9027db6739614)
+++ b/AnkiDroid/src/test/java/com/ichi2/anki/UnburyStudyCompletionTest.kt	(revision 7d325623fefa9fdcc5fe0099b9c9027db6739614)
@@ -0,0 +1,115 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+package com.ichi2.anki
+
+import android.content.Intent
+import android.widget.Button
+import androidx.core.content.edit
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import anki.scheduler.CardAnswer.Rating
+import com.ichi2.anki.CollectionManager.withCol
+import com.ichi2.anki.pages.CongratsPage
+import com.ichi2.anki.settings.Prefs
+import com.ichi2.testutils.rules.ExistingIssue
+import com.ichi2.testutils.rules.ExistingIssueRule
+import kotlinx.coroutines.test.advanceUntilIdle
+import org.junit.Rule
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.robolectric.Shadows.shadowOf
+import kotlin.test.assertEquals
+import kotlin.test.assertNotNull
+import kotlin.test.assertTrue
+
+@RunWith(AndroidJUnit4::class)
+class UnburyStudyCompletionTest : RobolectricTest() {
+    @get:Rule(order = Int.MIN_VALUE)
+    val existingIssue = ExistingIssueRule()
+
+    /**
+     * Using Unbury on Congrats and studying the unburied card should return to Congrats when
+     * the deck is finished again. Study Options forwards an activity result, but the flow
+     * currently starts without registering a receiver, so the second review closes silently.
+     */
+    @Test
+    @ExistingIssue
+    fun `finishing a review after unburying from Congrats reopens Congrats`() =
+        runTest {
+            Prefs.isNewStudyScreenEnabled = false
+            getPreferences().edit { putBoolean("new_congrats_screen", true) }
+            updateDeckConfig(col.decks.selected()) { autoplay = false }
+            val cardId = addBasicNote().firstCard().id
+            // A single manually buried card gives Congrats its Unbury action without a choice dialog.
+            withCol { sched.buryCards(listOf(cardId), manual = true) }
+            val congrats =
+                startActivityNormallyOpenCollectionWithIntent(
+                    SingleFragmentActivity::class.java,
+                    CongratsPage.getIntent(targetContext),
+                )
+            val congratsShadow = shadowOf(congrats)
+            val page = congrats.fragment as CongratsPage
+            // Run the actual bridge command that the Congrats page sends for Unbury.
+            page.bridgeCommands.getValue("unbury").invoke()
+            advanceRobolectricLooperUntil {
+                advanceUntilIdle()
+                congratsShadow.peekNextStartedActivity() != null
+            }
+            val studyOptionsLaunch = assertNotNull(congratsShadow.nextStartedActivityForResult)
+            assertEquals(StudyOptionsActivity::class.java.name, studyOptionsLaunch.intent.component?.className)
+            congratsShadow.clearNextStartedActivities()
+
+            val studyOptions =
+                startActivityNormallyOpenCollectionWithIntent(
+                    StudyOptionsActivity::class.java,
+                    studyOptionsLaunch.intent,
+                )
+            val studyOptionsShadow = shadowOf(studyOptions)
+            advanceRobolectricLooperUntil {
+                advanceUntilIdle()
+                studyOptions.findViewById<Button>(R.id.studyoptions_start)?.text ==
+                    studyOptions.getString(CommonString.studyoptions_start)
+            }
+            assertTrue(studyOptions.findViewById<Button>(R.id.studyoptions_start).performClick())
+            advanceRobolectricLooperUntil {
+                advanceUntilIdle()
+                studyOptionsShadow.peekNextStartedActivity() != null
+            }
+            val reviewLaunch = assertNotNull(studyOptionsShadow.nextStartedActivityForResult)
+            assertEquals(Reviewer::class.java.name, reviewLaunch.intent.component?.className)
+            studyOptionsShadow.clearNextStartedActivities()
+
+            val reviewer = startActivityNormallyOpenCollectionWithIntent(Reviewer::class.java, reviewLaunch.intent)
+            advanceRobolectricLooperUntil { reviewer.currentCardId == cardId }
+            reviewer.answerCardInner(Rating.EASY)
+            reviewer.updateCardAndRedraw()
+            advanceUntilIdle()
+            assertTrue(reviewer.isFinishing)
+
+            // Robolectric starts each activity explicitly. Deliver a registered activity result
+            // as Android would, including when Study Options forwards its caller's result.
+            val reviewerShadow = shadowOf(reviewer)
+            if (reviewLaunch.requestCode >= 0) {
+                studyOptions.activityResultRegistry.dispatchResult(
+                    reviewLaunch.requestCode,
+                    reviewerShadow.resultCode,
+                    reviewerShadow.resultIntent,
+                )
+            } else if (
+                reviewLaunch.intent.flags and Intent.FLAG_ACTIVITY_FORWARD_RESULT != 0 &&
+                studyOptionsLaunch.requestCode >= 0
+            ) {
+                congrats.activityResultRegistry.dispatchResult(
+                    studyOptionsLaunch.requestCode,
+                    reviewerShadow.resultCode,
+                    reviewerShadow.resultIntent,
+                )
+            }
+            advanceUntilIdle()
+            advanceRobolectricLooper()
+
+            // The saved launch chain has no receiver on the buggy revision, so none of these
+            // activities starts a second Congrats page when the reviewed card runs out.
+            val next = listOf(reviewerShadow, studyOptionsShadow, congratsShadow).firstNotNullOfOrNull { it.nextStartedActivity }
+            assertEquals(CongratsPage::class.java.name, next?.getStringExtra(SingleFragmentActivity.EXTRA_FRAGMENT_NAME))
+        }
+}
Lingua principale
Kotlin
Stelle
12.3k
Fork
3.1k
Merge medio
2g 1h
PR unite (30g)
311

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ankidroid/Anki-Android

Tutte le issue di ankidroid/Anki-Android

Issue simili

Altre issue su Kotlin

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.