Skip to content

Commit 659eb8a

Browse files
kanake10gpunto
andauthored
test sorting (#119)
Co-authored-by: Gianmarco <[email protected]>
1 parent 5303880 commit 659eb8a

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

stream-feeds-android-client/src/test/kotlin/io/getstream/feeds/android/client/internal/state/CommentReplyListStateImplTest.kt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import io.getstream.feeds.android.client.internal.model.upsertReaction
2424
import io.getstream.feeds.android.client.internal.test.TestData.commentData
2525
import io.getstream.feeds.android.client.internal.test.TestData.feedsReactionData
2626
import io.getstream.feeds.android.client.internal.test.TestData.threadedCommentData
27+
import java.util.Date
2728
import kotlinx.coroutines.test.runTest
2829
import org.junit.Assert.assertEquals
2930
import 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")

0 commit comments

Comments
 (0)