Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
For #12151 - Add support for empty step value in TimePicker
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandru2909 authored and mergify[bot] committed Sep 22, 2022
1 parent 77d9710 commit 9da5dd7
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -397,15 +397,20 @@ internal class GeckoPromptDelegate(private val geckoEngineSession: GeckoEngineSe
onConfirm("")
}
val initialDateString = prompt.defaultValue ?: ""
val stepValue = if (prompt.stepValue.isNullOrBlank()) {
null
} else {
prompt.stepValue
}

val format = when (prompt.type) {
DATE -> "yyyy-MM-dd"
MONTH -> "yyyy-MM"
WEEK -> "yyyy-'W'ww"
TIME -> {
if (shouldShowMillisecondsPicker(prompt.stepValue?.toFloat())) {
if (shouldShowMillisecondsPicker(stepValue?.toFloat())) {
"HH:mm:ss.SSS"
} else if (shouldShowSecondsPicker(prompt.stepValue?.toFloat())) {
} else if (shouldShowSecondsPicker(stepValue?.toFloat())) {
"HH:mm:ss"
} else {
"HH:mm"
Expand All @@ -422,7 +427,7 @@ internal class GeckoPromptDelegate(private val geckoEngineSession: GeckoEngineSe
initialDateString,
prompt.minValue,
prompt.maxValue,
prompt.stepValue,
stepValue,
onClear,
format,
onConfirm,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,59 @@ class GeckoPromptDelegateTest {
assertEquals((timeSelectionRequest as PromptRequest.TimeSelection).title, "title")
}

@Test
fun `onDateTimePrompt DATETIME_TYPE_TIME with stepValue time parameter must format time correctly`() {
val mockSession = GeckoEngineSession(runtime)
var timeSelectionRequest: PromptRequest.TimeSelection? = null
val confirmCaptor = argumentCaptor<String>()

val promptDelegate = GeckoPromptDelegate(mockSession)
mockSession.register(object : EngineSession.Observer {
override fun onPromptRequest(promptRequest: PromptRequest) {
timeSelectionRequest = promptRequest as PromptRequest.TimeSelection
}
})
val minutesGeckoPrompt = geckoDateTimePrompt(
type = TIME,
defaultValue = "17:00",
stepValue = "",
)
val secondsGeckoPrompt = geckoDateTimePrompt(
type = TIME,
defaultValue = "17:00:00",
stepValue = "1",
)
val millisecondsGeckoPrompt = geckoDateTimePrompt(
type = TIME,
defaultValue = "17:00:00.000",
stepValue = "0.1",
)

promptDelegate.onDateTimePrompt(mock(), minutesGeckoPrompt)

var selectedTime = "17:00"
assertNotNull(timeSelectionRequest)
(timeSelectionRequest as PromptRequest.TimeSelection).onConfirm(selectedTime.toDate("HH:mm"))
verify(minutesGeckoPrompt).confirm(confirmCaptor.capture())
assertEquals(selectedTime, confirmCaptor.value)

promptDelegate.onDateTimePrompt(mock(), secondsGeckoPrompt)

selectedTime = "17:00:25"
assertNotNull(timeSelectionRequest)
(timeSelectionRequest as PromptRequest.TimeSelection).onConfirm(selectedTime.toDate("HH:mm:ss"))
verify(secondsGeckoPrompt).confirm(confirmCaptor.capture())
assertEquals(selectedTime, confirmCaptor.value)

promptDelegate.onDateTimePrompt(mock(), millisecondsGeckoPrompt)

selectedTime = "17:00:20.100"
assertNotNull(timeSelectionRequest)
(timeSelectionRequest as PromptRequest.TimeSelection).onConfirm(selectedTime.toDate("HH:mm:ss.SSS"))
verify(millisecondsGeckoPrompt).confirm(confirmCaptor.capture())
assertEquals(selectedTime, confirmCaptor.value)
}

@Test
fun `onDateTimePrompt called with DATETIME_TYPE_DATETIME_LOCAL must provide a TimeSelection PromptRequest`() {
val mockSession = GeckoEngineSession(runtime)
Expand Down Expand Up @@ -1646,14 +1699,16 @@ class GeckoPromptDelegateTest {
type: Int,
defaultValue: String = "",
minValue: String = "",
maxValue: String = ""
maxValue: String = "",
stepValue: String = "",
): GeckoSession.PromptDelegate.DateTimePrompt {
val prompt: GeckoSession.PromptDelegate.DateTimePrompt = mock()
ReflectionUtils.setField(prompt, "title", title)
ReflectionUtils.setField(prompt, "type", type)
ReflectionUtils.setField(prompt, "defaultValue", defaultValue)
ReflectionUtils.setField(prompt, "minValue", minValue)
ReflectionUtils.setField(prompt, "maxValue", maxValue)
ReflectionUtils.setField(prompt, "stepValue", stepValue)
return prompt
}

Expand Down
3 changes: 3 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ permalink: /changelog/
* **nimbus-gradle-plugin**:
* Updated the plugin to use the version of application services defined in the buildSrc Dependencies.

* **browser-engine-gecko**:qwe
* 🚒 Bug fixed [fenix issue #16943](https://github.com/mozilla-mobile/fenix/issues/26943) - Prevent crashes when accessing a time picker with blank step value.

# 106.0.0
* [Commits](https://github.com/mozilla-mobile/android-components/compare/v105.0.0..v106.0.0)
* [Milestone](https://github.com/mozilla-mobile/android-components/milestone/153?closed=1)
Expand Down

0 comments on commit 9da5dd7

Please sign in to comment.