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

Expose ShowkaseBrowserComponent (and color and typography) in PaparazziShowkaseTestPreview #320

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.dp
import com.airbnb.android.showkase.annotation.ShowkaseComposable
Expand Down Expand Up @@ -69,6 +70,16 @@ fun PreviewCustomButtonSmall() {
)
}

@ShowkaseComposable(name = "CustomButton", group = "Localised", styleName = "Small")
@Composable
fun PreviewCustomButtonLocalised() {
CustomButton(
text = stringResource(id = R.string.button),
onClick = { },
size = ButtonSize.Small
)
}


@Suppress("MatchingDeclarationName")
enum class ButtonSize {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="button">Knapp</string>
</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="button">Button</string>
</resources>
Original file line number Diff line number Diff line change
@@ -1,9 +1,36 @@
package com.airbnb.android.showkase.screenshot.testing.paparazzi.sample

import androidx.compose.ui.unit.LayoutDirection
import app.cash.paparazzi.DeviceConfig
import app.cash.paparazzi.Paparazzi
import com.airbnb.android.showkase.annotation.ShowkaseScreenshot
import com.airbnb.android.showkase.screenshot.testing.paparazzi.PaparazziShowkaseDeviceConfig
import com.airbnb.android.showkase.screenshot.testing.paparazzi.PaparazziShowkaseScreenshotTest
import com.airbnb.android.showkase.screenshot.testing.paparazzi.PaparazziShowkaseTestPreview
import com.airbnb.android.showkase.screenshot.testing.paparazzi.PaparazziShowkaseUIMode

@ShowkaseScreenshot(rootShowkaseClass = PaparazziSampleRootModule::class)
abstract class MyPaparazziShowkaseScreenshotTest: PaparazziShowkaseScreenshotTest {
companion object: PaparazziShowkaseScreenshotTest.CompanionObject
abstract class MyPaparazziShowkaseScreenshotTest : PaparazziShowkaseScreenshotTest {
override fun takePaparazziSnapshot(
paparazzi: Paparazzi,
testPreview: PaparazziShowkaseTestPreview,
direction: LayoutDirection,
mode: PaparazziShowkaseUIMode
) {
if (paparazzi.resources.configuration.locales.get(0).toString() == "en-gb" ||
andersu marked this conversation as resolved.
Show resolved Hide resolved
testPreview.showkaseBrowserElement.group == "Localised"
) {
super.takePaparazziSnapshot(paparazzi, testPreview, direction, mode)
}
}

companion object : PaparazziShowkaseScreenshotTest.CompanionObject {
override fun deviceConfigs(): List<PaparazziShowkaseDeviceConfig> {
return listOf("en-rGB", "nb-rNO").map { locale ->
andersu marked this conversation as resolved.
Show resolved Hide resolved
PaparazziShowkaseDeviceConfig(
deviceConfig = DeviceConfig.PIXEL_5.copy(locale = locale)
)
}
}
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import app.cash.paparazzi.Paparazzi
import com.airbnb.android.showkase.annotation.ShowkaseScreenshot
import com.airbnb.android.showkase.models.ShowkaseBrowserColor
import com.airbnb.android.showkase.models.ShowkaseBrowserComponent
import com.airbnb.android.showkase.models.ShowkaseBrowserElement
import com.airbnb.android.showkase.models.ShowkaseBrowserTypography
import com.airbnb.android.showkase.ui.padding4x
import com.android.ide.common.rendering.api.SessionParams
Expand Down Expand Up @@ -133,6 +134,8 @@ interface PaparazziShowkaseScreenshotTest {
}

interface PaparazziShowkaseTestPreview {
val showkaseBrowserElement: ShowkaseBrowserElement
andersu marked this conversation as resolved.
Show resolved Hide resolved

@Composable
fun Content()
}
Expand All @@ -142,9 +145,11 @@ private const val DELIM = "**"
class ComponentPaparazziShowkaseTestPreview(
private val showkaseBrowserComponent: ShowkaseBrowserComponent,
) : PaparazziShowkaseTestPreview {
override val showkaseBrowserElement: ShowkaseBrowserElement = showkaseBrowserComponent

@Composable
override fun Content() = showkaseBrowserComponent.component()

override fun toString(): String =
"${showkaseBrowserComponent.group}${DELIM}${showkaseBrowserComponent.componentName}${DELIM}" +
"${showkaseBrowserComponent.styleName}"
Expand All @@ -153,6 +158,8 @@ class ComponentPaparazziShowkaseTestPreview(
class ColorPaparazziShowkaseTestPreview(
private val showkaseBrowserColor: ShowkaseBrowserColor
) : PaparazziShowkaseTestPreview {
override val showkaseBrowserElement: ShowkaseBrowserElement = showkaseBrowserColor

@Composable
override fun Content() {
Box(
Expand All @@ -170,6 +177,8 @@ class ColorPaparazziShowkaseTestPreview(
class TypographyPaparazziShowkaseTestPreview(
private val showkaseBrowserTypography: ShowkaseBrowserTypography
) : PaparazziShowkaseTestPreview {
override val showkaseBrowserElement: ShowkaseBrowserElement = showkaseBrowserTypography

@Composable
override fun Content() {
BasicText(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ data class ShowkaseBrowserColor(
val colorName: String,
val colorKDoc: String,
val color: Color
)
) : ShowkaseBrowserElement {
override val group: String = colorGroup
override val name: String = colorName
override val kDoc: String = colorKDoc
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import androidx.compose.runtime.Composable
// TODO(vinaygaba): Move it to a different module that has Android/Compose dependencies hoooked up.
// This was added here only because this module has compose dependencies.
data class ShowkaseBrowserComponent(
val componentKey: String,
val group: String,
val componentKey: String,
override val group: String,
val componentName: String,
val componentKDoc: String,
val component: @Composable () -> Unit,
Expand All @@ -16,4 +16,7 @@ data class ShowkaseBrowserComponent(
val heightDp: Int? = null,
val tags: List<String> = emptyList(),
val extraMetadata: List<String> = emptyList()
)
) : ShowkaseBrowserElement {
override val name: String = componentName
override val kDoc: String = componentKDoc
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.airbnb.android.showkase.models

sealed interface ShowkaseBrowserElement {
val group: String
val name: String
val kDoc: String
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ data class ShowkaseBrowserTypography(
val typographyName: String,
val typographyKDoc: String,
val textStyle: TextStyle,
)
) : ShowkaseBrowserElement {
override val group: String = typographyGroup
override val name: String = typographyName
override val kDoc: String = typographyKDoc
}