-
Notifications
You must be signed in to change notification settings - Fork 319
Stabilize the thread quote jump test and stop dropping focused-message jumps #6594
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
andremion
merged 6 commits into
develop
from
andrerego/and-1332-scroll-until-the-quoted-message-is-visible
Jul 29, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d96eecf
compose: Wait out an in-progress scroll before jumping to a focused m…
andremion 9fe5b93
e2e: Add a stale-safe click for objects matched by index
andremion d9a5b2a
e2e: Stabilize the thread quote jump test with the scrolling setup
andremion 557491c
compose: Extract the focused-item scroll and cover it with tests
andremion 6de26dc
e2e: Clarify the scroll and click helper contracts
andremion 4826025
compose: Pause the clock so the scroll wait test exercises the wait
andremion File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
...test/kotlin/io/getstream/chat/android/compose/ui/messages/list/ScrollToFocusedItemTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| /* | ||
| * Copyright (c) 2014-2026 Stream.io Inc. All rights reserved. | ||
| * | ||
| * Licensed under the Stream License; | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://github.com/GetStream/stream-chat-android/blob/main/LICENSE | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package io.getstream.chat.android.compose.ui.messages.list | ||
|
|
||
| import androidx.compose.animation.core.tween | ||
| import androidx.compose.foundation.gestures.animateScrollBy | ||
| import androidx.compose.foundation.layout.Box | ||
| import androidx.compose.foundation.layout.size | ||
| import androidx.compose.foundation.lazy.LazyColumn | ||
| import androidx.compose.foundation.lazy.LazyListState | ||
| import androidx.compose.foundation.lazy.rememberLazyListState | ||
| import androidx.compose.runtime.rememberCoroutineScope | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.test.junit4.createComposeRule | ||
| import androidx.compose.ui.unit.dp | ||
| import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
| import kotlinx.coroutines.CoroutineScope | ||
| import kotlinx.coroutines.Deferred | ||
| import kotlinx.coroutines.async | ||
| import kotlinx.coroutines.launch | ||
| import org.junit.Assert.assertEquals | ||
| import org.junit.Assert.assertFalse | ||
| import org.junit.Assert.assertTrue | ||
| import org.junit.Rule | ||
| import org.junit.Test | ||
| import org.junit.runner.RunWith | ||
| import org.robolectric.annotation.Config | ||
|
|
||
| @RunWith(AndroidJUnit4::class) | ||
| @Config(sdk = [33]) | ||
| internal class ScrollToFocusedItemTest { | ||
|
|
||
| @get:Rule | ||
| val composeTestRule = createComposeRule() | ||
|
|
||
| private lateinit var listState: LazyListState | ||
| private lateinit var scope: CoroutineScope | ||
|
|
||
| private fun setListContent() { | ||
| composeTestRule.setContent { | ||
| listState = rememberLazyListState() | ||
| scope = rememberCoroutineScope() | ||
| LazyColumn(state = listState, modifier = Modifier.size(200.dp)) { | ||
| items(count = 200) { | ||
| Box(modifier = Modifier.size(50.dp)) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| fun `given no focused item, the list does not scroll`() { | ||
| setListContent() | ||
|
|
||
| val jump = scrollToFocusedItemAsync(focusedItemIndex = -1) | ||
|
|
||
| composeTestRule.waitUntil(timeoutMillis = 5_000) { jump.isCompleted } | ||
| assertEquals(0, listState.firstVisibleItemIndex) | ||
| } | ||
|
|
||
| @Test | ||
| fun `given an idle list, scrolls to the focused item`() { | ||
| setListContent() | ||
|
|
||
| val jump = scrollToFocusedItemAsync(focusedItemIndex = 100) | ||
|
|
||
| composeTestRule.waitUntil(timeoutMillis = 5_000) { jump.isCompleted } | ||
| assertEquals(100, listState.firstVisibleItemIndex) | ||
| } | ||
|
|
||
| @Test | ||
| fun `given a scroll in progress, waits it out and then scrolls to the focused item`() { | ||
|
gpunto marked this conversation as resolved.
|
||
| setListContent() | ||
| // Pause the clock so the animation genuinely overlaps the jump. With the clock | ||
| // auto-advancing, runOnIdle would finish the animation before the jump even starts and | ||
| // the test would pass without exercising the wait. Assertions use runOnUiThread because | ||
| // runOnIdle cannot settle while the clock is paused mid-animation. | ||
| composeTestRule.mainClock.autoAdvance = false | ||
| composeTestRule.runOnUiThread { | ||
| scope.launch { | ||
| listState.animateScrollBy(value = 1_000f, animationSpec = tween(durationMillis = 2_000)) | ||
| } | ||
| } | ||
| composeTestRule.mainClock.advanceTimeBy(500) | ||
| composeTestRule.runOnUiThread { assertTrue(listState.isScrollInProgress) } | ||
|
|
||
| val jump = composeTestRule.runOnUiThread { | ||
| scope.async { listState.scrollToFocusedItem(focusedItemIndex = 100, offset = 0) } | ||
| } | ||
|
|
||
| composeTestRule.mainClock.advanceTimeBy(500) | ||
| composeTestRule.runOnUiThread { | ||
| assertTrue(listState.isScrollInProgress) | ||
| assertFalse(jump.isCompleted) | ||
| assertTrue(listState.firstVisibleItemIndex < 100) | ||
| } | ||
|
|
||
| composeTestRule.mainClock.autoAdvance = true | ||
| composeTestRule.waitUntil(timeoutMillis = 5_000) { jump.isCompleted } | ||
| assertEquals(100, listState.firstVisibleItemIndex) | ||
| } | ||
|
|
||
| private fun scrollToFocusedItemAsync(focusedItemIndex: Int): Deferred<Unit> = | ||
| composeTestRule.runOnIdle { | ||
| scope.async { | ||
| listState.scrollToFocusedItem(focusedItemIndex = focusedItemIndex, offset = 0) | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.