Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
2.8 kB · 86 lines
Kotlin
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687package social.grain
import androidx.compose.ui.test.junit4.v2.createComposeRuleimport androidx.compose.ui.test.onNodeWithTextimport androidx.compose.ui.test.performClickimport androidx.test.ext.junit.runners.AndroidJUnit4import org.junit.Assert.assertEqualsimport org.junit.Assert.assertNullimport org.junit.Ruleimport org.junit.Testimport org.junit.runner.RunWithimport social.grain.data.model.AspectRatioimport social.grain.data.model.GrainGalleryimport social.grain.data.model.GrainPhotoimport social.grain.data.model.GrainProfileimport social.grain.data.model.H3Locationimport social.grain.ui.components.GalleryCardimport 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) }}