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 committed Sep 19, 2022
1 parent 4f34790 commit 7e896a6
Show file tree
Hide file tree
Showing 2 changed files with 64 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

1 comment on commit 7e896a6

@firefoxci-taskcluster
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh oh! Looks like an error! Details

Failed to fetch task artifact public/github/customCheckRunText.md for GitHub integration.
Make sure the artifact exists on the worker or other location.

Please sign in to comment.