diff --git a/designsystem/src/androidUnitTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/InputAgeSnapshotTest.kt b/designsystem/src/androidUnitTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/InputAgeSnapshotTest.kt index fe3b002a6..98cff1266 100644 --- a/designsystem/src/androidUnitTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/InputAgeSnapshotTest.kt +++ b/designsystem/src/androidUnitTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/InputAgeSnapshotTest.kt @@ -44,7 +44,7 @@ class InputAgeSnapshotTest { }, ) - SubTitle("Input Age Component - Date Of Birth") + SubTitle("Input Age Component - Invalid Date Of Birth") InputAge( state = rememberInputAgeState( inputAgeData = InputAgeData( @@ -59,6 +59,22 @@ class InputAgeSnapshotTest { }, ) + SubTitle("Input Age Component - Date Of Birth") + InputAge( + state = rememberInputAgeState( + inputAgeData = InputAgeData( + title = "Label", + ), + inputType = AgeInputType.DateOfBirth( + TextFieldValue("1991-11-27"), + ), + inputState = InputShellState.DISABLED, + ), + onValueChanged = { + }, + ) + + SubTitle("Input Age Component - Date Of Birth Required Error") InputAge( state = rememberInputAgeState( diff --git a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputAge.kt b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputAge.kt index ff01da68e..b8133c932 100644 --- a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputAge.kt +++ b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputAge.kt @@ -60,7 +60,7 @@ import java.util.Calendar * @param modifier: optional modifier. */ @Suppress("DEPRECATION") -@Deprecated("This component is deprecated and will be removed in the next release. Use InputDateTime instead.") +@Deprecated("This component is deprecated and will be removed in the next release. Use InputAge instead.") @OptIn(ExperimentalMaterial3Api::class) @Composable fun InputAge( diff --git a/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputAgeTest.kt b/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputAgeTest.kt index 20a789566..fcbcb815f 100644 --- a/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputAgeTest.kt +++ b/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputAgeTest.kt @@ -3,11 +3,13 @@ package org.hisp.dhis.mobile.ui.designsystem.component import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue +import androidx.compose.ui.test.assertTextEquals 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 androidx.compose.ui.text.input.TextFieldValue import org.hisp.dhis.mobile.ui.designsystem.component.state.InputAgeData import org.hisp.dhis.mobile.ui.designsystem.component.state.rememberInputAgeState import org.junit.Rule @@ -223,4 +225,62 @@ class InputAgeTest { assert(newInputDaysType.value.text == "28") assert(newInputDaysType.unit == TimeUnitValues.DAYS) } + + @Test + fun shouldFormatDateCorrectly() { + rule.setContent { + InputAge( + state = rememberInputAgeState( + inputAgeData = InputAgeData( + title = "Label", + ), + inputType = AgeInputType.DateOfBirth(TextFieldValue("1991-11-27")), + ), + onValueChanged = { + // no-op + }, + ) + } + + rule.onNodeWithTag("INPUT_AGE_TEXT_FIELD").assertExists().assertTextEquals("27/11/1991") + } + + @Test + fun shouldShowErrorForOutsideRangeDate() { + rule.setContent { + InputAge( + state = rememberInputAgeState( + inputAgeData = InputAgeData( + title = "Label", + ), + inputType = AgeInputType.DateOfBirth(TextFieldValue("2025-11-27")), + ), + onValueChanged = { + // no-op + }, + ) + } + + rule.onNodeWithTag("INPUT_AGE_TEXT_FIELD").assertExists().assertTextEquals("27/11/2025") + rule.onNodeWithTag("INPUT_AGE_SUPPORTING_TEXT").assertExists() + } + + @Test + fun shouldWorkWithInvalidDate() { + rule.setContent { + InputAge( + state = rememberInputAgeState( + inputAgeData = InputAgeData( + title = "Label", + ), + inputType = AgeInputType.DateOfBirth(TextFieldValue("1004-9999-9999")), + ), + onValueChanged = { + // no-op + }, + ) + } + + rule.onNodeWithTag("INPUT_AGE_TEXT_FIELD").assertExists().assertTextEquals("99/99/9999") + } } diff --git a/designsystem/src/test/snapshots/images/org.hisp.dhis.mobile.ui.designsystem_InputAgeSnapshotTest_launchInputAgeSnapshot.png b/designsystem/src/test/snapshots/images/org.hisp.dhis.mobile.ui.designsystem_InputAgeSnapshotTest_launchInputAgeSnapshot.png index e093a22a5..4b2f2f983 100644 Binary files a/designsystem/src/test/snapshots/images/org.hisp.dhis.mobile.ui.designsystem_InputAgeSnapshotTest_launchInputAgeSnapshot.png and b/designsystem/src/test/snapshots/images/org.hisp.dhis.mobile.ui.designsystem_InputAgeSnapshotTest_launchInputAgeSnapshot.png differ