~ knotless Search/
↑↓ move↵ open⇧↵ all results

grain.social/grain-android

1 collaborator
0
1
main
51 lines · 1.5 KB Raw History
package social.grain

import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
import social.grain.data.model.GrainComment
import social.grain.data.model.GrainProfile
import 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())
    }
}