Restoring a changed queue reveals the next answer

Aperta
#23,759 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
Mezza giornata
Idoneità per principianti
55/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
android, kotlin
Ambito
mobile

Direzione di ricerca

The payload names a Robolectric test at AnkiDroid/src/test/java/com/ichi2/anki/ui/windows/reviewer/RestoredChangedCardTest.kt that restores a reviewer whose previous card was suspended. Start with ReviewerViewModel, particularly how it handles the saved showingAnswer and last_shown_card_id state in its restore path and onPageFinished. Done means the test passes: the restored model reports the next card's id and its question is shown, not the answer.

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

Descrizione

code-scan

Assisted-by: GPT-6.1-Terra xhigh & GPT-6.2-Sol xhigh & GPT-6.2-Astra xhigh

Subject: [EXISTING] Restoring a changed queue reveals the next answer

When the previously shown card leaves the queue while stopped, restoring the reviewer reveals another card's answer immediately.

---
diff --git a/AnkiDroid/src/test/java/com/ichi2/anki/ui/windows/reviewer/RestoredChangedCardTest.kt b/AnkiDroid/src/test/java/com/ichi2/anki/ui/windows/reviewer/RestoredChangedCardTest.kt
new file mode 100644
index 0000000000..1ec54c1911
--- /dev/null
+++ b/AnkiDroid/src/test/java/com/ichi2/anki/ui/windows/reviewer/RestoredChangedCardTest.kt
@@ -0,0 +1,36 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+package com.ichi2.anki.ui.windows.reviewer
+
+import androidx.lifecycle.SavedStateHandle
+import androidx.lifecycle.ViewModelStore
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import com.ichi2.anki.RobolectricTest
+import kotlinx.coroutines.test.advanceUntilIdle
+import org.junit.Test
+import org.junit.runner.RunWith
+import kotlin.test.assertEquals
+import kotlin.test.assertFalse
+
+@RunWith(AndroidJUnit4::class)
+class RestoredChangedCardTest : RobolectricTest() {
+    override fun getCollectionStorageMode() = CollectionStorageMode.IN_MEMORY_WITH_MEDIA
+
+    @Test
+    fun `restoring with a different queued card shows its question`() =
+        runTest {
+            val previous = addBasicNote("Previous", "Answer").firstCard()
+            val next = addBasicNote("Next", "Answer").firstCard()
+            col.sched.suspendCards(listOf(previous.id))
+            val state = SavedStateHandle(mapOf("showingAnswer" to true, "last_shown_card_id" to previous.id))
+            val store = ViewModelStore()
+            try {
+                val model = ReviewerViewModel(state).also { store.put("reviewer", it) }
+                model.onPageFinished(true)
+                advanceUntilIdle()
+                assertEquals(next.id, model.getCardId())
+                assertFalse(model.showingAnswer.value, "a new card must start on its question")
+            } finally {
+                store.clear()
+            }
+        }
+}

Originally posted by @david-allison in https://github.com/ankidroid/Anki-Android/pull/23695#pullrequestreview-6061399313

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.