|
17 | 17 |
|
18 | 18 | package com.maxkeppeler.sheets.calendar.functional |
19 | 19 |
|
| 20 | +import android.util.Range |
20 | 21 | import androidx.compose.material3.ExperimentalMaterial3Api |
21 | 22 | import androidx.compose.ui.test.assertIsNotEnabled |
22 | 23 | import androidx.compose.ui.test.junit4.createComposeRule |
@@ -145,6 +146,121 @@ class CalendarViewTests { |
145 | 146 | assert(endDate == testEndDate) |
146 | 147 | } |
147 | 148 |
|
| 149 | + @Test |
| 150 | + fun calendarViewDateSelectionStyleMonthConfigDatesDisabled() { |
| 151 | + val testDate = LocalDate.now().withDayOfMonth(15) |
| 152 | + val newDates = listOf( |
| 153 | + testDate.plusDays(2), |
| 154 | + testDate, |
| 155 | + testDate.minusDays(3) |
| 156 | + ) |
| 157 | + val disabledDates = listOf( |
| 158 | + testDate.minusDays(3), |
| 159 | + ) |
| 160 | + var selectedDate: LocalDate? = null |
| 161 | + rule.setContentAndWaitForIdle { |
| 162 | + CalendarView( |
| 163 | + useCaseState = UseCaseState(visible = true), |
| 164 | + selection = CalendarSelection.Date( |
| 165 | + onSelectDate = { dates -> selectedDate = dates } |
| 166 | + ), |
| 167 | + config = CalendarConfig( |
| 168 | + style = CalendarStyle.MONTH, |
| 169 | + disabledDates = disabledDates |
| 170 | + ) |
| 171 | + ) |
| 172 | + } |
| 173 | + |
| 174 | + newDates.forEach { date -> |
| 175 | + rule.onNodeWithTags( |
| 176 | + TestTags.CALENDAR_DATE_SELECTION, |
| 177 | + date.format(DateTimeFormatter.ISO_DATE) |
| 178 | + ).performClick() |
| 179 | + } |
| 180 | + |
| 181 | + rule.onPositiveButton().performClick() |
| 182 | + assert(selectedDate == testDate) |
| 183 | + } |
| 184 | + |
| 185 | + @Test |
| 186 | + fun calendarViewDatesSelectionStyleMonthConfigDatesDisabled() { |
| 187 | + val testDate = LocalDate.now().withDayOfMonth(15) |
| 188 | + val defaultDates = listOf( |
| 189 | + testDate.minusDays(10), |
| 190 | + testDate.minusDays(5) |
| 191 | + ) |
| 192 | + val newDates = listOf( |
| 193 | + testDate, |
| 194 | + testDate.minusDays(3) |
| 195 | + ) |
| 196 | + val disabledDates = listOf( |
| 197 | + testDate.minusDays(3), |
| 198 | + ) |
| 199 | + var selectedDates: List<LocalDate>? = null |
| 200 | + rule.setContentAndWaitForIdle { |
| 201 | + CalendarView( |
| 202 | + useCaseState = UseCaseState(visible = true), |
| 203 | + selection = CalendarSelection.Dates( |
| 204 | + selectedDates = defaultDates, |
| 205 | + onSelectDates = { dates -> selectedDates = dates } |
| 206 | + ), |
| 207 | + config = CalendarConfig( |
| 208 | + style = CalendarStyle.MONTH, |
| 209 | + disabledDates = disabledDates |
| 210 | + ) |
| 211 | + ) |
| 212 | + } |
| 213 | + |
| 214 | + newDates.forEach { date -> |
| 215 | + rule.onNodeWithTags( |
| 216 | + TestTags.CALENDAR_DATE_SELECTION, |
| 217 | + date.format(DateTimeFormatter.ISO_DATE) |
| 218 | + ).performClick() |
| 219 | + } |
| 220 | + |
| 221 | + rule.onPositiveButton().performClick() |
| 222 | + assert(selectedDates?.sorted() == (defaultDates + testDate).sorted()) |
| 223 | + } |
| 224 | + |
| 225 | + |
| 226 | + @Test |
| 227 | + fun calendarViewPeriodSelectionStyleMonthConfigDatesDisabled() { |
| 228 | + val testDate = LocalDate.now().withDayOfMonth(15) |
| 229 | + val disabledDates = listOf( |
| 230 | + testDate.minusDays(1), |
| 231 | + testDate.minusDays(2), |
| 232 | + testDate.minusDays(3), |
| 233 | + ) |
| 234 | + val testStartDate = testDate.minusDays(4) |
| 235 | + val testEndDate = testDate.plusDays(2) |
| 236 | + var selectedDate: Range<LocalDate>? = null |
| 237 | + rule.setContentAndWaitForIdle { |
| 238 | + CalendarView( |
| 239 | + useCaseState = UseCaseState(visible = true), |
| 240 | + selection = CalendarSelection.Period { startDate, endDate -> |
| 241 | + selectedDate = Range(startDate, endDate) |
| 242 | + }, |
| 243 | + config = CalendarConfig( |
| 244 | + style = CalendarStyle.MONTH, |
| 245 | + disabledDates = disabledDates |
| 246 | + ) |
| 247 | + ) |
| 248 | + } |
| 249 | + |
| 250 | + rule.onNodeWithTags( |
| 251 | + TestTags.CALENDAR_DATE_SELECTION, |
| 252 | + testStartDate.format(DateTimeFormatter.ISO_DATE) |
| 253 | + ).performClick() |
| 254 | + |
| 255 | + rule.onNodeWithTags( |
| 256 | + TestTags.CALENDAR_DATE_SELECTION, |
| 257 | + testEndDate.format(DateTimeFormatter.ISO_DATE) |
| 258 | + ).performClick() |
| 259 | + |
| 260 | + rule.onPositiveButton().assertIsNotEnabled() |
| 261 | + assert(selectedDate == null) |
| 262 | + } |
| 263 | + |
148 | 264 | @Test |
149 | 265 | fun calendarViewPeriodSelectionInvalid() { |
150 | 266 | rule.setContentAndWaitForIdle { |
|
0 commit comments