Skip to content

Commit

Permalink
chore(tabs): add paparazzi tests (#164)
Browse files Browse the repository at this point in the history
  • Loading branch information
FDELAHA24 authored Jul 17, 2023
1 parent c64ddc7 commit 4d95fc9
Show file tree
Hide file tree
Showing 9 changed files with 163 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tabs/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ plugins {
id("kotlin-android")
id("VitaminComposeLibraryPlugin")
id("com.vanniktech.maven.publish")
id("app.cash.paparazzi")
}

dependencies {
api(project(":foundation:foundation"))
implementation(AndroidX.compose.ui.tooling)
testImplementation("com.google.testparameterinjector:test-parameter-injector:1.8")
testImplementation(project(":foundation:foundation-icons"))
}
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),
)

}
}
}
}
}
}

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
}
}
}

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 }
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
}
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 4d95fc9

Please sign in to comment.