Skip to content

Commit

Permalink
Move Test tags to separate constants
Browse files Browse the repository at this point in the history
  • Loading branch information
Siddharth Agarwal authored and siddh1004 committed Jul 17, 2024
1 parent 0fb7824 commit 7f80ac4
Showing 1 changed file with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,25 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.unit.dp
import org.hisp.dhis.mobile.ui.designsystem.component.NavigationBarTestTags.NAVIGATION_BAR
import org.hisp.dhis.mobile.ui.designsystem.component.NavigationBarTestTags.NAVIGATION_BAR_BORDER
import org.hisp.dhis.mobile.ui.designsystem.component.NavigationBarTestTags.NAVIGATION_BAR_CONTAINER
import org.hisp.dhis.mobile.ui.designsystem.component.NavigationBarTestTags.NAVIGATION_BAR_ITEM_BADGE_PREFIX
import org.hisp.dhis.mobile.ui.designsystem.component.NavigationBarTestTags.NAVIGATION_BAR_ITEM_LABEL_PREFIX
import org.hisp.dhis.mobile.ui.designsystem.component.NavigationBarTestTags.NAVIGATION_BAR_ITEM_PREFIX
import org.hisp.dhis.mobile.ui.designsystem.theme.Outline
import org.hisp.dhis.mobile.ui.designsystem.theme.SurfaceColor
import org.hisp.dhis.mobile.ui.designsystem.theme.TextColor

object NavigationBarTestTags {
const val NAVIGATION_BAR_CONTAINER = "NAVIGATION_BAR_CONTAINER"
const val NAVIGATION_BAR_BORDER = "NAVIGATION_BAR_BORDER"
const val NAVIGATION_BAR = "NAVIGATION_BAR"
const val NAVIGATION_BAR_ITEM_PREFIX = "NAVIGATION_BAR_ITEM_"
const val NAVIGATION_BAR_ITEM_LABEL_PREFIX = "NAVIGATION_BAR_ITEM_LABEL_"
const val NAVIGATION_BAR_ITEM_BADGE_PREFIX = "NAVIGATION_BAR_ITEM_BADGE_"
}

@Composable
fun NavigationBar(
modifier: Modifier = Modifier,
Expand All @@ -24,28 +39,28 @@ fun NavigationBar(
onItemClick: (Int) -> Unit,
) {
Column(
modifier = modifier.testTag("NAVIGATION_BAR_CONTAINER"),
modifier = modifier.testTag(NAVIGATION_BAR_CONTAINER),
) {
HorizontalDivider(
modifier = Modifier.testTag("NAVIGATION_BAR_BORDER"),
modifier = Modifier.testTag(NAVIGATION_BAR_BORDER),
thickness = 0.6.dp,
color = Outline.Light,
)
androidx.compose.material3.NavigationBar(
modifier = Modifier.testTag("NAVIGATION_BAR"),
modifier = Modifier.testTag(NAVIGATION_BAR),
containerColor = SurfaceColor.ContainerLowest,
) {
items.forEachIndexed { index, item ->
val selected = selectedItemIndex == index
NavigationBarItem(
modifier = Modifier.testTag("NAVIGATION_BAR_ITEM_${item.label}"),
modifier = Modifier.testTag("$NAVIGATION_BAR_ITEM_PREFIX${item.label}"),
colors = navigationBarItemColors(),
icon = {
NavigationBarItemIcon(item = item, selected = selected)
},
label = {
Text(
modifier = Modifier.testTag("NAVIGATION_BAR_ITEM_LABEL_${item.label}"),
modifier = Modifier.testTag("$NAVIGATION_BAR_ITEM_LABEL_PREFIX${item.label}"),
text = item.label,
)
},
Expand Down Expand Up @@ -77,7 +92,7 @@ fun NavigationBarItemIcon(item: NavigationBarItem, selected: Boolean) {
val badgeYOffset = if (!item.badgeText.isNullOrEmpty()) (-4).dp else 0.dp

ErrorBadge(
modifier = Modifier.testTag("NAVIGATION_BAR_ITEM_BADGE_${item.label}")
modifier = Modifier.testTag("$NAVIGATION_BAR_ITEM_BADGE_PREFIX${item.label}")
.align(Alignment.TopEnd)
.offset(
x = badgeXOffset,
Expand Down

0 comments on commit 7f80ac4

Please sign in to comment.