-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(ratings): add paparazzi tests (#166)
Co-authored-by: ManonPolle <[email protected]>
- Loading branch information
1 parent
ffaf6cb
commit 0ab2190
Showing
17 changed files
with
152 additions
and
0 deletions.
There are no files selected for viewing
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
95 changes: 95 additions & 0 deletions
95
ratings/src/test/kotlin/com/decathlon/ratings/VitaminRatingsPrimaryTest.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package com.decathlon.ratings | ||
|
||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Row | ||
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.ratings.utils.RatingVariantsFactory | ||
import com.decathlon.ratings.utils.Theme | ||
import com.decathlon.ratings.utils.Variant | ||
import com.decathlon.vitamin.compose.foundation.VitaminTheme | ||
import com.decathlon.vitamin.compose.ratings.VitaminRatingColors | ||
import com.decathlon.vitamin.compose.ratings.VitaminRatingSizes | ||
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 VitaminRatingsPrimaryTest( | ||
@TestParameter val variant: Variant | ||
) { | ||
@get:Rule | ||
val paparazzi = Paparazzi() | ||
|
||
@Test | ||
fun small(@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) | ||
RatingVariantsFactory.Rating( | ||
variant = variant, | ||
colors = VitaminRatingColors.primary(), | ||
size = VitaminRatingSizes.small(), | ||
) | ||
RatingVariantsFactory.Rating( | ||
variant = variant, | ||
colors = VitaminRatingColors.emphasis(), | ||
size = VitaminRatingSizes.small(), | ||
) | ||
RatingVariantsFactory.Rating( | ||
variant = variant, | ||
colors = VitaminRatingColors.emphasis(), | ||
size = VitaminRatingSizes.small(), | ||
enabled = false | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
@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) | ||
RatingVariantsFactory.Rating( | ||
variant = variant, | ||
colors = VitaminRatingColors.primary(), | ||
size = VitaminRatingSizes.medium(), | ||
) | ||
RatingVariantsFactory.Rating( | ||
variant = variant, | ||
colors = VitaminRatingColors.emphasis(), | ||
size = VitaminRatingSizes.medium(), | ||
) | ||
RatingVariantsFactory.Rating( | ||
variant = variant, | ||
colors = VitaminRatingColors.emphasis(), | ||
size = VitaminRatingSizes.medium(), | ||
enabled = false | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
ratings/src/test/kotlin/com/decathlon/ratings/utils/RatingVariantsFactory.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.decathlon.ratings.utils | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import com.decathlon.vitamin.compose.ratings.RatingColors | ||
import com.decathlon.vitamin.compose.ratings.RatingSizes | ||
import com.decathlon.vitamin.compose.ratings.VitaminRatings | ||
|
||
object RatingVariantsFactory { | ||
|
||
@Composable | ||
fun Rating( | ||
variant: Variant, | ||
size: RatingSizes, | ||
colors: RatingColors, | ||
modifier: Modifier = Modifier, | ||
number: Float = 3.865f, | ||
nbComments: Int = 42, | ||
enabled: Boolean = true | ||
) { | ||
when (variant) { | ||
Variant.ReadOnly -> VitaminRatings.ReadOnly( | ||
nbComments = nbComments, | ||
colors = colors, | ||
sizes = size, | ||
number = number, | ||
modifier = modifier, | ||
showNote = true | ||
) | ||
Variant.ReadOnlyCompact -> VitaminRatings.ReadOnlyCompact( | ||
nbComments = nbComments, | ||
colors = colors, | ||
sizes = size, | ||
number = number, | ||
modifier = modifier | ||
) | ||
Variant.Interactive -> VitaminRatings.Interactive( | ||
colors = colors, | ||
sizes = size, | ||
number = number.toInt(), | ||
modifier = modifier, | ||
enabled = enabled, | ||
onValueChange = {} | ||
) | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package com.decathlon.ratings.utils | ||
|
||
enum class Theme { Light, Dark } |
5 changes: 5 additions & 0 deletions
5
ratings/src/test/kotlin/com/decathlon/ratings/utils/Variant.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.decathlon.ratings.utils | ||
|
||
enum class Variant { | ||
ReadOnly, ReadOnlyCompact, Interactive | ||
} |
Binary file added
BIN
+24 KB
...es/com.decathlon.ratings_VitaminRatingsPrimaryTest_medium[Interactive,Dark].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+23.8 KB
...s/com.decathlon.ratings_VitaminRatingsPrimaryTest_medium[Interactive,Light].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+28.7 KB
...mages/com.decathlon.ratings_VitaminRatingsPrimaryTest_medium[ReadOnly,Dark].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+28.8 KB
...ages/com.decathlon.ratings_VitaminRatingsPrimaryTest_medium[ReadOnly,Light].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+21 KB
...om.decathlon.ratings_VitaminRatingsPrimaryTest_medium[ReadOnlyCompact,Dark].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+20.9 KB
...m.decathlon.ratings_VitaminRatingsPrimaryTest_medium[ReadOnlyCompact,Light].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+16.6 KB
...ges/com.decathlon.ratings_VitaminRatingsPrimaryTest_small[Interactive,Dark].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+16.6 KB
...es/com.decathlon.ratings_VitaminRatingsPrimaryTest_small[Interactive,Light].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+23 KB
...images/com.decathlon.ratings_VitaminRatingsPrimaryTest_small[ReadOnly,Dark].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+23.1 KB
...mages/com.decathlon.ratings_VitaminRatingsPrimaryTest_small[ReadOnly,Light].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+19.6 KB
...com.decathlon.ratings_VitaminRatingsPrimaryTest_small[ReadOnlyCompact,Dark].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+19.5 KB
...om.decathlon.ratings_VitaminRatingsPrimaryTest_small[ReadOnlyCompact,Light].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.