|
| 1 | +package app.cash.paparazzi.accessibility |
| 2 | + |
| 3 | +import android.widget.TextView |
| 4 | +import app.cash.paparazzi.DeviceConfig |
| 5 | +import app.cash.paparazzi.Paparazzi |
| 6 | +import app.cash.paparazzi.Snapshot |
| 7 | +import app.cash.paparazzi.SnapshotHandler |
| 8 | +import app.cash.paparazzi.internal.ImageUtils |
| 9 | +import com.android.ide.common.rendering.api.SessionParams |
| 10 | +import org.junit.Rule |
| 11 | +import org.junit.Test |
| 12 | +import java.awt.image.BufferedImage |
| 13 | +import java.io.File |
| 14 | +import javax.imageio.ImageIO |
| 15 | + |
| 16 | +class AccessibilityRenderExtensionShrinkTest { |
| 17 | + private val snapshotHandler = TestSnapshotVerifier() |
| 18 | + |
| 19 | + @get:Rule |
| 20 | + val paparazzi = Paparazzi( |
| 21 | + deviceConfig = DeviceConfig.NEXUS_5, |
| 22 | + snapshotHandler = snapshotHandler, |
| 23 | + renderExtensions = setOf(AccessibilityRenderExtension()), |
| 24 | + renderingMode = SessionParams.RenderingMode.SHRINK |
| 25 | + ) |
| 26 | + |
| 27 | + @Test |
| 28 | + fun `verify baseline`() { |
| 29 | + val view = TextView(paparazzi.context).apply { |
| 30 | + id = 1 |
| 31 | + text = "Text View Sample" |
| 32 | + setPadding(50, 50, 50, 50) |
| 33 | + } |
| 34 | + paparazzi.snapshot(view, name = "accessibility-shrink") |
| 35 | + } |
| 36 | + |
| 37 | + private class TestSnapshotVerifier : SnapshotHandler { |
| 38 | + override fun newFrameHandler( |
| 39 | + snapshot: Snapshot, |
| 40 | + frameCount: Int, |
| 41 | + fps: Int |
| 42 | + ): SnapshotHandler.FrameHandler { |
| 43 | + return object : SnapshotHandler.FrameHandler { |
| 44 | + override fun handle(image: BufferedImage) { |
| 45 | + val expected = File("src/test/resources/${snapshot.name}.png") |
| 46 | + ImageUtils.assertImageSimilar( |
| 47 | + relativePath = expected.path, |
| 48 | + image = image, |
| 49 | + goldenImage = ImageIO.read(expected), |
| 50 | + maxPercentDifferent = 0.1 |
| 51 | + ) |
| 52 | + } |
| 53 | + |
| 54 | + override fun close() = Unit |
| 55 | + } |
| 56 | + } |
| 57 | + |
| 58 | + override fun close() = Unit |
| 59 | + } |
| 60 | +} |
0 commit comments