Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
5.2 kB · 140 lines
Kotlin
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141package social.grain
import androidx.compose.material3.Surfaceimport androidx.compose.ui.test.assertIsDisplayedimport 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.Ruleimport org.junit.Testimport org.junit.runner.RunWithimport social.grain.data.model.AspectRatioimport social.grain.data.model.AtLabelimport social.grain.data.model.GrainGalleryimport social.grain.data.model.GrainPhotoimport social.grain.data.model.GrainProfileimport social.grain.data.model.LabelDefinitionimport social.grain.data.model.LabelLocaleimport social.grain.ui.components.GalleryCardimport social.grain.ui.theme.GrainTheme
/** * That a labelled gallery actually draws its label. * * `resolveLabels` deciding correctly is worth nothing on its own — the bug this * guards against is a card that resolves `WARN_MEDIA` and then renders the * photo anyway, or resolves `BADGE` and renders nothing at all, which is what * happened to every label the server defined for itself. */@RunWith(AndroidJUnit4::class)class LabelRenderTest {
@get:Rule val composeRule = createComposeRule()
private fun definition(identifier: String, blurs: String, setting: String, name: String) = LabelDefinition( identifier = identifier, locales = listOf(LabelLocale(name)), blurs = blurs, defaultSetting = setting, )
private fun gallery(vararg labels: String) = GrainGallery( uri = "at://did:plc:sample/social.grain.gallery/1", title = "Yosemite, winter", creator = GrainProfile(did = "did:plc:sample", handle = "ansel.grain.social"), items = listOf( GrainPhoto( uri = "at://did:plc:sample/social.grain.photo/1", thumb = "", fullsize = "", aspectRatio = AspectRatio(3, 2), ), ), labels = labels.map { AtLabel(`val` = it) }, indexedAt = "2026-01-04T09:12:00Z", )
private fun setCard(gallery: GrainGallery, definitions: List<LabelDefinition>) { composeRule.setContent { GrainTheme(dynamicColor = false) { Surface { GalleryCard(gallery = gallery, labelDefinitions = definitions) } } } }
/** The gap this closes: a server-defined label that blurs nothing used to * resolve to a badge and then render as nothing whatsoever. */ @Test fun aBadgeLabelIsNamedNextToTheCaption() { setCard( gallery("spoiler"), listOf(definition("spoiler", "none", "warn", "Spoiler")), ) composeRule.onNodeWithText("Spoiler").assertIsDisplayed() // Still a card, not a cover. composeRule.onNodeWithText("Yosemite, winter").assertIsDisplayed() }
@Test fun coveredMediaNamesTheLabelAndRevealsOnShow() { setCard( gallery("nudity"), listOf(definition("nudity", "media", "warn", "Nudity")), ) // The name is the point — "Tap to show" told the reader nothing about // what they were being asked to consent to. composeRule.onNodeWithText("Nudity").assertIsDisplayed() composeRule.onNodeWithText("Show").assertIsDisplayed()
composeRule.onNodeWithText("Show").performClick() composeRule.waitForIdle() composeRule.onNodeWithText("Show").assertDoesNotExist() }
@Test fun contentWarningsCoverTheWholeCardAndCanBeRevealed() { setCard( gallery("!warn"), emptyList(), ) composeRule.onNodeWithText("Warning").assertIsDisplayed() composeRule.onNodeWithText("Yosemite, winter").assertDoesNotExist()
composeRule.onNodeWithText("Show anyway").performClick() composeRule.waitForIdle() composeRule.onNodeWithText("Yosemite, winter").assertIsDisplayed() }
/** A hidden gallery gets no way through — the difference between "you may * not want to see this" and "this shouldn't be shown". */ @Test fun aHiddenGalleryOffersNoRevealAtAll() { setCard(gallery("!hide"), emptyList()) composeRule.onNodeWithText("Hidden").assertIsDisplayed() composeRule.onNodeWithText("Show anyway").assertDoesNotExist() composeRule.onNodeWithText("Yosemite, winter").assertDoesNotExist() }
@Test fun aNegatedLabelGatesNothing() { composeRule.setContent { GrainTheme(dynamicColor = false) { Surface { GalleryCard( gallery = gallery().copy( labels = listOf(AtLabel(`val` = "!hide", neg = true)), ), labelDefinitions = emptyList(), ) } } } composeRule.onNodeWithText("Yosemite, winter").assertIsDisplayed() composeRule.onNodeWithText("Hidden").assertDoesNotExist() }}