Skip to content

Commit

Permalink
Add MenuItemTest
Browse files Browse the repository at this point in the history
  • Loading branch information
Siddharth Agarwal committed Sep 5, 2024
1 parent d4233f8 commit f418a68
Show file tree
Hide file tree
Showing 6 changed files with 203 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import org.hisp.dhis.mobile.ui.designsystem.component.ColumnComponentContainer
import org.hisp.dhis.mobile.ui.designsystem.component.ColumnScreenContainer
import org.hisp.dhis.mobile.ui.designsystem.component.MenuItem
import org.hisp.dhis.mobile.ui.designsystem.component.MenuItemData
import org.hisp.dhis.mobile.ui.designsystem.component.MenuItemState
import org.hisp.dhis.mobile.ui.designsystem.component.MenuItemStyle
import org.hisp.dhis.mobile.ui.designsystem.component.MenuLeadingElement
import org.hisp.dhis.mobile.ui.designsystem.component.MenuTrailingElement
import org.hisp.dhis.mobile.ui.designsystem.component.menuItem.MenuItem
import org.hisp.dhis.mobile.ui.designsystem.component.menuItem.MenuItemData
import org.hisp.dhis.mobile.ui.designsystem.component.menuItem.MenuItemState
import org.hisp.dhis.mobile.ui.designsystem.component.menuItem.MenuItemStyle
import org.hisp.dhis.mobile.ui.designsystem.component.menuItem.MenuLeadingElement
import org.hisp.dhis.mobile.ui.designsystem.component.menuItem.MenuTrailingElement

