Skip to content

Commit

Permalink
add: [ANDROAPP-6097] Unit test added
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidAparicioAlbaAsenjo committed May 14, 2024
1 parent 82f0d68 commit 08b45f5
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -32,14 +32,14 @@ class AssistChipTest {
)
},
onClick = {},
badge = "3"
badge = "3",
)
AssistChip(
label = "Label",
onClick = {},
badge = "3"
badge = "3",
)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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()
}
}

0 comments on commit 08b45f5

Please sign in to comment.