diff --git a/designsystem/src/androidUnitTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/AssistChipTest.kt b/designsystem/src/androidUnitTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/AssistChipSanpshotTest.kt similarity index 93% rename from designsystem/src/androidUnitTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/AssistChipTest.kt rename to designsystem/src/androidUnitTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/AssistChipSanpshotTest.kt index e4f791f5c..bc2f15d29 100644 --- a/designsystem/src/androidUnitTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/AssistChipTest.kt +++ b/designsystem/src/androidUnitTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/AssistChipSanpshotTest.kt @@ -13,7 +13,7 @@ import org.hisp.dhis.mobile.ui.designsystem.theme.Spacing import org.junit.Rule import org.junit.Test -class AssistChipTest { +class AssistChipSanpshotTest { @get:Rule val paparazzi = paparazzi() @@ -32,14 +32,14 @@ class AssistChipTest { ) }, onClick = {}, - badge = "3" + badge = "3", ) AssistChip( label = "Label", onClick = {}, - badge = "3" + badge = "3", ) } } } -} \ No newline at end of file +} diff --git a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/AssistChip.kt b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/AssistChip.kt index 74bbd8677..384a53955 100644 --- a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/AssistChip.kt +++ b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/AssistChip.kt @@ -18,6 +18,7 @@ import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.layout.onSizeChanged +import androidx.compose.ui.platform.testTag import androidx.compose.ui.unit.IntOffset import org.hisp.dhis.mobile.ui.designsystem.theme.Outline import org.hisp.dhis.mobile.ui.designsystem.theme.Ripple @@ -49,11 +50,17 @@ fun AssistChip( val interactionSource = remember { MutableInteractionSource() } val isPressed by interactionSource.collectIsPressedAsState() - Box(modifier = modifier) { + Box(modifier = Modifier) { CompositionLocalProvider(LocalRippleTheme provides Ripple.CustomDHISRippleTheme()) { AssistChip( onClick = { onClick.invoke() }, - label = { Text(label, color = TextColor.OnSurfaceVariant) }, + label = { + Text( + label, + color = TextColor.OnSurfaceVariant, + ) + }, + modifier = modifier, enabled = enabled, colors = if (isPressed) { AssistChipDefaults.assistChipColors( @@ -81,7 +88,8 @@ fun AssistChip( modifier = Modifier .align(Alignment.TopEnd) .onSizeChanged { offset = IntOffset(it.width / 3, it.height / 3) } - .offset { offset }, + .offset { offset } + .testTag("ASSIST_CHIP_BADGE"), text = badge, ) } diff --git a/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/AssistChipTest.kt b/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/AssistChipTest.kt new file mode 100644 index 000000000..a9eda1a57 --- /dev/null +++ b/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/AssistChipTest.kt @@ -0,0 +1,39 @@ +package org.hisp.dhis.mobile.ui.designsystem.component + +import androidx.compose.foundation.layout.size +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.Search +import androidx.compose.material3.AssistChipDefaults +import androidx.compose.material3.Icon +import androidx.compose.ui.Modifier +import androidx.compose.ui.test.junit4.createComposeRule +import androidx.compose.ui.test.onNodeWithTag +import org.junit.Rule +import org.junit.Test + +class AssistChipTest { + + @get:Rule + val rule = createComposeRule() + + @Test + fun assistChipShouldDisplayBadges() { + rule.setContent { + AssistChip( + label = "Label", + icon = { + Icon( + imageVector = Icons.Filled.Search, + contentDescription = "search icon", + modifier = Modifier + .size(AssistChipDefaults.IconSize), + ) + }, + onClick = {}, + badge = "2", + ) + } + + rule.onNodeWithTag("ASSIST_CHIP_BADGE").assertExists() + } +}