Issue with completion feedback after studying unburied cards from Congrats

オープン
#23,751 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
45/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
android, kotlin
領域
mobile, testing

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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))
+        }
+}
主要言語
Kotlin
スター
12.3k
フォーク
3.1k
平均マージ
2日 1時間
マージ済み PR(30日)
311

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

ankidroid/Anki-Android のほかの issue

ankidroid/Anki-Android の issue をすべて見る

似ている issue

Kotlin の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。