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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package social.grain
import androidx.compose.ui.test.junit4.v2.createComposeRule
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import social.grain.data.model.AspectRatio
import social.grain.data.model.GrainGallery
import social.grain.data.model.GrainPhoto
import social.grain.data.model.GrainProfile
import social.grain.data.model.H3Location
import social.grain.ui.components.GalleryCard
import social.grain.ui.theme.GrainTheme
private const val CELL = "8a2a1072b59ffff"
private const val PLACE = "Liberty Island"
/**
* The place name under an author opens that location's feed.
*
* It has to report the H3 cell rather than the name: the feed groups on the
* cell, so a tap that carried only the words would open somebody else's
* spelling of the same corner, or nothing at all.
*/
@RunWith(AndroidJUnit4::class)
class GalleryCardLocationTapTest {
@get:Rule
val composeRule = createComposeRule()
private fun gallery(location: H3Location?) = GrainGallery(
uri = "at://did:plc:test/social.grain.gallery/1",
creator = GrainProfile(did = "did:plc:test", handle = "harbor.example"),
location = location,
items = listOf(
GrainPhoto(
uri = "at://did:plc:test/social.grain.photo/1",
aspectRatio = AspectRatio(3, 2),
),
),
indexedAt = "2026-08-01T00:00:00Z",
)
@Test
fun tappingThePlaceNameReportsTheCellBehindIt() {
var opened: Pair<String, String>? = null
composeRule.setContent {
GrainTheme {
GalleryCard(
gallery = gallery(H3Location(value = CELL, name = PLACE)),
onLocationTap = { cell, name -> opened = cell to name },
)
}
}
composeRule.onNodeWithText(PLACE).performClick()
assertEquals(CELL to PLACE, opened)
}
@Test
fun aGalleryWithNoCellHasNothingToOpen() {
var opened: Pair<String, String>? = null
composeRule.setContent {
GrainTheme {
GalleryCard(
// The name survived onto the view but the cell didn't, so
// there is no feed to send anyone to.
gallery = gallery(null).copy(locationDisplay = PLACE),
onLocationTap = { cell, name -> opened = cell to name },
)
}
}
composeRule.onNodeWithText(PLACE).performClick()
assertNull(opened)
}
}