Skip to content

Commit

Permalink
chore(switches): add paparazzi tests (#118)
Browse files Browse the repository at this point in the history
Co-authored-by: ManonPolle <[email protected]>
Co-authored-by: ManonPolle <[email protected]>
  • Loading branch information
3 people committed Jun 22, 2023
1 parent 6f71eb5 commit a3be2ab
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
Expand All @@ -21,6 +22,7 @@ fun SampleRow(
) {
Row(
horizontalArrangement = Arrangement.SpaceAround,
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier
.fillMaxWidth()
.background(color = color)
Expand Down
2 changes: 2 additions & 0 deletions switches/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ 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")
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,29 @@ import androidx.compose.material.SwitchDefaults
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.compositeOver
import com.decathlon.vitamin.compose.foundation.VitaminPalette
import com.decathlon.vitamin.compose.foundation.VitaminTheme
import com.decathlon.vitamin.compose.foundation.VtmnStatesDisabled

object VitaminSwitchesColors {
@Composable
fun primary(
checkedThumbColor: Color = VitaminTheme.colors.vtmnContentActive,
checkedTrackColor: Color = VitaminTheme.colors.vtmnContentActive,
checkedTrackColor: Color = VitaminPalette.vtmnBlue200,
checkedTrackAlpha: Float = 0.54f,
uncheckedThumbColor: Color = VitaminTheme.colors.vtmnContentPrimaryReversed,
uncheckedThumbColor: Color = VitaminPalette.vtmnWhite,
uncheckedTrackColor: Color = VitaminTheme.colors.vtmnContentInactive,
uncheckedTrackAlpha: Float = 1f,
disabledCheckedThumbColor: Color = VitaminTheme.colors.vtmnContentActive
disabledCheckedThumbColor: Color = checkedThumbColor
.copy(alpha = VtmnStatesDisabled)
.compositeOver(VitaminTheme.colors.vtmnContentPrimaryReversed),
disabledCheckedTrackColor: Color = VitaminTheme.colors.vtmnContentActive
disabledCheckedTrackColor: Color = checkedTrackColor
.copy(alpha = VtmnStatesDisabled)
.compositeOver(VitaminTheme.colors.vtmnContentPrimaryReversed),
disabledUncheckedThumbColor: Color = VitaminTheme.colors.vtmnContentPrimaryReversed
disabledUncheckedThumbColor: Color = uncheckedThumbColor
.copy(alpha = VtmnStatesDisabled)
.compositeOver(VitaminTheme.colors.vtmnContentPrimaryReversed),
disabledUncheckedTrackColor: Color = VitaminTheme.colors.vtmnContentInactive
disabledUncheckedTrackColor: Color = uncheckedTrackColor
.copy(alpha = VtmnStatesDisabled)
.compositeOver(VitaminTheme.colors.vtmnContentPrimaryReversed)
): SwitchColors = SwitchDefaults.colors(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.decathlon.vitamin.compose.switches

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
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.switches.utils.Theme
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 VitaminSwitchesPrimaryTest {
@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)
.fillMaxWidth()
.background(VitaminTheme.colors.vtmnBackgroundPrimary),
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
Text(text = "Primary", style = VitaminTheme.typography.subtitle1)
Row(
horizontalArrangement = Arrangement.spacedBy(4.dp)
) {
VitaminSwitches.Primary(
checked = true,
enabled = true
)
VitaminSwitches.Primary(
checked = false,
enabled = true
)
}
Row(
horizontalArrangement = Arrangement.spacedBy(4.dp)
) {
VitaminSwitches.Primary(
checked = true,
enabled = false
)
VitaminSwitches.Primary(
checked = false,
enabled = false
)
}
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.decathlon.vitamin.compose.switches.utils

enum class Theme { Light, Dark }
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 a3be2ab

Please sign in to comment.