Skip to content

Instantly share code, notes, and snippets.

@davidvavra
Created June 30, 2022 10:41
Show Gist options
  • Save davidvavra/225088f82727f870066b0e7f300a674b to your computer and use it in GitHub Desktop.
Save davidvavra/225088f82727f870066b0e7f300a674b to your computer and use it in GitHub Desktop.
class ComponentPreview(
private val showkaseBrowserComponent: ShowkaseBrowserComponent
) {
val content: @Composable () -> Unit = showkaseBrowserComponent.component
override fun toString(): String =
showkaseBrowserComponent.group + ":" + showkaseBrowserComponent.componentName
}
@RunWith(TestParameterInjector::class)
class ComposePaparazziTests {
object PreviewProvider : TestParameter.TestParameterValuesProvider {
override fun provideValues(): List<ComponentPreview> =
Showkase.getMetadata().componentList.map(::ComponentPreview)
}
@get:Rule
val paparazzi = Paparazzi(
maxPercentDifference = 0.0,
deviceConfig = PIXEL_5.copy(softButtons = false),
)
@Test
fun preview_tests(
@TestParameter(valuesProvider = PreviewProvider::class) componentPreview: ComponentPreview,
@TestParameter(value = ["1.0", "1.5"]) fontScale: Float,
@TestParameter(value = ["light", "dark"]) theme: String
) {
paparazzi.snapshot() {
CompositionLocalProvider(
LocalInspectionMode provides true,
LocalDensity provides Density(
density = LocalDensity.current.density,
fontScale = fontScale
)
) {
ShowkaseTheme(darkTheme = (theme == "dark")) {
componentPreview.content()
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment