From 33f1cb4abf19fbdf8cfd865208fe794490c42d8e Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 29 Apr 2024 10:07:20 +0200 Subject: [PATCH] Test TimelineView regarding "Jump to bottom" button. --- .../impl/timeline/TimelineStateProvider.kt | 3 +- .../impl/timeline/TimelineViewTest.kt | 33 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelineStateProvider.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelineStateProvider.kt index f2670b7023..b9e417b188 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelineStateProvider.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelineStateProvider.kt @@ -49,13 +49,14 @@ fun aTimelineState( renderReadReceipts: Boolean = false, timelineRoomInfo: TimelineRoomInfo = aTimelineRoomInfo(), focusedEventIndex: Int = -1, + isLive: Boolean = true, eventSink: (TimelineEvents) -> Unit = {}, ) = TimelineState( timelineItems = timelineItems, timelineRoomInfo = timelineRoomInfo, renderReadReceipts = renderReadReceipts, newEventState = NewEventState.None, - isLive = true, + isLive = isLive, focusedEventId = timelineItems.filterIsInstance().getOrNull(focusedEventIndex)?.eventId, focusRequestState = FocusRequestState.None, eventSink = eventSink, diff --git a/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/timeline/TimelineViewTest.kt b/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/timeline/TimelineViewTest.kt index d16de9f01d..29d46d2da2 100644 --- a/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/timeline/TimelineViewTest.kt +++ b/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/timeline/TimelineViewTest.kt @@ -19,6 +19,8 @@ package io.element.android.features.messages.impl.timeline import androidx.activity.ComponentActivity import androidx.compose.ui.test.junit4.AndroidComposeTestRule import androidx.compose.ui.test.junit4.createAndroidComposeRule +import androidx.compose.ui.test.onNodeWithContentDescription +import androidx.compose.ui.test.performClick import androidx.test.ext.junit.runners.AndroidJUnit4 import io.element.android.features.messages.impl.timeline.model.TimelineItem import io.element.android.features.messages.impl.timeline.model.virtual.TimelineItemLoadingIndicatorModel @@ -26,6 +28,7 @@ import io.element.android.features.messages.impl.typing.TypingNotificationState import io.element.android.features.messages.impl.typing.aTypingNotificationState import io.element.android.libraries.matrix.api.core.UserId import io.element.android.libraries.matrix.api.timeline.Timeline +import io.element.android.libraries.ui.strings.CommonStrings import io.element.android.tests.testutils.EnsureNeverCalledWithParam import io.element.android.tests.testutils.EnsureNeverCalledWithTwoParams import io.element.android.tests.testutils.EventsRecorder @@ -65,6 +68,34 @@ class TimelineViewTest { ), ) } + + @Test + fun `scroll to bottom on live timeline does not emit the Event`() { + val eventsRecorder = EventsRecorder(expectEvents = false) + rule.setTimelineView( + state = aTimelineState( + isLive = true, + eventSink = eventsRecorder, + ), + forceJumpToBottomVisibility = true, + ) + val contentDescription = rule.activity.getString(CommonStrings.a11y_jump_to_bottom) + rule.onNodeWithContentDescription(contentDescription).performClick() + } + + @Test + fun `scroll to bottom on detached timeline emits the expected Event`() { + val eventsRecorder = EventsRecorder() + rule.setTimelineView( + state = aTimelineState( + isLive = false, + eventSink = eventsRecorder, + ), + ) + val contentDescription = rule.activity.getString(CommonStrings.a11y_jump_to_bottom) + rule.onNodeWithContentDescription(contentDescription).performClick() + eventsRecorder.assertSingle(TimelineEvents.JumpToLive) + } } private fun AndroidComposeTestRule.setTimelineView( @@ -80,6 +111,7 @@ private fun AndroidComposeTestRule.setTimel onReactionLongClicked: (emoji: String, TimelineItem.Event) -> Unit = EnsureNeverCalledWithTwoParams(), onMoreReactionsClicked: (TimelineItem.Event) -> Unit = EnsureNeverCalledWithParam(), onReadReceiptClick: (TimelineItem.Event) -> Unit = EnsureNeverCalledWithParam(), + forceJumpToBottomVisibility: Boolean = false, ) { setContent { TimelineView( @@ -95,6 +127,7 @@ private fun AndroidComposeTestRule.setTimel onReactionLongClicked = onReactionLongClicked, onMoreReactionsClicked = onMoreReactionsClicked, onReadReceiptClick = onReadReceiptClick, + forceJumpToBottomVisibility = forceJumpToBottomVisibility, ) } }