Skip to content

Commit

Permalink
test(modals): Add paparazzi tests
Browse files Browse the repository at this point in the history
  • Loading branch information
corentin-stamper committed Feb 3, 2023
1 parent f5b3775 commit 3f9ea4b
Show file tree
Hide file tree
Showing 13 changed files with 183 additions and 0 deletions.
2 changes: 2 additions & 0 deletions modals/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"))
implementation(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,132 @@
package com.decathlon.vitamin.compose.modals

import androidx.compose.material.Text
import app.cash.paparazzi.Paparazzi
import com.decathlon.vitamin.compose.foundation.VitaminTheme
import com.decathlon.vitamin.compose.modals.utils.DataFactory
import com.decathlon.vitamin.compose.modals.utils.Theme
import com.decathlon.vitamin.compose.modals.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 VitaminModalsPrimaryTest(
@TestParameter val variant: Variant
) {

@get:Rule
val paparazzi = Paparazzi()

@Test
fun primary(
@TestParameter theme: Theme
) {
paparazzi.snapshot {
VitaminTheme(theme == Theme.Dark) {
VitaminModals.Primary(
onDismissRequest = {},
iconRes = R.drawable.ic_vtmn_map_pin_line,
title = DataFactory.title,
content = {
Text(
text = DataFactory.message
)
},
positiveButton = {
VitaminModalButtons.Primary(
text = "Button",
onClick = {}
)
},
negativeButton = {
VitaminModalButtons.Primary(
text = "Button",
onClick = {}
)
}
)
}
}
}

@Test
fun primaryLongMessage(
@TestParameter theme: Theme
) {
paparazzi.snapshot {
VitaminTheme(theme == Theme.Dark) {
VitaminModals.Primary(
onDismissRequest = {},
iconRes = R.drawable.ic_vtmn_map_pin_line,
title = DataFactory.title,
content = {
Text(
text = DataFactory.longAnnotatedMessage
)
},
positiveButton = {
VitaminModalButtons.Primary(
text = "Button",
onClick = {}
)
},
negativeButton = {
VitaminModalButtons.Primary(
text = "Button",
onClick = {}
)
}
)
}
}
}

@Test
fun primaryWithoutButtons(
@TestParameter theme: Theme
) {
paparazzi.snapshot {
VitaminTheme(theme == Theme.Dark) {
VitaminModals.Primary(
onDismissRequest = {},
iconRes = R.drawable.ic_vtmn_map_pin_line,
title = DataFactory.title,
content = {
Text(
text = DataFactory.message
)
}
)
}
}
}

@Test
fun primaryWithNeutralButton(
@TestParameter theme: Theme
) {
paparazzi.snapshot {
VitaminTheme(theme == Theme.Dark) {
VitaminModals.Primary(
onDismissRequest = {},
iconRes = R.drawable.ic_vtmn_map_pin_line,
title = DataFactory.title,
content = {
Text(
text = DataFactory.message
)
},
neutralButton = {
VitaminModalButtons.Primary(
text = "Button",
onClick = {}
)
}
)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.decathlon.vitamin.compose.modals.utils

import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.withStyle

class DataFactory {

companion object {
internal val title: String = "Subtitle"
internal val message: String = "Lorem ipsum dolor sit amet, consectetur adipiscing " +
"elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut " +
"enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip " +
"ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate " +
"velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat " +
"cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id " +
"est laborum."
internal val longAnnotatedMessage: AnnotatedString = buildAnnotatedString {
append("$message\n\n")
withStyle(
style = SpanStyle(fontStyle = FontStyle.Italic)
) {
append("$message\n\n")
}
withStyle(
style = SpanStyle(fontWeight = FontWeight.Bold)
) {
append("$message\n\n")
}
append("$message\n\n")
withStyle(
style = SpanStyle(fontStyle = FontStyle.Italic)
) {
append(message)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.decathlon.vitamin.compose.modals.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.modals.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.
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.
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.
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.

0 comments on commit 3f9ea4b

Please sign in to comment.