Skip to content

Commit

Permalink
ANDROAPP-5684-mobile-ui-legend-component-info-icon-visibility (#131)
Browse files Browse the repository at this point in the history
* Hide legend info icon when there is no popup description data

* Disable click when legend doesn't contain popup description data

* Fix broken tests

* Add test for legend click action
  • Loading branch information
msasikanth authored Nov 2, 2023
1 parent 6ab2ffb commit 67cce3e
Show file tree
Hide file tree
Showing 25 changed files with 134 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.compose.ui.Modifier
import org.hisp.dhis.mobile.ui.designsystem.component.ColumnComponentContainer
import org.hisp.dhis.mobile.ui.designsystem.component.Legend
import org.hisp.dhis.mobile.ui.designsystem.component.LegendData
import org.hisp.dhis.mobile.ui.designsystem.component.LegendDescriptionData
import org.hisp.dhis.mobile.ui.designsystem.component.SubTitle
import org.hisp.dhis.mobile.ui.designsystem.theme.Spacing
import org.hisp.dhis.mobile.ui.designsystem.theme.SurfaceColor
Expand All @@ -33,5 +34,25 @@ fun LegendScreen() {
" consectetur adipiscing elit. Maecenas dolor lacus,",
),
)

SubTitle("Legend with popup description")
Legend(
LegendData(
color = SurfaceColor.CustomGreen,
title = "Legend with popup",
popUpLegendDescriptionData = listOf(
LegendDescriptionData(
color = SurfaceColor.CustomGreen,
text = "Item 1",
range = 0..300,
),
LegendDescriptionData(
color = SurfaceColor.CustomGreen,
text = "Item 2",
range = 301..600,
),
),
),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,25 @@ fun Legend(
var showBottomSheetShell by rememberSaveable { mutableStateOf(false) }

CompositionLocalProvider(LocalRippleTheme provides Ripple.CustomDHISRippleTheme) {
Column(
modifier = modifier
val hasPopupLegendDescriptionData = legendData.popUpLegendDescriptionData.orEmpty().isNotEmpty()
val clickableModifier = if (hasPopupLegendDescriptionData) {
Modifier
.clickable(
onClick = {
legendData.popUpLegendDescriptionData?.let {
showBottomSheetShell = true
}
},
)
.hoverPointerIcon(true),
.hoverPointerIcon(true)
} else {
Modifier
}

Column(
modifier = modifier
.then(clickableModifier)
.testTag("LEGEND"),
) {
Row(
modifier = Modifier
Expand All @@ -76,11 +85,14 @@ fun Legend(
.weight(2f, true),
style = MaterialTheme.typography.bodyMedium,
)
Icon(
imageVector = Icons.Outlined.HelpOutline,
contentDescription = "Legend Icon",
modifier = Modifier.size(InternalSizeValues.Size18),
)

if (hasPopupLegendDescriptionData) {
Icon(
imageVector = Icons.Outlined.HelpOutline,
contentDescription = "Legend Icon",
modifier = Modifier.size(InternalSizeValues.Size18),
)
}
}
Divider(
modifier = Modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.test.assertHasClickAction
import androidx.compose.ui.test.assertHasNoClickAction
import androidx.compose.ui.test.assertIsEnabled
import androidx.compose.ui.test.assertIsNotEnabled
import androidx.compose.ui.test.junit4.createComposeRule
Expand Down Expand Up @@ -212,7 +212,7 @@ class BasicInputImageTest {
}
rule.onNodeWithTag("INPUT_IMAGE").assertExists()
rule.onNodeWithTag("INPUT_IMAGE_LEGEND").assertExists()
rule.onNodeWithTag("INPUT_IMAGE_LEGEND").assertHasClickAction()
rule.onNodeWithTag("INPUT_IMAGE_LEGEND").assertHasNoClickAction()
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.test.assert
import androidx.compose.ui.test.assertHasClickAction
import androidx.compose.ui.test.assertHasNoClickAction
import androidx.compose.ui.test.assertIsFocused
import androidx.compose.ui.test.assertIsNotEnabled
import androidx.compose.ui.test.assertIsNotFocused
Expand Down Expand Up @@ -235,7 +235,7 @@ class InputCheckBoxTest {

rule.onNodeWithTag("INPUT_CHECK_BOX").assertExists()
rule.onNodeWithTag("INPUT_CHECK_BOX_LEGEND").assertExists()
rule.onNodeWithTag("INPUT_CHECK_BOX_LEGEND").assertHasClickAction()
rule.onNodeWithTag("INPUT_CHECK_BOX_LEGEND").assertHasNoClickAction()
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.test.assertHasClickAction
import androidx.compose.ui.test.assertHasNoClickAction
import androidx.compose.ui.test.assertIsEnabled
import androidx.compose.ui.test.assertIsNotEnabled
import androidx.compose.ui.test.junit4.createComposeRule
Expand Down Expand Up @@ -143,7 +143,7 @@ class InputCoordinateTest {
}
rule.onNodeWithTag("INPUT_COORDINATE").assertExists()
rule.onNodeWithTag("INPUT_COORDINATE_LEGEND").assertExists()
rule.onNodeWithTag("INPUT_COORDINATE_LEGEND").assertHasClickAction()
rule.onNodeWithTag("INPUT_COORDINATE_LEGEND").assertHasNoClickAction()
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.test.assertHasClickAction
import androidx.compose.ui.test.assertHasNoClickAction
import androidx.compose.ui.test.assertIsEnabled
import androidx.compose.ui.test.assertIsNotEnabled
import androidx.compose.ui.test.assertTextEquals
Expand Down Expand Up @@ -142,7 +142,7 @@ class InputDropDownTest {
}
rule.onNodeWithTag("INPUT_DROPDOWN").assertExists()
rule.onNodeWithTag("INPUT_DROPDOWN_LEGEND").assertExists()
rule.onNodeWithTag("INPUT_DROPDOWN_LEGEND").assertHasClickAction()
rule.onNodeWithTag("INPUT_DROPDOWN_LEGEND").assertHasNoClickAction()
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.test.assert
import androidx.compose.ui.test.assertHasClickAction
import androidx.compose.ui.test.assertHasNoClickAction
import androidx.compose.ui.test.assertIsEnabled
import androidx.compose.ui.test.assertIsNotEnabled
import androidx.compose.ui.test.assertTextEquals
Expand Down Expand Up @@ -151,7 +151,7 @@ class InputEmailTest {
}
rule.onNodeWithTag("INPUT_EMAIL").assertExists()
rule.onNodeWithTag("INPUT_EMAIL_LEGEND").assertExists()
rule.onNodeWithTag("INPUT_EMAIL_LEGEND").assertHasClickAction()
rule.onNodeWithTag("INPUT_EMAIL_LEGEND").assertHasNoClickAction()
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.test.assert
import androidx.compose.ui.test.assertHasClickAction
import androidx.compose.ui.test.assertHasNoClickAction
import androidx.compose.ui.test.assertIsNotEnabled
import androidx.compose.ui.test.assertTextEquals
import androidx.compose.ui.test.hasText
Expand Down Expand Up @@ -123,7 +123,7 @@ class InputIntegerTest {
}
rule.onNodeWithTag("INPUT_INTEGER").assertExists()
rule.onNodeWithTag("INPUT_INTEGER_LEGEND").assertExists()
rule.onNodeWithTag("INPUT_INTEGER_LEGEND").assertHasClickAction()
rule.onNodeWithTag("INPUT_INTEGER_LEGEND").assertHasNoClickAction()
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.test.assert
import androidx.compose.ui.test.assertHasClickAction
import androidx.compose.ui.test.assertHasNoClickAction
import androidx.compose.ui.test.assertIsNotEnabled
import androidx.compose.ui.test.assertTextEquals
import androidx.compose.ui.test.hasText
Expand Down Expand Up @@ -131,7 +131,7 @@ class InputLetterTest {
}
rule.onNodeWithTag("INPUT_LETTER").assertExists()
rule.onNodeWithTag("INPUT_LETTER_LEGEND").assertExists()
rule.onNodeWithTag("INPUT_LETTER_LEGEND").assertHasClickAction()
rule.onNodeWithTag("INPUT_LETTER_LEGEND").assertHasNoClickAction()
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.test.assert
import androidx.compose.ui.test.assertHasClickAction
import androidx.compose.ui.test.assertHasNoClickAction
import androidx.compose.ui.test.assertIsEnabled
import androidx.compose.ui.test.assertIsNotEnabled
import androidx.compose.ui.test.assertTextEquals
Expand Down Expand Up @@ -152,7 +152,7 @@ class InputLinkTest {
}
rule.onNodeWithTag("INPUT_LINK").assertExists()
rule.onNodeWithTag("INPUT_LINK_LEGEND").assertExists()
rule.onNodeWithTag("INPUT_LINK_LEGEND").assertHasClickAction()
rule.onNodeWithTag("INPUT_LINK_LEGEND").assertHasNoClickAction()
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.test.assert
import androidx.compose.ui.test.assertHasClickAction
import androidx.compose.ui.test.assertHasNoClickAction
import androidx.compose.ui.test.assertIsNotEnabled
import androidx.compose.ui.test.assertTextEquals
import androidx.compose.ui.test.hasText
Expand Down Expand Up @@ -131,7 +131,7 @@ class InputLongTextTest {
}
rule.onNodeWithTag("INPUT_LONG_TEXT").assertExists()
rule.onNodeWithTag("INPUT_LONG_TEXT_LEGEND").assertExists()
rule.onNodeWithTag("INPUT_LONG_TEXT_LEGEND").assertHasClickAction()
rule.onNodeWithTag("INPUT_LONG_TEXT_LEGEND").assertHasNoClickAction()
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.test.assert
import androidx.compose.ui.test.assertHasClickAction
import androidx.compose.ui.test.assertHasNoClickAction
import androidx.compose.ui.test.assertIsNotEnabled
import androidx.compose.ui.test.hasText
import androidx.compose.ui.test.junit4.createComposeRule
Expand Down Expand Up @@ -121,7 +121,7 @@ class InputNegativeIntegerTest {
}
rule.onNodeWithTag("INPUT_NEGATIVE_INTEGER").assertExists()
rule.onNodeWithTag("INPUT_NEGATIVE_INTEGER_LEGEND").assertExists()
rule.onNodeWithTag("INPUT_NEGATIVE_INTEGER_LEGEND").assertHasClickAction()
rule.onNodeWithTag("INPUT_NEGATIVE_INTEGER_LEGEND").assertHasNoClickAction()
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.test.assert
import androidx.compose.ui.test.assertHasClickAction
import androidx.compose.ui.test.assertHasNoClickAction
import androidx.compose.ui.test.assertIsNotEnabled
import androidx.compose.ui.test.assertTextEquals
import androidx.compose.ui.test.hasText
Expand Down Expand Up @@ -131,7 +131,7 @@ class InputNumberTest {
}
rule.onNodeWithTag("INPUT_NUMBER").assertExists()
rule.onNodeWithTag("INPUT_NUMBER_LEGEND").assertExists()
rule.onNodeWithTag("INPUT_NUMBER_LEGEND").assertHasClickAction()
rule.onNodeWithTag("INPUT_NUMBER_LEGEND").assertHasNoClickAction()
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.test.assertHasClickAction
import androidx.compose.ui.test.assertHasNoClickAction
import androidx.compose.ui.test.assertIsEnabled
import androidx.compose.ui.test.assertIsNotEnabled
import androidx.compose.ui.test.assertTextEquals
Expand Down Expand Up @@ -146,7 +146,7 @@ class InputOrgUnitTest {
}
rule.onNodeWithTag("INPUT_ORG_UNIT").assertExists()
rule.onNodeWithTag("INPUT_ORG_UNIT_LEGEND").assertExists()
rule.onNodeWithTag("INPUT_ORG_UNIT_LEGEND").assertHasClickAction()
rule.onNodeWithTag("INPUT_ORG_UNIT_LEGEND").assertHasNoClickAction()
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.test.assert
import androidx.compose.ui.test.assertHasClickAction
import androidx.compose.ui.test.assertHasNoClickAction
import androidx.compose.ui.test.assertIsNotEnabled
import androidx.compose.ui.test.assertTextEquals
import androidx.compose.ui.test.hasText
Expand Down Expand Up @@ -122,7 +122,7 @@ class InputPercentageTest {
}
rule.onNodeWithTag("INPUT_PERCENTAGE").assertExists()
rule.onNodeWithTag("INPUT_PERCENTAGE_LEGEND").assertExists()
rule.onNodeWithTag("INPUT_PERCENTAGE_LEGEND").assertHasClickAction()
rule.onNodeWithTag("INPUT_PERCENTAGE_LEGEND").assertHasNoClickAction()
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.test.assertHasClickAction
import androidx.compose.ui.test.assertHasNoClickAction
import androidx.compose.ui.test.assertIsEnabled
import androidx.compose.ui.test.assertIsNotEnabled
import androidx.compose.ui.test.junit4.createComposeRule
Expand Down Expand Up @@ -141,7 +141,7 @@ class InputPolygonTest {
}
rule.onNodeWithTag("INPUT_POLYGON").assertExists()
rule.onNodeWithTag("INPUT_POLYGON_LEGEND").assertExists()
rule.onNodeWithTag("INPUT_POLYGON_LEGEND").assertHasClickAction()
rule.onNodeWithTag("INPUT_POLYGON_LEGEND").assertHasNoClickAction()
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.test.assert
import androidx.compose.ui.test.assertHasClickAction
import androidx.compose.ui.test.assertHasNoClickAction
import androidx.compose.ui.test.assertIsNotEnabled
import androidx.compose.ui.test.assertTextEquals
import androidx.compose.ui.test.hasText
Expand Down Expand Up @@ -123,7 +123,7 @@ class InputPositiveIntegerOrZeroTest {
}
rule.onNodeWithTag("INPUT_POSITIVE_INTEGER_OR_ZERO").assertExists()
rule.onNodeWithTag("INPUT_POSITIVE_INTEGER_OR_ZERO_LEGEND").assertExists()
rule.onNodeWithTag("INPUT_POSITIVE_INTEGER_OR_ZERO_LEGEND").assertHasClickAction()
rule.onNodeWithTag("INPUT_POSITIVE_INTEGER_OR_ZERO_LEGEND").assertHasNoClickAction()
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.test.assert
import androidx.compose.ui.test.assertHasClickAction
import androidx.compose.ui.test.assertHasNoClickAction
import androidx.compose.ui.test.assertIsNotEnabled
import androidx.compose.ui.test.assertTextEquals
import androidx.compose.ui.test.hasText
Expand Down Expand Up @@ -123,7 +123,7 @@ class InputPositiveIntegerTest {
}
rule.onNodeWithTag("INPUT_POSITIVE_INTEGER").assertExists()
rule.onNodeWithTag("INPUT_POSITIVE_INTEGER_LEGEND").assertExists()
rule.onNodeWithTag("INPUT_POSITIVE_INTEGER_LEGEND").assertHasClickAction()
rule.onNodeWithTag("INPUT_POSITIVE_INTEGER_LEGEND").assertHasNoClickAction()
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.test.assertHasClickAction
import androidx.compose.ui.test.assertHasNoClickAction
import androidx.compose.ui.test.assertIsNotSelected
import androidx.compose.ui.test.assertIsSelected
import androidx.compose.ui.test.junit4.createComposeRule
Expand Down Expand Up @@ -227,7 +227,7 @@ class InputRadioButtonTest {

rule.onNodeWithTag("RADIO_BUTTON_INPUT").assertExists()
rule.onNodeWithTag("RADIO_BUTTON_INPUT_LEGEND").assertExists()
rule.onNodeWithTag("RADIO_BUTTON_INPUT_LEGEND").assertHasClickAction()
rule.onNodeWithTag("RADIO_BUTTON_INPUT_LEGEND").assertHasNoClickAction()
}

@Test
Expand Down
Loading

0 comments on commit 67cce3e

Please sign in to comment.