Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nuke TestSnapshotVerifier #1748

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,14 @@ import android.widget.Button
import android.widget.FrameLayout
import android.widget.LinearLayout
import android.widget.TextView
import app.cash.paparazzi.internal.ImageUtils
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
import java.awt.image.BufferedImage
import java.io.File
import javax.imageio.ImageIO

class RenderExtensionTest {
@get:Rule
val tempDir = TemporaryFolder()

private val snapshotHandler = TestSnapshotVerifier()

@get:Rule
val paparazzi = Paparazzi(
deviceConfig = DeviceConfig.NEXUS_5,
snapshotHandler = snapshotHandler,
snapshotHandler = SnapshotVerifier(maxPercentDifference = 0.1),
renderExtensions = setOf(
WrappedRenderExtension(Color.DKGRAY),
WrappedRenderExtension(Color.RED),
Expand Down Expand Up @@ -71,29 +61,6 @@ class RenderExtensionTest {
}
)
}

private inner class TestSnapshotVerifier : SnapshotHandler {
override fun newFrameHandler(snapshot: Snapshot, frameCount: Int, fps: Int): SnapshotHandler.FrameHandler {
return object : SnapshotHandler.FrameHandler {
override fun handle(image: BufferedImage) {
val expected = File("src/test/resources/${snapshot.name}.png")
ImageUtils.assertImageSimilar(
relativePath = expected.path,
image = image,
goldenImage = ImageIO.read(expected),
maxPercentDifferent = 0.1,
failureDir = File("src/test/resources/${snapshot.name}").apply {
mkdirs()
}
)
}

override fun close() = Unit
}
}

override fun close() = Unit
}
}

class WrappedRenderExtension(val color: Int) : RenderExtension {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,15 @@ import android.widget.LinearLayout
import android.widget.TextView
import app.cash.paparazzi.DeviceConfig
import app.cash.paparazzi.Paparazzi
import app.cash.paparazzi.Snapshot
import app.cash.paparazzi.SnapshotHandler
import app.cash.paparazzi.internal.ImageUtils
import app.cash.paparazzi.SnapshotVerifier
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
import java.awt.image.BufferedImage
import java.io.File
import javax.imageio.ImageIO

class AccessibilityRenderExtensionTest {
@get:Rule
val tempDir = TemporaryFolder()

private val snapshotHandler = TestSnapshotVerifier()

@get:Rule
val paparazzi = Paparazzi(
deviceConfig = DeviceConfig.NEXUS_5,
snapshotHandler = snapshotHandler,
snapshotHandler = SnapshotVerifier(maxPercentDifference = 0.1),
renderExtensions = setOf(AccessibilityRenderExtension())
)

Expand Down Expand Up @@ -116,25 +105,4 @@ class AccessibilityRenderExtensionTest {
}
)
}

private inner class TestSnapshotVerifier : SnapshotHandler {
override fun newFrameHandler(snapshot: Snapshot, frameCount: Int, fps: Int): SnapshotHandler.FrameHandler {
return object : SnapshotHandler.FrameHandler {
override fun handle(image: BufferedImage) {
val expected = File("src/test/resources/${snapshot.name}.png")
ImageUtils.assertImageSimilar(
relativePath = expected.path,
image = image,
goldenImage = ImageIO.read(expected),
maxPercentDifferent = 0.1,
failureDir = tempDir.newFolder()
)
}

override fun close() = Unit
}
}

override fun close() = Unit
}
}
Loading