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 5bdb444
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 88 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
171 changes: 87 additions & 84 deletions ktlint-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -281,31 +281,31 @@
<error line="373" column="30" source="trailing-comma-on-call-site" />
<error line="374" column="18" source="trailing-comma-on-call-site" />
<error line="383" column="46" source="trailing-comma-on-declaration-site" />
<error line="429" column="22" source="trailing-comma-on-call-site" />
<error line="437" column="47" source="trailing-comma-on-declaration-site" />
<error line="480" column="30" source="trailing-comma-on-call-site" />
<error line="481" column="18" source="trailing-comma-on-call-site" />
<error line="489" column="42" source="trailing-comma-on-declaration-site" />
<error line="510" column="30" source="trailing-comma-on-call-site" />
<error line="511" column="18" source="trailing-comma-on-call-site" />
<error line="520" column="43" source="trailing-comma-on-declaration-site" />
<error line="534" column="72" source="trailing-comma-on-call-site" />
<error line="542" column="43" source="trailing-comma-on-declaration-site" />
<error line="558" column="77" source="trailing-comma-on-call-site" />
<error line="566" column="40" source="trailing-comma-on-declaration-site" />
<error line="591" column="43" source="trailing-comma-on-declaration-site" />
<error line="612" column="41" source="trailing-comma-on-call-site" />
<error line="616" column="30" source="trailing-comma-on-call-site" />
<error line="617" column="18" source="trailing-comma-on-call-site" />
<error line="625" column="44" source="trailing-comma-on-declaration-site" />
<error line="655" column="30" source="trailing-comma-on-call-site" />
<error line="658" column="18" source="trailing-comma-on-call-site" />
<error line="666" column="51" source="trailing-comma-on-declaration-site" />
<error line="686" column="29" source="trailing-comma-on-call-site" />
<error line="687" column="18" source="trailing-comma-on-call-site" />
<error line="703" column="30" source="trailing-comma-on-declaration-site" />
<error line="731" column="30" source="trailing-comma-on-call-site" />
<error line="732" column="18" source="trailing-comma-on-call-site" />
<error line="434" column="22" source="trailing-comma-on-call-site" />
<error line="442" column="47" source="trailing-comma-on-declaration-site" />
<error line="485" column="30" source="trailing-comma-on-call-site" />
<error line="486" column="18" source="trailing-comma-on-call-site" />
<error line="494" column="42" source="trailing-comma-on-declaration-site" />
<error line="515" column="30" source="trailing-comma-on-call-site" />
<error line="516" column="18" source="trailing-comma-on-call-site" />
<error line="525" column="43" source="trailing-comma-on-declaration-site" />
<error line="539" column="72" source="trailing-comma-on-call-site" />
<error line="547" column="43" source="trailing-comma-on-declaration-site" />
<error line="563" column="77" source="trailing-comma-on-call-site" />
<error line="571" column="40" source="trailing-comma-on-declaration-site" />
<error line="596" column="43" source="trailing-comma-on-declaration-site" />
<error line="617" column="41" source="trailing-comma-on-call-site" />
<error line="621" column="30" source="trailing-comma-on-call-site" />
<error line="622" column="18" source="trailing-comma-on-call-site" />
<error line="630" column="44" source="trailing-comma-on-declaration-site" />
<error line="660" column="30" source="trailing-comma-on-call-site" />
<error line="663" column="18" source="trailing-comma-on-call-site" />
<error line="671" column="51" source="trailing-comma-on-declaration-site" />
<error line="691" column="29" source="trailing-comma-on-call-site" />
<error line="692" column="18" source="trailing-comma-on-call-site" />
<error line="708" column="30" source="trailing-comma-on-declaration-site" />
<error line="736" column="30" source="trailing-comma-on-call-site" />
<error line="737" column="18" source="trailing-comma-on-call-site" />
</file>
<file name="components/browser/engine-gecko/src/main/java/mozilla/components/browser/engine/gecko/prompt/PromptInstanceDismissDelegate.kt">
<error line="13" column="45" source="trailing-comma-on-declaration-site" />
Expand Down Expand Up @@ -897,65 +897,68 @@
<error line="476" column="10" source="trailing-comma-on-call-site" />
<error line="483" column="31" source="trailing-comma-on-call-site" />
<error line="511" column="10" source="trailing-comma-on-call-site" />
<error line="537" column="10" source="trailing-comma-on-call-site" />
<error line="543" column="42" source="trailing-comma-on-call-site" />
<error line="569" column="35" source="trailing-comma-on-call-site" />
<error line="570" column="14" source="trailing-comma-on-call-site" />
<error line="612" column="10" source="trailing-comma-on-call-site" />
<error line="660" column="84" source="trailing-comma-on-call-site" />
<error line="666" column="42" source="trailing-comma-on-call-site" />
<error line="684" column="10" source="trailing-comma-on-call-site" />
<error line="731" column="10" source="trailing-comma-on-call-site" />
<error line="756" column="10" source="trailing-comma-on-call-site" />
<error line="767" column="92" source="trailing-comma-on-call-site" />
<error line="781" column="24" source="trailing-comma-on-call-site" />
<error line="809" column="48" source="trailing-comma-on-declaration-site" />
<error line="818" column="38" source="trailing-comma-on-call-site" />
<error line="828" column="48" source="trailing-comma-on-declaration-site" />
<error line="836" column="38" source="trailing-comma-on-call-site" />
<error line="853" column="10" source="trailing-comma-on-call-site" />
<error line="861" column="30" source="trailing-comma-on-call-site" />
<error line="868" column="69" source="trailing-comma-on-call-site" />
<error line="908" column="10" source="trailing-comma-on-call-site" />
<error line="916" column="30" source="trailing-comma-on-call-site" />
<error line="942" column="10" source="trailing-comma-on-call-site" />
<error line="950" column="30" source="trailing-comma-on-call-site" />
<error line="961" column="30" source="trailing-comma-on-call-site" />
<error line="968" column="99" source="trailing-comma-on-call-site" />
<error line="1009" column="10" source="trailing-comma-on-call-site" />
<error line="1074" column="10" source="trailing-comma-on-call-site" />
<error line="1122" column="10" source="trailing-comma-on-call-site" />
<error line="1167" column="10" source="trailing-comma-on-call-site" />
<error line="1204" column="10" source="trailing-comma-on-call-site" />
<error line="1242" column="10" source="trailing-comma-on-call-site" />
<error line="1266" column="10" source="trailing-comma-on-call-site" />
<error line="1333" column="10" source="trailing-comma-on-call-site" />
<error line="1342" column="1" source="no-empty-first-line-in-method-block" />
<error line="1407" column="10" source="trailing-comma-on-call-site" />
<error line="1453" column="10" source="trailing-comma-on-call-site" />
<error line="1496" column="10" source="trailing-comma-on-call-site" />
<error line="1546" column="10" source="trailing-comma-on-call-site" />
<error line="1561" column="24" source="trailing-comma-on-call-site" />
<error line="1571" column="24" source="trailing-comma-on-call-site" />
<error line="1589" column="24" source="trailing-comma-on-call-site" />
<error line="1608" column="24" source="trailing-comma-on-call-site" />
<error line="1624" column="40" source="trailing-comma-on-declaration-site" />
<error line="1636" column="36" source="trailing-comma-on-declaration-site" />
<error line="1649" column="30" source="trailing-comma-on-declaration-site" />
<error line="1664" column="52" source="trailing-comma-on-declaration-site" />
<error line="1677" column="72" source="trailing-comma-on-declaration-site" />
<error line="1688" column="46" source="trailing-comma-on-declaration-site" />
<error line="1699" column="46" source="trailing-comma-on-declaration-site" />
<error line="1709" column="40" source="trailing-comma-on-declaration-site" />
<error line="1723" column="45" source="trailing-comma-on-declaration-site" />
<error line="1734" column="36" source="trailing-comma-on-declaration-site" />
<error line="1743" column="58" source="trailing-comma-on-declaration-site" />
<error line="1752" column="51" source="trailing-comma-on-declaration-site" />
<error line="1756" column="39" source="trailing-comma-on-call-site" />
<error line="1772" column="64" source="trailing-comma-on-declaration-site" />
<error line="1782" column="36" source="trailing-comma-on-declaration-site" />
<error line="1793" column="61" source="trailing-comma-on-declaration-site" />
<error line="1797" column="39" source="trailing-comma-on-call-site" />
<error line="530" column="26" source="no-multi-spaces" />
<error line="538" column="22" source="no-multi-spaces" />
<error line="546" column="22" source="no-multi-spaces" />
<error line="564" column="10" source="trailing-comma-on-call-site" />
<error line="590" column="10" source="trailing-comma-on-call-site" />
<error line="596" column="42" source="trailing-comma-on-call-site" />
<error line="622" column="35" source="trailing-comma-on-call-site" />
<error line="623" column="14" source="trailing-comma-on-call-site" />
<error line="665" column="10" source="trailing-comma-on-call-site" />
<error line="713" column="84" source="trailing-comma-on-call-site" />
<error line="719" column="42" source="trailing-comma-on-call-site" />
<error line="737" column="10" source="trailing-comma-on-call-site" />
<error line="784" column="10" source="trailing-comma-on-call-site" />
<error line="809" column="10" source="trailing-comma-on-call-site" />
<error line="820" column="92" source="trailing-comma-on-call-site" />
<error line="834" column="24" source="trailing-comma-on-call-site" />
<error line="862" column="48" source="trailing-comma-on-declaration-site" />
<error line="871" column="38" source="trailing-comma-on-call-site" />
<error line="881" column="48" source="trailing-comma-on-declaration-site" />
<error line="889" column="38" source="trailing-comma-on-call-site" />
<error line="906" column="10" source="trailing-comma-on-call-site" />
<error line="914" column="30" source="trailing-comma-on-call-site" />
<error line="921" column="69" source="trailing-comma-on-call-site" />
<error line="961" column="10" source="trailing-comma-on-call-site" />
<error line="969" column="30" source="trailing-comma-on-call-site" />
<error line="995" column="10" source="trailing-comma-on-call-site" />
<error line="1003" column="30" source="trailing-comma-on-call-site" />
<error line="1014" column="30" source="trailing-comma-on-call-site" />
<error line="1021" column="99" source="trailing-comma-on-call-site" />
<error line="1062" column="10" source="trailing-comma-on-call-site" />
<error line="1127" column="10" source="trailing-comma-on-call-site" />
<error line="1175" column="10" source="trailing-comma-on-call-site" />
<error line="1220" column="10" source="trailing-comma-on-call-site" />
<error line="1257" column="10" source="trailing-comma-on-call-site" />
<error line="1295" column="10" source="trailing-comma-on-call-site" />
<error line="1319" column="10" source="trailing-comma-on-call-site" />
<error line="1386" column="10" source="trailing-comma-on-call-site" />
<error line="1395" column="1" source="no-empty-first-line-in-method-block" />
<error line="1460" column="10" source="trailing-comma-on-call-site" />
<error line="1506" column="10" source="trailing-comma-on-call-site" />
<error line="1549" column="10" source="trailing-comma-on-call-site" />
<error line="1599" column="10" source="trailing-comma-on-call-site" />
<error line="1614" column="24" source="trailing-comma-on-call-site" />
<error line="1624" column="24" source="trailing-comma-on-call-site" />
<error line="1642" column="24" source="trailing-comma-on-call-site" />
<error line="1661" column="24" source="trailing-comma-on-call-site" />
<error line="1677" column="40" source="trailing-comma-on-declaration-site" />
<error line="1689" column="36" source="trailing-comma-on-declaration-site" />
<error line="1719" column="52" source="trailing-comma-on-declaration-site" />
<error line="1732" column="72" source="trailing-comma-on-declaration-site" />
<error line="1743" column="46" source="trailing-comma-on-declaration-site" />
<error line="1754" column="46" source="trailing-comma-on-declaration-site" />
<error line="1764" column="40" source="trailing-comma-on-declaration-site" />
<error line="1778" column="45" source="trailing-comma-on-declaration-site" />
<error line="1789" column="36" source="trailing-comma-on-declaration-site" />
<error line="1798" column="58" source="trailing-comma-on-declaration-site" />
<error line="1807" column="51" source="trailing-comma-on-declaration-site" />
<error line="1811" column="39" source="trailing-comma-on-call-site" />
<error line="1827" column="64" source="trailing-comma-on-declaration-site" />
<error line="1837" column="36" source="trailing-comma-on-declaration-site" />
<error line="1848" column="61" source="trailing-comma-on-declaration-site" />
<error line="1852" column="39" source="trailing-comma-on-call-site" />
</file>
<file name="components/browser/engine-gecko/src/test/java/mozilla/components/browser/engine/gecko/prompt/PromptInstanceDismissDelegateTest.kt">
<error line="29" column="10" source="trailing-comma-on-call-site" />
Expand Down

0 comments on commit 5bdb444

Please sign in to comment.