-
-
Save davidvavra/225088f82727f870066b0e7f300a674b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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