Add Note restored after its note type was deleted bounces to the deck list

Aperta
#23,359 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
63/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
android, kotlin
Ambito
mobile

Direzione di ricerca

Start with the regression test in AnkiDroid/src/test/java/com/ichi2/anki/NoteEditorMissingNoteTypeTest.kt and trace how NoteEditorActivity restores Add Note state after the selected note type is removed. Run the test to reproduce the bounce to the deck list; done means restoration opens the editor with an existing note type and does not launch another activity. The issue notes this may need to be split from the linked PR.

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

Descrizione

Assisted-by: Claude Opus 5.5 max

Subject: [EXISTING] Add Note restored after its note type was deleted bounces to the deck list

Add Note recreated after its note type is deleted hits the linked issue's error and silently opens the deck list instead of falling back.

⚠️ 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/NoteEditorMissingNoteTypeTest.kt b/AnkiDroid/src/test/java/com/ichi2/anki/NoteEditorMissingNoteTypeTest.kt
new file mode 100644
index 0000000000..2014769dc8
--- /dev/null
+++ b/AnkiDroid/src/test/java/com/ichi2/anki/NoteEditorMissingNoteTypeTest.kt
@@ -0,0 +1,40 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+package com.ichi2.anki
+
+import androidx.test.core.app.ActivityScenario
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import com.ichi2.anki.common.destinations.NoteEditorDestination
+import com.ichi2.anki.common.destinations.toIntent
+import com.ichi2.anki.noteeditor.getNoteEditorFragment
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.robolectric.Shadows.shadowOf
+import kotlin.test.assertNotNull
+import kotlin.test.assertNull
+
+@RunWith(AndroidJUnit4::class)
+class NoteEditorMissingNoteTypeTest : RobolectricTest() {
+    @Test
+    fun `restoring Add Note after its note type was deleted falls back to an existing note type`() {
+        ensureCollectionLoadIsSynchronous()
+        val name = addStandardNoteType("Deleted Later", arrayOf("Front", "Back"), "{{Front}}", "{{Back}}")
+        val type = col.notetypes.byName(name)!!
+
+        ActivityScenario.launch<NoteEditorActivity>(NoteEditorDestination.AddNote().toIntent()).use { scenario ->
+            scenario.onActivity { it.getNoteEditorFragment().setCurrentlySelectedNoteType(type.id) }
+            advanceRobolectricLooper()
+            col.notetypes.remove(type.id)
+
+            scenario.recreate()
+            advanceRobolectricLooper()
+
+            scenario.onActivity { activity ->
+                val opened = shadowOf(activity).nextStartedActivity?.component?.className
+                assertNull(opened, "the editor gave up and opened $opened")
+                val restoredNoteTypeId = activity.getNoteEditorFragment().editorNote?.noteTypeId
+                assertNotNull(restoredNoteTypeId?.let { col.notetypes.get(it) }, "restored note type $restoredNoteTypeId does not exist")
+            }
+        }
+    }
+}

Originally posted by @criticalAY in https://github.com/ankidroid/Anki-Android/pull/23077#pullrequestreview-5930134433

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.