Filter chips discard the default browser query

Open Beginner friendly
#23,374 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
67/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
android, kotlin
Domain
mobile

Research direction

Start with CardBrowserInitialQueryFilterTest.kt, which shows the expected behavior: after setting the default query to "cat", changing the flags filter should preserve that query. Trace how setFlagsFilter updates searchRequestFlow before the search view is opened, then run the new Robolectric test. Done means the query remains "cat" after the BLUE flag filter is applied.

Written by the indexing model from the issue text.

Description

Assisted-by: GPT-6.1-Sol xhigh

[EXISTING] Filter chips discard the default browser query
Subject: [EXISTING] Filter chips discard the default browser query

Selecting a filter chip before opening search clears the configured default query, widening the displayed results.

⚠️ 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/CardBrowserInitialQueryFilterTest.kt b/AnkiDroid/src/test/java/com/ichi2/anki/browser/CardBrowserInitialQueryFilterTest.kt
new file mode 100644
index 0000000000..6ba0e5b445
--- /dev/null
+++ b/AnkiDroid/src/test/java/com/ichi2/anki/browser/CardBrowserInitialQueryFilterTest.kt
@@ -0,0 +1,27 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+package com.ichi2.anki.browser
+
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import com.ichi2.anki.Flag
+import com.ichi2.anki.RobolectricTest
+import com.ichi2.anki.utils.ext.defaultBrowserSearch
+import org.junit.Test
+import org.junit.runner.RunWith
+import kotlin.test.assertEquals
+
+@RunWith(AndroidJUnit4::class)
+class CardBrowserInitialQueryFilterTest : RobolectricTest() {
+    @Test
+    fun `changing a chip retains the default browser query before opening search`() {
+        col.config.defaultBrowserSearch = "cat"
+        withCardBrowserFragment(useSearchView = true) {
+            advanceRobolectricLooperUntil { activityViewModel.searchRequestFlow.value.query == "cat" }
+
+            searchViewModel.setFlagsFilter(listOf(Flag.BLUE))
+            advanceRobolectricLooperUntil { activityViewModel.searchRequestFlow.value.filters.flags == listOf(Flag.BLUE) }
+
+            assertEquals("cat", activityViewModel.searchRequestFlow.value.query)
+        }
+    }
+}

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

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.