Tag edits are lost after the browser is recreated

Aperta
#23,196 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

Start with AnkiDroid/src/test/java/com/ichi2/anki/browser/EditTagsDialogRecreationTest.kt, which reproduces the failure by recreating the browser while the Edit tags dialog is open. Trace how TagsDialog restores its state and applies tag edits after recreation. Done means the regression test passes and the selected notes receive the added tag after confirming the restored dialog.

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

Descrizione

Subject: [EXISTING] Tag edits are lost after the browser is recreated

Rotating the browser while Edit tags is open, then confirming, silently leaves the selected notes' tags unchanged.

⚠️ This issue existed before the PR and should likely be split off into a separate issue.
---
diff --git a/AnkiDroid/src/test/java/com/ichi2/anki/browser/EditTagsDialogRecreationTest.kt b/AnkiDroid/src/test/java/com/ichi2/anki/browser/EditTagsDialogRecreationTest.kt
new file mode 100644
index 0000000000..98ef0eeb0f
--- /dev/null
+++ b/AnkiDroid/src/test/java/com/ichi2/anki/browser/EditTagsDialogRecreationTest.kt
@@ -0,0 +1,79 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+package com.ichi2.anki.browser
+
+import android.content.DialogInterface
+import androidx.appcompat.app.AlertDialog
+import androidx.test.core.app.ActivityScenario
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import com.ichi2.anki.CardBrowser
+import com.ichi2.anki.RobolectricTest
+import com.ichi2.anki.browser.search.StandardSearchFragment
+import com.ichi2.anki.dialogs.tags.TagsDialog
+import com.ichi2.anki.settings.Prefs
+import com.ichi2.anki.utils.ext.DIALOG_FRAGMENT_TAG
+import org.junit.Test
+import org.junit.runner.RunWith
+import kotlin.test.assertEquals
+import kotlin.test.assertIs
+import kotlin.test.assertNotNull
+
+@RunWith(AndroidJUnit4::class)
+class EditTagsDialogRecreationTest : RobolectricTest() {
+    @Test
+    fun `edit tags dialog edits the note`() = editTags(recreate = false)
+
+    @Test
+    fun `edit tags dialog restored after recreation edits the note`() = editTags(recreate = true)
+
+    private fun editTags(recreate: Boolean) =
+        runTest {
+            val note =
+                addBasicNote("Tagged").apply {
+                    addTag("probe")
+                    flush()
+                }
+            Prefs.devUsingCardBrowserSearchView = true
+            try {
+                ActivityScenario.launch(CardBrowser::class.java).use { scenario ->
+                    lateinit var browser: CardBrowser
+                    scenario.onActivity { browser = it }
+                    browser.viewModel.searchJob?.join()
+                    advanceRobolectricLooper()
+                    assertNotNull(
+                        browser.cardBrowserFragment.childFragmentManager.findFragmentByTag(StandardSearchFragment.TAG),
+                        "StandardSearchFragment exists before the search view is opened",
+                    )
+                    browser.viewModel.selectAll()?.join()
+                    advanceRobolectricLooper()
+                    browser.cardBrowserFragment.showEditTagsDialog()
+                    advanceRobolectricLooperUntil { browser.supportFragmentManager.findFragmentByTag(DIALOG_FRAGMENT_TAG) is TagsDialog }
+                    if (recreate) {
+                        scenario.recreate()
+                        advanceRobolectricLooper()
+                        scenario.onActivity { browser = it }
+                    }
+                    val dialog = assertIs<TagsDialog>(browser.supportFragmentManager.findFragmentByTag(DIALOG_FRAGMENT_TAG))
+                    val button = (dialog.requireDialog() as AlertDialog).getButton(DialogInterface.BUTTON_POSITIVE)
+                    advanceRobolectricLooperUntil { button.isEnabled }
+                    dialog.viewModel.tags.await().apply {
+                        add("added")
+                        check("added")
+                    }
+                    button.performClick()
+                    advanceRobolectricLooper()
+                    browser.viewModel.searchJob?.join()
+                    advanceRobolectricLooper()
+                    val searchTags = browser.viewModel.searchRequestFlow.value.filters.tags
+                    val noteTags = col.getNote(note.id).tags.sorted()
+                    assertEquals(
+                        "search=[] note=[added, probe]",
+                        "search=$searchTags note=$noteTags",
+                        "recreate=$recreate rows=${browser.viewModel.rowCount}",
+                    )
+                }
+            } finally {
+                Prefs.devUsingCardBrowserSearchView = false
+            }
+        }
+}
Lingua principale
Kotlin
Stelle
12.3k
Fork
3.1k
Merge medio
1g 11h
PR unite (30g)
383

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.