Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
Kotlin
at main
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152package social.grain
import org.junit.Assert.assertEqualsimport org.junit.Assert.assertTrueimport org.junit.Testimport social.grain.data.model.GrainCommentimport social.grain.data.model.GrainProfileimport social.grain.data.model.asThreads
/** * Threading is now shared between galleries and stories. These cover the shared * helper directly, so a change made for one subject can't quietly break the * other. */class CommentThreadingSharedTest {
private fun comment(uri: String, replyTo: String? = null) = GrainComment( uri = uri, author = GrainProfile(did = "did:plc:a", handle = "a.test"), text = uri, replyTo = replyTo, )
@Test fun `replies attach to their root and order is preserved`() { val threads = listOf( comment("at://r1"), comment("at://r2"), comment("at://c1", replyTo = "at://r1"), ).asThreads()
assertEquals(listOf("at://r1", "at://r2"), threads.map { it.root.uri }) assertEquals(listOf("at://c1"), threads[0].replies.map { it.uri }) assertTrue(threads[1].replies.isEmpty()) }
@Test fun `an orphaned reply is not promoted to a root`() { val threads = listOf( comment("at://r1"), comment("at://orphan", replyTo = "at://not-on-this-page"), ).asThreads()
assertEquals(listOf("at://r1"), threads.map { it.root.uri }) }
@Test fun `an empty list threads to nothing`() { assertTrue(emptyList<GrainComment>().asThreads().isEmpty()) }}