1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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())
}
}