@Composable
fun MenuItemScreen() {
Expand All @@ -35,7 +35,7 @@ fun MenuItemScreen() {
modifier = Modifier.weight(1f),
menuItemData = MenuItemData(
label = "Menu Item",
supportingText = "Supporting Text",
supportingText = "Support Text",
showDivider = true,
leadingElement = MenuLeadingElement.Icon(
icon = Icons.Outlined.Done,
Expand All @@ -50,7 +50,7 @@ fun MenuItemScreen() {
modifier = Modifier.weight(1f),
menuItemData = MenuItemData(
label = "Menu Item",
supportingText = "Supporting Text",
supportingText = "Support Text",
showDivider = true,
style = MenuItemStyle.ALERT,
leadingElement = MenuLeadingElement.Icon(
Expand All @@ -70,7 +70,7 @@ fun MenuItemScreen() {
modifier = Modifier.weight(1f),
menuItemData = MenuItemData(
label = "Menu Item",
supportingText = "Supporting Text",
supportingText = "Support Text",
showDivider = true,
state = MenuItemState.SELECTED,
leadingElement = MenuLeadingElement.Icon(
Expand All @@ -86,7 +86,7 @@ fun MenuItemScreen() {
modifier = Modifier.weight(1f),
menuItemData = MenuItemData(
label = "Menu Item",
supportingText = "Supporting Text",
supportingText = "Support Text",
showDivider = true,
state = MenuItemState.SELECTED,
style = MenuItemStyle.ALERT,
Expand All @@ -107,7 +107,7 @@ fun MenuItemScreen() {
modifier = Modifier.weight(1f),
menuItemData = MenuItemData(
label = "Menu Item",
supportingText = "Supporting Text",
supportingText = "Support Text",
showDivider = true,
state = MenuItemState.DISABLED,
leadingElement = MenuLeadingElement.Icon(
Expand All @@ -123,7 +123,7 @@ fun MenuItemScreen() {
modifier = Modifier.weight(1f),
menuItemData = MenuItemData(
label = "Menu Item",
supportingText = "Supporting Text",
supportingText = "Support Text",
showDivider = true,
state = MenuItemState.DISABLED,
style = MenuItemStyle.ALERT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import org.hisp.dhis.mobile.ui.designsystem.component.ColumnComponentContainer
import org.hisp.dhis.mobile.ui.designsystem.component.ColumnScreenContainer
import org.hisp.dhis.mobile.ui.designsystem.component.MenuItem
import org.hisp.dhis.mobile.ui.designsystem.component.MenuItemData
import org.hisp.dhis.mobile.ui.designsystem.component.MenuItemState
import org.hisp.dhis.mobile.ui.designsystem.component.MenuItemStyle
import org.hisp.dhis.mobile.ui.designsystem.component.MenuLeadingElement
import org.hisp.dhis.mobile.ui.designsystem.component.MenuTrailingElement
import org.hisp.dhis.mobile.ui.designsystem.component.menuItem.MenuItem
import org.hisp.dhis.mobile.ui.designsystem.component.menuItem.MenuItemData
import org.hisp.dhis.mobile.ui.designsystem.component.menuItem.MenuItemState
import org.hisp.dhis.mobile.ui.designsystem.component.menuItem.MenuItemStyle
import org.hisp.dhis.mobile.ui.designsystem.component.menuItem.MenuLeadingElement
import org.hisp.dhis.mobile.ui.designsystem.component.menuItem.MenuTrailingElement
import org.junit.Rule
import org.junit.Test

Expand All @@ -39,8 +39,8 @@ class MenuItemSnapshotTest {
MenuItem(
modifier = Modifier.weight(1f),
menuItemData = MenuItemData(
label = "Menu Item",
supportingText = "Supporting Text",
label = "Label",
supportingText = "Support Text",
showDivider = true,
leadingElement = MenuLeadingElement.Icon(
icon = Icons.Outlined.Done,
Expand All @@ -54,8 +54,8 @@ class MenuItemSnapshotTest {
MenuItem(
modifier = Modifier.weight(1f),
menuItemData = MenuItemData(
label = "Menu Item",
supportingText = "Supporting Text",
label = "Label",
supportingText = "Support Text",
showDivider = true,
style = MenuItemStyle.ALERT,
leadingElement = MenuLeadingElement.Icon(
Expand All @@ -74,8 +74,8 @@ class MenuItemSnapshotTest {
MenuItem(
modifier = Modifier.weight(1f),
menuItemData = MenuItemData(
label = "Menu Item",
supportingText = "Supporting Text",
label = "Label",
supportingText = "Support Text",
showDivider = true,
state = MenuItemState.SELECTED,
leadingElement = MenuLeadingElement.Icon(
Expand All @@ -90,8 +90,8 @@ class MenuItemSnapshotTest {
MenuItem(
modifier = Modifier.weight(1f),
menuItemData = MenuItemData(
label = "Menu Item",
supportingText = "Supporting Text",
label = "Label",
supportingText = "Support Text",
showDivider = true,
state = MenuItemState.SELECTED,
style = MenuItemStyle.ALERT,
Expand All @@ -111,8 +111,8 @@ class MenuItemSnapshotTest {
MenuItem(
modifier = Modifier.weight(1f),
menuItemData = MenuItemData(
label = "Menu Item",
supportingText = "Supporting Text",
label = "Label",
supportingText = "Support Text",
showDivider = true,
state = MenuItemState.DISABLED,
leadingElement = MenuLeadingElement.Icon(
Expand All @@ -127,8 +127,8 @@ class MenuItemSnapshotTest {
MenuItem(
modifier = Modifier.weight(1f),
menuItemData = MenuItemData(
label = "Menu Item",
supportingText = "Supporting Text",
label = "Label",
supportingText = "Support Text",
showDivider = true,
state = MenuItemState.DISABLED,
style = MenuItemStyle.ALERT,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.hisp.dhis.mobile.ui.designsystem.component
package org.hisp.dhis.mobile.ui.designsystem.component.menuItem

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
Expand All @@ -18,6 +18,15 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.platform.testTag
import org.hisp.dhis.mobile.ui.designsystem.component.menuItem.MenuItemTestTags.MENU_ITEM_CONTAINER
import org.hisp.dhis.mobile.ui.designsystem.component.menuItem.MenuItemTestTags.MENU_ITEM_DIVIDER
import org.hisp.dhis.mobile.ui.designsystem.component.menuItem.MenuItemTestTags.MENU_ITEM_LEADING_ICON
import org.hisp.dhis.mobile.ui.designsystem.component.menuItem.MenuItemTestTags.MENU_ITEM_LEADING_INDENT
import org.hisp.dhis.mobile.ui.designsystem.component.menuItem.MenuItemTestTags.MENU_ITEM_SUPPORTING_TEXT
import org.hisp.dhis.mobile.ui.designsystem.component.menuItem.MenuItemTestTags.MENU_ITEM_TEXT
import org.hisp.dhis.mobile.ui.designsystem.component.menuItem.MenuItemTestTags.MENU_ITEM_TRAILING_ICON
import org.hisp.dhis.mobile.ui.designsystem.component.menuItem.MenuItemTestTags.MENU_ITEM_TRAILING_TEXT
import org.hisp.dhis.mobile.ui.designsystem.theme.Border
import org.hisp.dhis.mobile.ui.designsystem.theme.Outline
import org.hisp.dhis.mobile.ui.designsystem.theme.Spacing
Expand Down Expand Up @@ -50,7 +59,7 @@ fun MenuItem(
}

Column(
modifier = modifier,
modifier = modifier.testTag(MENU_ITEM_CONTAINER),
) {
Row(
modifier = Modifier
Expand All @@ -76,12 +85,14 @@ fun MenuItem(
modifier = Modifier.weight(1f),
) {
Text(
modifier = Modifier.testTag(MENU_ITEM_TEXT),
style = MaterialTheme.typography.bodyLarge,
color = if (menuItemData.style == MenuItemStyle.ALERT) SurfaceColor.Error else TextColor.OnSurface,
text = menuItemData.label,
)
if (!menuItemData.supportingText.isNullOrEmpty()) {
Text(
modifier = Modifier.testTag(MENU_ITEM_SUPPORTING_TEXT),
style = MaterialTheme.typography.bodyMedium,
color = if (menuItemData.style == MenuItemStyle.ALERT) TextColor.OnErrorContainer else TextColor.OnSurfaceVariant,
text = menuItemData.supportingText,
Expand All @@ -96,7 +107,9 @@ fun MenuItem(
}
if (menuItemData.showDivider) {
HorizontalDivider(
modifier = modifier.padding(vertical = Spacing.Spacing8),
modifier = modifier
.testTag(MENU_ITEM_DIVIDER)
.padding(vertical = Spacing.Spacing8),
thickness = Border.Thin,
color = Outline.Medium,
)
Expand All @@ -112,7 +125,12 @@ private fun MenuItemLeadingElement(
) {
when (leadingElement) {
is MenuLeadingElement.Indent -> {
Box(modifier = Modifier.padding(end = Spacing.Spacing12).size(Spacing.Spacing24))
Box(
modifier = Modifier
.testTag(MENU_ITEM_LEADING_INDENT)
.padding(end = Spacing.Spacing12)
.size(Spacing.Spacing24),
)
}

is MenuLeadingElement.Icon -> {
Expand All @@ -133,7 +151,10 @@ private fun MenuItemLeadingElement(
}
Icon(
imageVector = leadingElement.icon,
modifier = Modifier.padding(end = Spacing.Spacing12).size(Spacing.Spacing24),
modifier = Modifier
.testTag(MENU_ITEM_LEADING_ICON)
.padding(end = Spacing.Spacing12)
.size(Spacing.Spacing24),
contentDescription = null,
tint = iconTint,
)
Expand All @@ -151,16 +172,21 @@ private fun MenuItemTrailingElement(
when (trailingElement) {
is MenuTrailingElement.Icon -> {
Icon(
modifier = Modifier
.testTag(MENU_ITEM_TRAILING_ICON)
.padding(start = Spacing.Spacing12)
.size(Spacing.Spacing24),
imageVector = trailingElement.icon,
modifier = Modifier.padding(start = Spacing.Spacing12).size(Spacing.Spacing24),
contentDescription = null,
tint = if (state == MenuItemState.SELECTED) trailingElement.selectedTintColor else trailingElement.defaultTintColor,
)
}

is MenuTrailingElement.Text -> {
Text(
modifier = Modifier.padding(start = Spacing.Spacing12),
modifier = Modifier
.testTag(MENU_ITEM_TRAILING_TEXT)
.padding(start = Spacing.Spacing12),
style = MaterialTheme.typography.bodyLarge,
color = if (state == MenuItemState.SELECTED) TextColor.OnSurface else TextColor.OnSurfaceVariant,
text = trailingElement.text,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.hisp.dhis.mobile.ui.designsystem.component.menuItem

object MenuItemTestTags {
const val MENU_ITEM_CONTAINER = "MENU_ITEM_CONTAINER"
const val MENU_ITEM_TEXT = "MENU_ITEM_TEXT"
const val MENU_ITEM_SUPPORTING_TEXT = "MENU_ITEM_SUPPORTING_TEXT"
const val MENU_ITEM_DIVIDER = "MENU_ITEM_DIVIDER"
const val MENU_ITEM_LEADING_INDENT = "MENU_ITEM_LEADING_INDENT"
const val MENU_ITEM_LEADING_ICON = "MENU_ITEM_LEADING_ICON"
const val MENU_ITEM_TRAILING_ICON = "MENU_ITEM_TRAILING_ICON"
const val MENU_ITEM_TRAILING_TEXT = "MENU_ITEM_TRAILING_TEXT"
}
Loading

0 comments on commit f418a68

Please sign in to comment.