Skip to content

Commit

Permalink
Show dateformat text in lowercase for date and dateTime label. (#1976)
Browse files Browse the repository at this point in the history
* Show dateformat text in lowercase for date and dateTime label.

* Fix android test failure.

* Update datacapture/src/main/java/com/google/android/fhir/datacapture/views/factories/DatePickerViewHolderFactory.kt

* Update datacapture/src/main/java/com/google/android/fhir/datacapture/views/factories/DatePickerViewHolderFactory.kt

* Update datacapture/src/main/java/com/google/android/fhir/datacapture/views/factories/DateTimePickerViewHolderFactory.kt

---------

Co-authored-by: Santosh Pingle <[email protected]>
Co-authored-by: Jing Tang <[email protected]>
  • Loading branch information
3 people committed Apr 19, 2023
1 parent 8308d19 commit 67ca247
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class QuestionnaireUiEspressoTest {

onView(withId(R.id.date_input_layout)).check { view, _ ->
val actualError = (view as TextInputLayout).error
assertThat(actualError).isEqualTo("Date format needs to be MM/dd/yyyy (e.g. 01/31/2023)")
assertThat(actualError).isEqualTo("Date format needs to be mm/dd/yyyy (e.g. 01/31/2023)")
}
onView(withId(R.id.time_input_layout)).check { view, _ -> assertThat(view.isEnabled).isFalse() }
}
Expand Down Expand Up @@ -222,7 +222,7 @@ class QuestionnaireUiEspressoTest {

onView(withId(R.id.text_input_layout)).check { view, _ ->
val actualError = (view as TextInputLayout).error
assertThat(actualError).isEqualTo("Date format needs to be MM/dd/yyyy (e.g. 01/31/2023)")
assertThat(actualError).isEqualTo("Date format needs to be mm/dd/yyyy (e.g. 01/31/2023)")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ internal object DatePickerViewHolderFactory :
override fun bind(questionnaireViewItem: QuestionnaireViewItem) {
clearPreviousState()
header.bind(questionnaireViewItem)
textInputLayout.hint = canonicalizedDatePattern
// Use 'mm' for month instead of 'MM' to avoid confusion.
// See https://developer.android.com/reference/kotlin/java/text/SimpleDateFormat.
textInputLayout.hint = canonicalizedDatePattern.lowercase()
textInputEditText.removeTextChangedListener(textWatcher)

val questionnaireItemViewItemDateAnswer =
Expand Down Expand Up @@ -325,6 +327,8 @@ internal fun Int.length() =
internal fun invalidDateErrorText(context: Context, formatPattern: String) =
context.getString(
R.string.date_format_validation_error_msg,
formatPattern,
// Use 'mm' for month instead of 'MM' to avoid confusion.
// See https://developer.android.com/reference/kotlin/java/text/SimpleDateFormat.
formatPattern.lowercase(),
formatPattern.replace("dd", "31").replace("MM", "01").replace("yyyy", "2023")
)
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ internal object DateTimePickerViewHolderFactory :
override fun bind(questionnaireViewItem: QuestionnaireViewItem) {
clearPreviousState()
header.bind(questionnaireViewItem)
dateInputLayout.hint = canonicalizedDatePattern
// Use 'mm' for month instead of 'MM' to avoid confusion.
// See https://developer.android.com/reference/kotlin/java/text/SimpleDateFormat.
dateInputLayout.hint = canonicalizedDatePattern.lowercase()
dateInputEditText.removeTextChangedListener(textWatcher)

val questionnaireItemViewItemDateTimeAnswer =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,20 @@ class DatePickerViewHolderFactoryTest {
assertThat(viewHolder.dateInputView.text.toString()).isEqualTo("11/19/2020")
}

@Test
fun `show dateFormat label in lowerCase`() {
setLocale(Locale.US)
viewHolder.bind(
QuestionnaireViewItem(
Questionnaire.QuestionnaireItemComponent(),
QuestionnaireResponse.QuestionnaireResponseItemComponent(),
validationResult = NotValidated,
answersChangedCallback = { _, _, _, _ -> },
)
)
assertThat(viewHolder.dateInputView.hint.toString()).isEqualTo("mm/dd/yyyy")
}

@Test
fun shouldSetDateInput_localeJp() {
setLocale(Locale.JAPAN)
Expand Down Expand Up @@ -371,6 +385,23 @@ class DatePickerViewHolderFactoryTest {
.isEqualTo("Maximum value allowed is:2025-01-01")
}

@Test
fun `show dateFormat in lowerCase in the error message`() {
val itemViewItem =
QuestionnaireViewItem(
Questionnaire.QuestionnaireItemComponent(),
QuestionnaireResponse.QuestionnaireResponseItemComponent(),
validationResult = NotValidated,
answersChangedCallback = { _, _, _, _ -> },
draftAnswer = "11/19/202"
)

viewHolder.bind(itemViewItem)

assertThat(viewHolder.itemView.findViewById<TextInputLayout>(R.id.text_input_layout).error)
.isEqualTo("Date format needs to be mm/dd/yyyy (e.g. 01/31/2023)")
}

@Test
fun displayValidationResult_noError_shouldShowNoErrorMessage() {
viewHolder.bind(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,19 @@ class DateTimePickerViewHolderFactoryTest {
assertThat(viewHolder.timeInputView.text.toString()).isEqualTo("")
}

@Test
fun `show dateFormat label in lowerCase`() {
viewHolder.bind(
QuestionnaireViewItem(
Questionnaire.QuestionnaireItemComponent(),
QuestionnaireResponse.QuestionnaireResponseItemComponent(),
validationResult = NotValidated,
answersChangedCallback = { _, _, _, _ -> },
)
)
assertThat(viewHolder.dateInputView.hint.toString()).isEqualTo("mm/dd/yyyy")
}

@Test
fun shouldSetDateTimeInput() {
viewHolder.bind(
Expand Down Expand Up @@ -414,7 +427,24 @@ class DateTimePickerViewHolderFactoryTest {
viewHolder.bind(itemViewItem)

assertThat(viewHolder.itemView.findViewById<TextInputLayout>(R.id.date_input_layout).error)
.isEqualTo("Date format needs to be MM/dd/yyyy (e.g. 01/31/2023)")
.isEqualTo("Date format needs to be mm/dd/yyyy (e.g. 01/31/2023)")
}

@Test
fun `show dateFormat in lowerCase in the error message`() {
val itemViewItem =
QuestionnaireViewItem(
Questionnaire.QuestionnaireItemComponent(),
QuestionnaireResponse.QuestionnaireResponseItemComponent(),
validationResult = NotValidated,
answersChangedCallback = { _, _, _, _ -> },
draftAnswer = "11/19/202"
)

viewHolder.bind(itemViewItem)

assertThat(viewHolder.itemView.findViewById<TextInputLayout>(R.id.date_input_layout).error)
.isEqualTo("Date format needs to be mm/dd/yyyy (e.g. 01/31/2023)")
}

@Test
Expand Down

0 comments on commit 67ca247

Please sign in to comment.