Saving the split view editor restores a renamed tag

Open
#23,219 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
android, kotlin
Domain
database, mobile

Research direction

Start with the regression test shown in CardBrowserTest.kt, which renames a tag while the split view editor is open and then saves a note. Trace how the editor retains and saves note tags across the activity pause and resume, using the split pane editor and tag management paths as entry points. Done means the renamed tag remains "bar" after saving the edited note; run the focused CardBrowserTest.

Written by the indexing model from the issue text.

Description

Needs Triage
Subject: [EXISTING] Saving the split view editor restores a renamed tag

On a tablet split view, renaming a tag in Manage tags and then saving the note in the editor pane writes the old tag back.

⚠️ This issue existed before the PR and should likely be split off into a separate issue. This PR adds a new way to trigger it from the browser's tag options.

---
diff --git a/AnkiDroid/src/test/java/com/ichi2/anki/CardBrowserTest.kt b/AnkiDroid/src/test/java/com/ichi2/anki/CardBrowserTest.kt
index dded6222a3..4074346b4f 100644
--- a/AnkiDroid/src/test/java/com/ichi2/anki/CardBrowserTest.kt
+++ b/AnkiDroid/src/test/java/com/ichi2/anki/CardBrowserTest.kt
@@ -92,6 +92,8 @@ import com.ichi2.anki.model.SelectableDeck
 import com.ichi2.anki.model.SortType
 import com.ichi2.anki.noteeditor.toIntent
 import com.ichi2.anki.observability.undoableOp
+import com.ichi2.anki.tags.ManageTagsViewModel
+import com.ichi2.anki.tags.TagName
 import com.ichi2.anki.scheduling.ForgetCardsDialog
 import com.ichi2.anki.servicelayer.PreferenceUpgradeService
 import com.ichi2.anki.servicelayer.PreferenceUpgradeService.PreferenceUpgrade.UpgradeBrowserColumns.Companion.LEGACY_COLUMN1_KEYS
@@ -1678,6 +1680,39 @@ class CardBrowserTest : RobolectricTest() {
         }
     }
 
+    @Test
+    fun `a tag renamed in manage tags is not restored by saving the note editor pane`() =
+        runTest {
+            val note = addBasicNote("Hello", "World").update { addTag("foo") }
+            setCardBrowserFragmented(true)
+            withSplitPaneUiAsync {
+                ensureCollectionLoadIsSynchronous()
+                val controller = startActivityControllerNormallyOpenCollectionWithIntent(CardBrowser::class.java, Intent())
+                val browser = controller.get()
+                browser.waitForSearchResults()
+                browser.viewModel.setQuery("deck:\"Default\"", forceRefresh = true)
+                advanceRobolectricLooper()
+                browser.cardBrowserFragment.openNoteEditorForCurrentlySelectedRow()
+                advanceRobolectricLooper()
+
+                // Manage tags covers the browser while the tag is renamed
+                controller.pause().stop()
+                val manageTags = ManageTagsViewModel()
+                manageTags.refreshTags().join()
+                manageTags.renameTag(requireNotNull(TagName.build("foo")), requireNotNull(TagName.build("bar"))).join()
+                assertEquals(listOf("bar"), col.getNote(note.id).tags)
+                controller.start().resume()
+                advanceRobolectricLooper()
+
+                val editor = requireNotNull(browser.fragment) { "note editor unloaded" }
+                editor.setFieldValueFromUi(0, "Hello edited")
+                editor.saveNote()
+                advanceRobolectricLooper()
+
+                assertEquals(listOf("bar"), col.getNote(note.id).tags)
+            }
+        }
+
     /**
      * see issue 15609
      */

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

Dominant language
Kotlin
Stars
12.3k
Forks
3.1k
Avg merge
1d 11h
Merged PRs (30d)
383

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ankidroid/Anki-Android

All issues in ankidroid/Anki-Android

Similar issues

More Kotlin issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.