From 882e593913c4279ed97102417d80792a02a85251 Mon Sep 17 00:00:00 2001 From: Kristof Nemere <109959688+kristofnemere@users.noreply.github.com> Date: Mon, 7 Oct 2024 11:35:20 +0200 Subject: [PATCH] [MBL-17966][All] Fixed rrule datetime format refs: MBL-17966 affects: All release note: none * Fixed rrule datetime format * added test --- .../CreateUpdateEventViewModel.kt | 4 +-- .../CreateUpdateEventViewModelTest.kt | 27 +++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/libs/pandautils/src/main/java/com/instructure/pandautils/features/calendarevent/createupdate/CreateUpdateEventViewModel.kt b/libs/pandautils/src/main/java/com/instructure/pandautils/features/calendarevent/createupdate/CreateUpdateEventViewModel.kt index 434d80b653..2d39e215f4 100644 --- a/libs/pandautils/src/main/java/com/instructure/pandautils/features/calendarevent/createupdate/CreateUpdateEventViewModel.kt +++ b/libs/pandautils/src/main/java/com/instructure/pandautils/features/calendarevent/createupdate/CreateUpdateEventViewModel.kt @@ -21,7 +21,7 @@ import android.content.res.Resources import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope -import com.google.ical.values.DateValueImpl +import com.google.ical.values.DateTimeValueImpl import com.google.ical.values.Frequency import com.google.ical.values.RRule import com.google.ical.values.Weekday @@ -644,7 +644,7 @@ class CreateUpdateEventViewModel @Inject constructor( } if (customFrequencyUiState.selectedDate != null) { val date = customFrequencyUiState.selectedDate - until = DateValueImpl(date.year, date.monthValue, date.dayOfMonth) + until = DateTimeValueImpl(date.year, date.monthValue, date.dayOfMonth, 0, 0, 0) } else { count = customFrequencyUiState.selectedOccurrences } diff --git a/libs/pandautils/src/test/java/com/instructure/pandautils/features/calendarevent/createupdate/CreateUpdateEventViewModelTest.kt b/libs/pandautils/src/test/java/com/instructure/pandautils/features/calendarevent/createupdate/CreateUpdateEventViewModelTest.kt index 4246555d49..4b9bda474a 100644 --- a/libs/pandautils/src/test/java/com/instructure/pandautils/features/calendarevent/createupdate/CreateUpdateEventViewModelTest.kt +++ b/libs/pandautils/src/test/java/com/instructure/pandautils/features/calendarevent/createupdate/CreateUpdateEventViewModelTest.kt @@ -536,6 +536,33 @@ class CreateUpdateEventViewModelTest { } } + @Test + fun `Frequency updates correctly - Custom with date until`() = runTest { + every { savedStateHandle.get(CreateUpdateEventFragment.INITIAL_DATE) } returns "2024-04-10" + + createViewModel() + + viewModel.handleAction(CreateUpdateEventAction.UpdateCustomFrequencyQuantity(2)) + viewModel.handleAction(CreateUpdateEventAction.UpdateCustomFrequencySelectedTimeUnitIndex(1)) + viewModel.handleAction(CreateUpdateEventAction.UpdateCustomFrequencySelectedDays(setOf(DayOfWeek.MONDAY, DayOfWeek.TUESDAY))) + viewModel.handleAction(CreateUpdateEventAction.UpdateCustomFrequencyEndDate(LocalDate.of(2024, 10, 7))) + viewModel.handleAction(CreateUpdateEventAction.SaveCustomFrequency) + viewModel.handleAction(CreateUpdateEventAction.Save(CalendarEventAPI.ModifyEventScope.ONE)) + + coVerify(exactly = 1) { + repository.createEvent( + any(), + any(), + any(), + "FREQ=WEEKLY;UNTIL=20241007T000000Z;INTERVAL=2;BYDAY=MO,TU", + any(), + any(), + any(), + any() + ) + } + } + private fun createViewModel() { viewModel = CreateUpdateEventViewModel(savedStateHandle, resources, repository, apiPrefs) }