Mouse-wheel scrolling leaves a Timebox draft unsaved

Open Beginner friendly
#23,686 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
Half a day
Newbie friendliness
65/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
android, kotlin
Domain
mobile

Research direction

Run the new regression test in AnkiDroid/src/test/java/com/ichi2/anki/preferences/TimeboxMouseScrollRegressionTest.kt; it sets up TimeboxSettingsScreen with TimeboxSettingsViewModel, performs a mouse-wheel scroll, and expects CollectionPreferences.getTimeboxTimeLimit() to reflect the typed draft. Then trace where the focused minutes field commits its draft in the screen and view model, and why scrolling bypasses that commit. Done when this regression test passes and the existing Timebox settings tests still pass.

Written by the indexing model from the issue text.

Description

code-scan Needs Triage
Subject: Mouse-wheel scrolling leaves a Timebox draft unsaved

Scrolling Timebox with a mouse wheel can leave a focused draft uncommitted.

---
diff --git a/AnkiDroid/src/test/java/com/ichi2/anki/preferences/TimeboxMouseScrollRegressionTest.kt b/AnkiDroid/src/test/java/com/ichi2/anki/preferences/TimeboxMouseScrollRegressionTest.kt
new file mode 100644
index 0000000000..b19379b646
--- /dev/null
+++ b/AnkiDroid/src/test/java/com/ichi2/anki/preferences/TimeboxMouseScrollRegressionTest.kt
@@ -0,0 +1,76 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+package com.ichi2.anki.preferences
+
+import androidx.compose.foundation.layout.Box
+import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.height
+import androidx.compose.runtime.collectAsState
+import androidx.compose.runtime.getValue
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.semantics.SemanticsProperties
+import androidx.compose.ui.test.SemanticsMatcher
+import androidx.compose.ui.test.assertIsFocused
+import androidx.compose.ui.test.hasSetTextAction
+import androidx.compose.ui.test.junit4.v2.createComposeRule
+import androidx.compose.ui.test.performClick
+import androidx.compose.ui.test.performMouseInput
+import androidx.compose.ui.test.performTextReplacement
+import androidx.compose.ui.unit.dp
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import com.ichi2.anki.RobolectricTest
+import com.ichi2.anki.utils.CollectionPreferences
+import com.ichi2.compose.theme.AnkiDroidTheme
+import org.junit.Rule
+import org.junit.Test
+import org.junit.runner.RunWith
+import kotlin.test.assertEquals
+import kotlin.time.Duration.Companion.minutes
+
+@RunWith(AndroidJUnit4::class)
+class TimeboxMouseScrollRegressionTest : RobolectricTest() {
+    @get:Rule
+    val composeRule = createComposeRule()
+
+    @Test
+    fun `scrolling Timebox with a mouse wheel commits the draft`() =
+        runTest {
+            CollectionPreferences.setTimeboxTimeLimit(20.minutes)
+            val viewModel = TimeboxSettingsViewModel()
+            advanceRobolectricLooper()
+            composeRule.setContent {
+                val state by viewModel.uiState.collectAsState()
+                AnkiDroidTheme {
+                    Box(Modifier.fillMaxWidth().height(285.dp)) {
+                        TimeboxSettingsScreen(
+                            isLoading = state.isLoading,
+                            isEnabled = state.isEnabled,
+                            minutes = state.limit.minutes,
+                            onToggleEnabled = viewModel::toggleEnabled,
+                            onIncrement = viewModel::increment,
+                            onDecrement = viewModel::decrement,
+                            onSetMinutes = viewModel::setMinutes,
+                            onNavigateUp = {},
+                        )
+                    }
+                }
+            }
+
+            val input = composeRule.onNode(hasSetTextAction())
+            input.performClick()
+            input.performTextReplacement("45")
+            input.assertIsFocused()
+
+            val pane = composeRule.onNode(SemanticsMatcher.keyIsDefined(SemanticsProperties.VerticalScrollAxisRange))
+            val scrollRange = pane.fetchSemanticsNode().config[SemanticsProperties.VerticalScrollAxisRange]
+            val previousPosition = scrollRange.value()
+            pane.performMouseInput {
+                moveTo(center)
+                scroll(3f)
+            }
+            composeRule.waitUntil(2_000) { scrollRange.value() > previousPosition }
+            advanceRobolectricLooper()
+
+            assertEquals(45.minutes, CollectionPreferences.getTimeboxTimeLimit())
+        }
+}
  • Originally posted by @david-allison in #22858
Dominant language
Kotlin
Stars
12.3k
Forks
3.1k
Avg merge
2d 1h
Merged PRs (30d)
320

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.