Skip to content

Commit

Permalink
feat: [ANDROAPP-5794] fix test and add year range control
Browse files Browse the repository at this point in the history
  • Loading branch information
xavimolloy committed Feb 23, 2024
1 parent 3e07f61 commit 9644e96
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.dhis2.usescases.eventsWithoutRegistration.eventDetails
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithTag
Expand Down Expand Up @@ -224,7 +225,7 @@ class EventInitialTest {
EventInputDateUiModel(
eventDate = date,
detailsEnabled = details.enabled,
onDateClick = viewModel.showPeriodDialog() ,
onDateClick = {} ,
onDateSelected = { dateValues ->
viewModel.onDateSet(dateValues.year, dateValues.month, dateValues.day)
},
Expand Down Expand Up @@ -257,7 +258,7 @@ class EventInitialTest {
EventInputDateUiModel(
eventDate = date,
detailsEnabled = details.enabled,
onDateClick = viewModel.showPeriodDialog(),
onDateClick = {},
onDateSelected = { dateValues ->
viewModel.onDateSet(dateValues.year, dateValues.month, dateValues.day)
},
Expand Down Expand Up @@ -287,7 +288,7 @@ class EventInitialTest {
val catCombo by viewModel.eventCatCombo.collectAsState()

ProvideCategorySelector(
modifier = Modifier,
modifier = Modifier.testTag(EMPTY_CATEGORY_SELECTOR),
eventCatComboUiModel = EventCatComboUiModel(
EventCategory("UID", "NO OPTIONS ", 0, emptyList()),
eventCatCombo = catCombo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ fun ProvideInputDate(
var state by remember {
mutableStateOf(getInputState(uiModel.detailsEnabled))
}

val yearRange = if (uiModel.selectableDates != null) {
IntRange(uiModel.selectableDates.initialDate.substring(4, 8).toInt(), uiModel.selectableDates.endDate.substring(4, 8).toInt())
} else {
IntRange(1924, 2124)
}
InputDateTime(
InputDateTimeModel(
title = uiModel.eventDate.label ?: "",
Expand All @@ -91,6 +95,7 @@ fun ProvideInputDate(
},
is24hourFormat = uiModel.is24HourFormat,
selectableDates = uiModel.selectableDates ?: SelectableDates("01011924", "12312124"),
yearRange = yearRange,
),
modifier = modifier.testTag(INPUT_EVENT_INITIAL_DATE),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import org.hisp.dhis.mobile.ui.designsystem.component.internal.DateTimeTransform
import org.hisp.dhis.mobile.ui.designsystem.component.internal.DateTransformation
import org.hisp.dhis.mobile.ui.designsystem.component.internal.TimeTransformation
import java.text.SimpleDateFormat
import java.util.Calendar
import java.util.Date
import java.util.Locale

Expand Down Expand Up @@ -52,6 +53,7 @@ fun ProvideInputDate(
},
)
}
val yearIntRange = if (fieldUiModel.allowFutureDates == true) IntRange(1924, 2124) else (IntRange(1924, Calendar.getInstance().get(Calendar.YEAR)))
val selectableDates = if (fieldUiModel.allowFutureDates == true) {
SelectableDates(initialDate = "12111924", endDate = "12112124")
} else {
Expand All @@ -62,6 +64,7 @@ fun ProvideInputDate(
),
)
}

InputDateTime(
InputDateTimeModel(
title = fieldUiModel.label,
Expand All @@ -85,6 +88,7 @@ fun ProvideInputDate(
)
},
selectableDates = selectableDates,
yearRange = yearIntRange,
inputStyle = inputStyle,
),
modifier = modifier.semantics { contentDescription = formatStoredDateToUI(value.text, fieldUiModel.valueType) },
Expand Down

0 comments on commit 9644e96

Please sign in to comment.