-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(tabs): add paparazzi tests (#164)
- Loading branch information
Showing
9 changed files
with
163 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
62 changes: 62 additions & 0 deletions
62
tabs/src/test/kotlin/com/decathlon/vitamin/compose/tabs/VitaminTabsPrimaryTest.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,62 @@ | ||
package com.decathlon.vitamin.compose.tabs | ||
|
||
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.tabs.utils.TabsVariantsFactory | ||
import com.decathlon.vitamin.compose.tabs.utils.Theme | ||
import com.decathlon.vitamin.compose.tabs.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 VitaminTabsPrimaryTest( | ||
@TestParameter val variant: Variant | ||
) { | ||
@get:Rule | ||
val paparazzi = Paparazzi() | ||
|
||
@Suppress("LongMethod") | ||
@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) | ||
|
||
TabsVariantsFactory.Tabs( | ||
variant = variant, | ||
tabItems = TabsVariantsFactory.TabItems(variant), | ||
) | ||
|
||
TabsVariantsFactory.Tabs( | ||
variant = variant, | ||
tabItems = TabsVariantsFactory.TabItemsWithIcons(variant), | ||
) | ||
|
||
TabsVariantsFactory.Tabs( | ||
variant = variant, | ||
tabItems = TabsVariantsFactory.TabItemsWithTopIcons(variant), | ||
) | ||
|
||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
90 changes: 90 additions & 0 deletions
90
tabs/src/test/kotlin/com/decathlon/vitamin/compose/tabs/utils/TabsVariantsFactory.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,90 @@ | ||
package com.decathlon.vitamin.compose.tabs.utils | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.mutableStateListOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.vector.rememberVectorPainter | ||
import com.decathlon.vitamin.compose.VitaminIcons | ||
import com.decathlon.vitamin.compose.tabs.TabItem | ||
import com.decathlon.vitamin.compose.tabs.VitaminTabs | ||
import com.decathlon.vitamin.compose.vitaminicons.Line | ||
import com.decathlon.vitamin.compose.vitaminicons.line.Heart | ||
|
||
object TabsVariantsFactory { | ||
|
||
@Suppress("LongMethod") | ||
@Composable | ||
fun Tabs( | ||
variant: Variant, | ||
tabItems: List<TabItem>, | ||
modifier: Modifier = Modifier, | ||
) { | ||
when (variant) { | ||
Variant.Fixed -> VitaminTabs.Fixed( | ||
modifier = modifier, | ||
tabItems = tabItems | ||
) {} | ||
|
||
Variant.Scrollable -> VitaminTabs.Scrollable( | ||
modifier = modifier, | ||
tabItems = tabItems | ||
) {} | ||
|
||
} | ||
} | ||
|
||
@Composable | ||
fun TabItems(variant: Variant): List<TabItem> { | ||
val list = remember { mutableStateListOf<TabItem>() } | ||
for (i in 0..getItemCountForVariant(variant)) { | ||
list.add( | ||
TabItem( | ||
label = "Label $i", | ||
selected = i == 0 | ||
) | ||
) | ||
} | ||
return list | ||
} | ||
|
||
@Composable | ||
fun TabItemsWithIcons(variant: Variant): List<TabItem> { | ||
val list = remember { mutableStateListOf<TabItem>() } | ||
for (i in 0..getItemCountForVariant(variant)) { | ||
list.add( | ||
TabItem( | ||
label = "Label $i", | ||
icon = rememberVectorPainter(VitaminIcons.Line.Heart), | ||
selected = i == 0 | ||
) | ||
) | ||
} | ||
return list | ||
} | ||
|
||
@Composable | ||
fun TabItemsWithTopIcons(variant: Variant): List<TabItem> { | ||
val list = remember { mutableStateListOf<TabItem>() } | ||
for (i in 0..getItemCountForVariant(variant)) { | ||
list.add( | ||
TabItem( | ||
label = "Label $i", | ||
icon = rememberVectorPainter(VitaminIcons.Line.Heart), | ||
topIcon = true, | ||
selected = i == 0 | ||
) | ||
) | ||
} | ||
return list | ||
} | ||
|
||
private fun getItemCountForVariant(variant: Variant): Int { | ||
return if (variant == Variant.Scrollable) { | ||
10 | ||
} else { | ||
3 | ||
} | ||
} | ||
} | ||
|
3 changes: 3 additions & 0 deletions
3
tabs/src/test/kotlin/com/decathlon/vitamin/compose/tabs/utils/Theme.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,3 @@ | ||
package com.decathlon.vitamin.compose.tabs.utils | ||
|
||
enum class Theme { Light, Dark } |
5 changes: 5 additions & 0 deletions
5
tabs/src/test/kotlin/com/decathlon/vitamin/compose/tabs/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.vitamin.compose.tabs.utils | ||
|
||
enum class Variant { | ||
Fixed, Scrollable | ||
} |
Binary file added
BIN
+23 KB
...om.decathlon.vitamin.compose.tabs_VitaminTabsPrimaryTest_medium[Fixed,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.4 KB
...m.decathlon.vitamin.compose.tabs_VitaminTabsPrimaryTest_medium[Fixed,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
+24.8 KB
...cathlon.vitamin.compose.tabs_VitaminTabsPrimaryTest_medium[Scrollable,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
+25.3 KB
...athlon.vitamin.compose.tabs_VitaminTabsPrimaryTest_medium[Scrollable,Light].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.