Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Androapp 6218 mobile input age no such element exception on spanish translation #259

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,33 @@ import org.hisp.dhis.mobile.ui.designsystem.theme.SurfaceColor
*
* @param orientation: Controls how the radio buttons will be displayed, HORIZONTAL for rows or
* VERTICAL for columns.
* @param optionSelected: controls which item is selected.
* @param optionSelected: controls which [TimeUnitValues] is selected.
* @param enabled: manages the enabled state
* @param onClick: is a callback to notify which item has changed into the block.
* @param onClick: is a callback to notify when [TimeUnitValues] is changed.
* @param modifier: optional modifier.
*/
@Composable
internal fun TimeUnitSelector(
orientation: Orientation,
optionSelected: String,
optionSelected: TimeUnitValues,
modifier: Modifier = Modifier,
enabled: Boolean = true,
onClick: (RadioButtonData) -> Unit,
onClick: (TimeUnitValues) -> Unit,
) {
val backgroundColor = if (enabled) {
SurfaceColor.Surface
} else {
SurfaceColor.DisabledSurface
}

val options = TimeUnitValues.entries.map {
RadioButtonData(it.name, optionSelected == it, enabled, provideStringResource(it.value))
}

var selectedOption by remember {
mutableStateOf(options.find { it.selected } ?: options[0])
}

RowComponentContainer(
modifier = modifier
.background(color = backgroundColor, Shape.SmallBottom)
Expand All @@ -45,18 +53,10 @@ internal fun TimeUnitSelector(
end = Spacing.Spacing8,
),
) {
val options = TimeUnitValues.values().map {
RadioButtonData(it.value, optionSelected == it.value, enabled, provideStringResource(it.value))
}
val selectedItem = options.find {
it.selected
}
var currentItem by remember {
mutableStateOf(selectedItem ?: options[0])
}
RadioButtonBlock(orientation, options, currentItem) {
currentItem = it
onClick.invoke(it)
RadioButtonBlock(orientation, options, selectedOption) {
selectedOption = it
val selectedTimeUnit = TimeUnitValues.entries.first { it.name == selectedOption.uid }
onClick.invoke(selectedTimeUnit)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ fun InputAge(
.testTag("INPUT_AGE_TEXT_FIELD")
.fillMaxWidth(),
inputTextValue = getTextFieldValue(uiModel.inputType),
helper = helperText,
helper = if (helperText != null) provideStringResource(helperText).lowercase() else null,
isSingleLine = true,
helperStyle = helperStyle,
onInputChanged = { newText ->
Expand Down Expand Up @@ -218,12 +218,9 @@ fun InputAge(
modifier = Modifier.fillMaxWidth()
.testTag("INPUT_AGE_TIME_UNIT_SELECTOR"),
orientation = Orientation.HORIZONTAL,
optionSelected = YEARS.value,
optionSelected = YEARS,
enabled = uiModel.state != InputShellState.DISABLED,
onClick = { itemData ->
val timeUnit = TimeUnitValues.entries
.first { it.value.contains(itemData.textInput!!, ignoreCase = true) }

onClick = { timeUnit ->
uiModel.onValueChanged.invoke(uiModel.inputType.copy(unit = timeUnit))
},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.performTextClearance
import androidx.compose.ui.test.performTextInput
import org.junit.Rule
import org.junit.Test
Expand All @@ -27,7 +28,6 @@ class InputAgeTest {
// no-op
},
),

)
}

Expand All @@ -49,7 +49,6 @@ class InputAgeTest {
// no-op
},
),

)
}

Expand All @@ -72,7 +71,6 @@ class InputAgeTest {
inputType = it
},
),

)
}

Expand All @@ -93,7 +91,6 @@ class InputAgeTest {
// no-op
},
),

)
}

Expand All @@ -116,7 +113,6 @@ class InputAgeTest {
inputType = it
},
),

)
}

Expand All @@ -138,7 +134,6 @@ class InputAgeTest {
inputType = it
},
),

)
}

Expand Down Expand Up @@ -176,4 +171,39 @@ class InputAgeTest {

rule.onNodeWithTag("INPUT_AGE_SUPPORTING_TEXT").assertExists()
}

@Test
fun changingAgeTimeUnitShouldWorkProperly() {
var inputType by mutableStateOf<AgeInputType>(AgeInputType.Age.EMPTY)

rule.setContent {
InputAge(
InputAgeModel(
title = "Label",
inputType = inputType,
onValueChanged = {
inputType = it
},
),
)
}

rule.onNodeWithTag("INPUT_AGE_TIME_UNIT_SELECTOR").assertExists()
rule.onNodeWithTag("RADIO_BUTTON_YEARS").assertExists()
rule.onNodeWithTag("RADIO_BUTTON_MONTHS").assertExists()
rule.onNodeWithTag("RADIO_BUTTON_DAYS").assertExists()

rule.onNodeWithTag("RADIO_BUTTON_MONTHS").performClick()
rule.onNodeWithTag("INPUT_AGE_TEXT_FIELD").performTextInput("11")
val newInputMonthType = inputType as AgeInputType.Age
assert(newInputMonthType.value.text == "11")
assert(newInputMonthType.unit == TimeUnitValues.MONTHS)

rule.onNodeWithTag("RADIO_BUTTON_DAYS").performClick()
rule.onNodeWithTag("INPUT_AGE_TEXT_FIELD").performTextClearance()
rule.onNodeWithTag("INPUT_AGE_TEXT_FIELD").performTextInput("28")
val newInputDaysType = inputType as AgeInputType.Age
assert(newInputDaysType.value.text == "28")
assert(newInputDaysType.unit == TimeUnitValues.DAYS)
}
}
Loading