File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
stream-feeds-android-client/src/test/kotlin/io/getstream/feeds/android/client/internal/state Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ import io.getstream.feeds.android.client.internal.model.upsertReaction
2424import io.getstream.feeds.android.client.internal.test.TestData.commentData
2525import io.getstream.feeds.android.client.internal.test.TestData.feedsReactionData
2626import io.getstream.feeds.android.client.internal.test.TestData.threadedCommentData
27+ import java.util.Date
2728import kotlinx.coroutines.test.runTest
2829import org.junit.Assert.assertEquals
2930import org.junit.Test
@@ -94,6 +95,38 @@ internal class CommentReplyListStateImplTest {
9495 assertEquals(listOf (parentComment), state.replies.value)
9596 }
9697
98+ @Test
99+ fun `on onCommentAdded replies are sorted by createdAt` () = runTest {
100+ val parentComment = threadedCommentData(" parent-1" , text = " Parent comment" )
101+
102+ setupInitialReplies(parentComment)
103+
104+ val oldReply =
105+ threadedCommentData(
106+ id = " reply-1" ,
107+ parentId = " parent-1" ,
108+ text = " Old reply" ,
109+ createdAt = Date (1 ),
110+ )
111+
112+ val newReply =
113+ threadedCommentData(
114+ id = " reply-2" ,
115+ parentId = " parent-1" ,
116+ text = " New reply" ,
117+ createdAt = Date (2 ),
118+ )
119+
120+ // Add replies in reverse order to test sorting
121+ state.onCommentAdded(oldReply)
122+ state.onCommentAdded(newReply)
123+
124+ val expectedParent =
125+ parentComment.copy(replies = listOf (newReply, oldReply), replyCount = 2 )
126+
127+ assertEquals(listOf (expectedParent), state.replies.value)
128+ }
129+
97130 @Test
98131 fun `on onCommentRemoved with top-level comment, remove it from state` () = runTest {
99132 val comment1 = threadedCommentData(" comment-1" , text = " First comment" )
You can’t perform that action at this time.
0 commit comments