@@ -385,4 +385,107 @@ class ClockViewTests {
385385 }
386386 rule.onPositiveButton().assertIsNotEnabled()
387387 }
388+
389+ @Test
390+ fun clockView_12HourFormat_midnightSelection_returnsMidnight () {
391+ var selectedTime: LocalTime ? = null
392+ rule.setContentAndWaitForIdle {
393+ ClockView (
394+ useCaseState = UseCaseState (visible = true ),
395+ selection = ClockSelection .HoursMinutes { hours, minutes ->
396+ selectedTime = LocalTime .of(hours, minutes)
397+ },
398+ config = ClockConfig (is24HourFormat = false )
399+ )
400+ }
401+
402+ listOf (1 , 2 , 0 , 0 ).forEach {
403+ runBlocking {
404+ rule.onNodeWithTags(TestTags .KEYBOARD_KEY , it).performClick()
405+ delay(Constants .DEBOUNCE_KEY_CLICK_DURATION )
406+ }
407+ }
408+ runBlocking {
409+ rule.onNodeWithTags(TestTags .CLOCK_12_HOUR_FORMAT , 0 ).performClick() // Select AM
410+ delay(Constants .DEBOUNCE_KEY_CLICK_DURATION )
411+ }
412+ rule.onPositiveButton().performClick()
413+
414+ assert (selectedTime == LocalTime .MIDNIGHT )
415+ }
416+
417+ @Test
418+ fun clockView_12HourFormat_noonSelection_returnsNoon () {
419+ var selectedTime: LocalTime ? = null
420+ rule.setContentAndWaitForIdle {
421+ ClockView (
422+ useCaseState = UseCaseState (visible = true ),
423+ selection = ClockSelection .HoursMinutes { hours, minutes ->
424+ selectedTime = LocalTime .of(hours, minutes)
425+ },
426+ config = ClockConfig (is24HourFormat = false )
427+ )
428+ }
429+
430+ listOf (1 , 2 , 0 , 0 ).forEach {
431+ runBlocking {
432+ rule.onNodeWithTags(TestTags .KEYBOARD_KEY , it).performClick()
433+ delay(Constants .DEBOUNCE_KEY_CLICK_DURATION )
434+ }
435+ }
436+ runBlocking {
437+ rule.onNodeWithTags(TestTags .CLOCK_12_HOUR_FORMAT , 1 ).performClick() // Select PM
438+ delay(Constants .DEBOUNCE_KEY_CLICK_DURATION )
439+ }
440+ rule.onPositiveButton().performClick()
441+ assert (selectedTime == LocalTime .NOON )
442+ }
443+
444+ @Test
445+ fun clockView_12HourFormat_amPmIndicatorMisalignment_returnsCorrectTime () {
446+ var selectedTime: LocalTime ? = null
447+ val testTime = LocalTime .of(10 , 30 )
448+
449+ rule.setContentAndWaitForIdle {
450+ ClockView (
451+ useCaseState = UseCaseState (visible = true ),
452+ selection = ClockSelection .HoursMinutes { hours, minutes ->
453+ selectedTime = LocalTime .of(hours, minutes)
454+ },
455+ config = ClockConfig (is24HourFormat = false )
456+ )
457+ }
458+ listOf (1 , 0 , 3 , 0 ).forEach {
459+ runBlocking {
460+ rule.onNodeWithTags(TestTags .KEYBOARD_KEY , it).performClick()
461+ delay(Constants .DEBOUNCE_KEY_CLICK_DURATION )
462+ }
463+ }
464+ // Change AM/PM without adjusting time again
465+ runBlocking {
466+ rule.onNodeWithTags(TestTags .CLOCK_12_HOUR_FORMAT , 1 ).performClick() // Change to PM
467+ delay(Constants .DEBOUNCE_KEY_CLICK_DURATION )
468+ }
469+ rule.onPositiveButton().performClick()
470+ assert (selectedTime == testTime.plusHours(12 ))
471+ }
472+
473+ @Test
474+ fun clockView_12HourFormat_defaultTimeSelection_returnsDefaultTime () {
475+ val defaultTime = LocalTime .of(10 , 30 , 0 )
476+ var selectedTime: LocalTime ? = null
477+ rule.setContentAndWaitForIdle {
478+ ClockView (
479+ useCaseState = UseCaseState (visible = true ),
480+ selection = ClockSelection .HoursMinutes { hours, minutes ->
481+ selectedTime = LocalTime .of(hours, minutes)
482+ },
483+ config = ClockConfig (is24HourFormat = false , defaultTime = defaultTime)
484+ )
485+ }
486+
487+ rule.onPositiveButton().performClick()
488+ assert (selectedTime == defaultTime)
489+ }
490+
388491}
0 commit comments