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

chore(snackbars): add paparazzi tests #131

Merged
merged 2 commits into from
Apr 20, 2023
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
2 changes: 2 additions & 0 deletions snackbars/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ plugins {
id("kotlin-android")
id("VitaminComposeLibraryPlugin")
id("com.vanniktech.maven.publish")
id("app.cash.paparazzi")
}

dependencies {
api(project(":foundation:foundation"))
api(project(":buttons"))
implementation(AndroidX.compose.ui.tooling)
testImplementation("com.google.testparameterinjector:test-parameter-injector:1.8")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.decathlon.vitamin.compose.snackbars

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.material.Scaffold
import androidx.compose.material.Text
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import app.cash.paparazzi.Paparazzi
import com.decathlon.vitamin.compose.foundation.VitaminTheme
import com.decathlon.vitamin.compose.snackbars.utils.SnackbarVariantsFactory
import com.decathlon.vitamin.compose.snackbars.utils.Theme
import com.decathlon.vitamin.compose.snackbars.utils.Variant
import com.google.testing.junit.testparameterinjector.TestParameter
import com.google.testing.junit.testparameterinjector.TestParameterInjector
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith


@RunWith(TestParameterInjector::class)
class VitaminSnackbarPrimaryTest(
@TestParameter val variant: Variant
) {
@get:Rule
val paparazzi = Paparazzi()

@Test
fun medium(@TestParameter theme: Theme) {
paparazzi.snapshot {
VitaminTheme(theme == Theme.Dark) {
Scaffold { padding ->
Column(
modifier = Modifier.padding(padding),
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
Text(text = variant.name, style = VitaminTheme.typography.subtitle1)
SnackbarVariantsFactory.Snackbar(
variant = variant
)
SnackbarVariantsFactory.Snackbar(
variant = variant,
action = {
Button(
text = "Button",
onClick = { /*Not used in this context*/ }
)
}
)
SnackbarVariantsFactory.Snackbar(
variant = variant,
action = {
Button(
text = "Button",
onClick = { /*Not used in this context*/ }
)
},
actionOnNewLine = true
)
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.decathlon.vitamin.compose.snackbars.utils

import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import com.decathlon.vitamin.compose.snackbars.VitaminSnackbars
import com.decathlon.vitamin.compose.snackbars.VitaminSnackbarsActions

object SnackbarVariantsFactory {

@Composable
fun Snackbar(
variant: Variant,
modifier: Modifier = Modifier,
text: String = "This is the description of the snackbar",
actionOnNewLine: Boolean = false,
action: @Composable (VitaminSnackbarsActions.() -> Unit)? = null
) {
when (variant) {
Variant.Primary -> VitaminSnackbars.Primary(
modifier = modifier,
text = text,
action = action,
actionOnNewLine = actionOnNewLine
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.decathlon.vitamin.compose.snackbars.utils

enum class Theme { Light, Dark }
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.decathlon.vitamin.compose.snackbars.utils

enum class Variant {
Primary
}
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.