@@ -19,6 +19,7 @@ package com.maxkeppeler.sheets.calendar.functional
1919
2020import android.util.Range
2121import androidx.compose.material3.ExperimentalMaterial3Api
22+ import androidx.compose.ui.test.assertIsDisplayed
2223import androidx.compose.ui.test.assertIsNotEnabled
2324import androidx.compose.ui.test.junit4.createComposeRule
2425import androidx.compose.ui.test.performClick
@@ -45,7 +46,7 @@ class CalendarViewTests {
4546 val rule = createComposeRule()
4647
4748 @Test
48- fun calendarViewDateSelectionSuccess () {
49+ fun givenCalendarView_whenDateSelected_thenDateSelectionSuccess () {
4950 val testDate = LocalDate .now()
5051 .withDayOfMonth(12 )
5152
@@ -65,7 +66,7 @@ class CalendarViewTests {
6566 }
6667
6768 @Test
68- fun calendarViewDateSelectionInvalid () {
69+ fun givenCalendarView_whenNoDateSelected_thenDateSelectionInvalid () {
6970 rule.setContentAndWaitForIdle {
7071 CalendarView (
7172 useCaseState = UseCaseState (visible = true ),
@@ -76,7 +77,7 @@ class CalendarViewTests {
7677 }
7778
7879 @Test
79- fun calendarViewDatesSelectionSuccess () {
80+ fun givenCalendarView_whenMultipleDatesSelected_thenDatesSelectionSuccess () {
8081 val testDates = listOf (
8182 LocalDate .now().withDayOfMonth(2 ),
8283 LocalDate .now().withDayOfMonth(8 ),
@@ -104,7 +105,7 @@ class CalendarViewTests {
104105 }
105106
106107 @Test
107- fun calendarViewDatesSelectionInvalid () {
108+ fun givenCalendarView_whenNoDatesSelected_thenDatesSelectionInvalid () {
108109 rule.setContentAndWaitForIdle {
109110 CalendarView (
110111 useCaseState = UseCaseState (visible = true ),
@@ -115,7 +116,7 @@ class CalendarViewTests {
115116 }
116117
117118 @Test
118- fun calendarViewPeriodSelectionSuccess () {
119+ fun givenCalendarView_whenDateSelectedWithStyleMonthAndDisabledDates_thenDateSelectionStyleMonthConfigDatesDisabled () {
119120 val testStartDate = LocalDate .now().withDayOfMonth(2 )
120121 val testEndDate = LocalDate .now().withDayOfMonth(12 )
121122
@@ -147,7 +148,7 @@ class CalendarViewTests {
147148 }
148149
149150 @Test
150- fun calendarViewDateSelectionStyleMonthConfigDatesDisabled () {
151+ fun givenCalendarView_whenMultipleDatesSelectedWithStyleMonthAndDisabledDates_thenDatesSelectionStyleMonthConfigDatesDisabled () {
151152 val testDate = LocalDate .now().withDayOfMonth(15 )
152153 val newDates = listOf (
153154 testDate.plusDays(2 ),
@@ -183,7 +184,7 @@ class CalendarViewTests {
183184 }
184185
185186 @Test
186- fun calendarViewDatesSelectionStyleMonthConfigDatesDisabled () {
187+ fun givenCalendarView_whenPeriodSelectedWithStyleMonthAndDisabledDates_thenPeriodSelectionStyleMonthConfigDatesDisabled () {
187188 val testDate = LocalDate .now().withDayOfMonth(15 )
188189 val defaultDates = listOf (
189190 testDate.minusDays(10 ),
@@ -224,7 +225,7 @@ class CalendarViewTests {
224225
225226
226227 @Test
227- fun calendarViewPeriodSelectionStyleMonthConfigDatesDisabled () {
228+ fun givenCalendarView_whenPeriodSelectedWithStyleMonthAndDisabledDatesAlt_thenPeriodSelectionStyleMonthConfigDatesDisabled () {
228229 val testDate = LocalDate .now().withDayOfMonth(15 )
229230 val disabledDates = listOf (
230231 testDate.minusDays(1 ),
@@ -262,7 +263,7 @@ class CalendarViewTests {
262263 }
263264
264265 @Test
265- fun calendarViewPeriodSelectionInvalid () {
266+ fun givenCalendarView_whenNoPeriodSelected_thenPeriodSelectionInvalid () {
266267 rule.setContentAndWaitForIdle {
267268 CalendarView (
268269 useCaseState = UseCaseState (visible = true ),
@@ -273,7 +274,7 @@ class CalendarViewTests {
273274 }
274275
275276 @Test
276- fun calendarViewPeriodSelectionInvalidSelectEndDateBeforeStartDate () {
277+ fun givenCalendarView_whenEndDateSelectedBeforeStartDate_thenPeriodSelectionInvalidSelectEndDateBeforeStartDate () {
277278 val testStartDate = LocalDate .now().withDayOfMonth(12 )
278279 val testEndDate = LocalDate .now().withDayOfMonth(2 )
279280 rule.setContentAndWaitForIdle {
@@ -297,7 +298,7 @@ class CalendarViewTests {
297298 }
298299
299300 @Test
300- fun calendarViewDisplaysCalendarStyleWeek () {
301+ fun givenCalendarView_whenCalendarStyleWeek_thenCalendarViewDisplaysCalendarStyleWeek () {
301302 rule.setContentAndWaitForIdle {
302303 CalendarView (
303304 useCaseState = UseCaseState (visible = true ),
@@ -309,7 +310,7 @@ class CalendarViewTests {
309310 }
310311
311312 @Test
312- fun calendarViewDisplaysCalendarStyleMonth () {
313+ fun givenCalendarView_whenCalendarStyleMonth_thenCalendarViewDisplaysCalendarStyleMonth () {
313314 rule.setContentAndWaitForIdle {
314315 CalendarView (
315316 useCaseState = UseCaseState (visible = true ),
@@ -320,4 +321,123 @@ class CalendarViewTests {
320321 rule.onPositiveButton().assertIsNotEnabled()
321322 }
322323
324+
325+ @Test
326+ fun givenCalendarView_whenDateSelectedWithCameraDate_thenDisplayCorrectTime () {
327+ val testDate = LocalDate .now().withDayOfMonth(15 )
328+ val testCameraDate = LocalDate .now().minusMonths(2 )
329+ rule.setContentAndWaitForIdle {
330+ CalendarView (
331+ useCaseState = UseCaseState (visible = true ),
332+ selection = CalendarSelection .Date (
333+ selectedDate = testDate,
334+ onSelectDate = { date -> }
335+ ),
336+ config = CalendarConfig (
337+ style = CalendarStyle .MONTH ,
338+ cameraDate = testCameraDate
339+ )
340+ )
341+ }
342+
343+ rule.onNodeWithTags(
344+ TestTags .CALENDAR_DATE_SELECTION ,
345+ testCameraDate.format(DateTimeFormatter .ISO_DATE )
346+ ).apply {
347+ assertExists()
348+ assertIsDisplayed()
349+ }
350+ }
351+
352+ @Test
353+ fun givenCalendarView_whenDateSelectedWithCameraDateOutsideBoundary_thenDisplaySelectedTime () {
354+ val testDate = LocalDate .now().withDayOfMonth(15 )
355+ val testBoundary = testDate.minusYears(2 ).. testDate.plusYears(2 )
356+ val testCameraDate = LocalDate .now().minusYears(4 )
357+ rule.setContentAndWaitForIdle {
358+ CalendarView (
359+ useCaseState = UseCaseState (visible = true ),
360+ selection = CalendarSelection .Date (
361+ selectedDate = testDate,
362+ onSelectDate = { date -> }
363+ ),
364+ config = CalendarConfig (
365+ boundary = testBoundary,
366+ cameraDate = testCameraDate,
367+ style = CalendarStyle .MONTH
368+ )
369+ )
370+ }
371+
372+ rule.onNodeWithTags(
373+ TestTags .CALENDAR_DATE_SELECTION ,
374+ testCameraDate.format(DateTimeFormatter .ISO_DATE )
375+ ).assertDoesNotExist()
376+
377+ rule.onNodeWithTags(
378+ TestTags .CALENDAR_DATE_SELECTION ,
379+ testDate.format(DateTimeFormatter .ISO_DATE )
380+ ).apply {
381+ assertExists()
382+ assertIsDisplayed()
383+ }
384+ }
385+
386+
387+ @Test
388+ fun givenCalendarView_whenCameraDateOutsideBoundaryCurrentTimeInsideBoundary_thenDisplayCurrentTime () {
389+ val testDate = LocalDate .now()
390+ val testBoundary = testDate.minusYears(2 ).. testDate.plusYears(2 )
391+ val testCameraDate = LocalDate .now().minusYears(4 )
392+ rule.setContentAndWaitForIdle {
393+ CalendarView (
394+ useCaseState = UseCaseState (visible = true ),
395+ selection = CalendarSelection .Date (
396+ onSelectDate = { date -> }
397+ ),
398+ config = CalendarConfig (
399+ boundary = testBoundary,
400+ cameraDate = testCameraDate,
401+ style = CalendarStyle .MONTH
402+ )
403+ )
404+ }
405+
406+ rule.onNodeWithTags(
407+ TestTags .CALENDAR_DATE_SELECTION ,
408+ testDate.format(DateTimeFormatter .ISO_DATE )
409+ ).apply {
410+ assertExists()
411+ assertIsDisplayed()
412+ }
413+ }
414+
415+ @Test
416+ fun givenCalendarView_whenCameraDateOutsideBoundaryCurrentTimeOutsideBoundary_thenDisplayCurrentTime () {
417+ val testDate = LocalDate .now()
418+ val testBoundary = testDate.plusYears(2 ).. testDate.plusYears(4 )
419+ val testCameraDate = LocalDate .now().minusYears(4 )
420+ rule.setContentAndWaitForIdle {
421+ CalendarView (
422+ useCaseState = UseCaseState (visible = true ),
423+ selection = CalendarSelection .Date (
424+ onSelectDate = { date -> }
425+ ),
426+ config = CalendarConfig (
427+ boundary = testBoundary,
428+ cameraDate = testCameraDate,
429+ style = CalendarStyle .MONTH
430+ )
431+ )
432+ }
433+
434+ rule.onNodeWithTags(
435+ TestTags .CALENDAR_DATE_SELECTION ,
436+ testBoundary.start.format(DateTimeFormatter .ISO_DATE )
437+ ).apply {
438+ assertExists()
439+ assertIsDisplayed()
440+ }
441+ }
442+
323443}
0 commit comments