Modern Apps git

← Modern-Apps.git

calendar: make EditEventComposeTest deterministic in CI

Commit
8410f2e7eb2228376c9499413ff5ddc1736f9119
Author
Vayun Mathur <[email protected]>
When
2026-11-07 13:55 UTC (28 days ago)
Parents
102a233
Timed Instances render in the system zone while the fixtures
were built in UTC, so on a CI box in another zone the 09:00
event moved to a different hour and off the visible grid.
Pin the class default timezone to UTC (restored afterwards)
and build the hourly-grid fixture at 01:00 in the system zone,
near the top of the 24-hour scroll view on any viewport.

Verified: targeted class 3x (--no-build-cache), the class also
passes under TZ=Pacific/Kiritimati, and the full
:calendar:testDevUnitTest suite (303 tests) passes.

(cherry picked from commit 09b71775c0614361c789e8fdb19dc9580d31baa5)

Diff

calendar/src/test/java/com/vayunmathur/calendar/ui/EditEventComposeTest.kt
diff --git a/calendar/src/test/java/com/vayunmathur/calendar/ui/EditEventComposeTest.kt b/calendar/src/test/java/com/vayunmathur/calendar/ui/EditEventComposeTest.ktindex 2e12615e4a..b14a3742eb 100644--- a/calendar/src/test/java/com/vayunmathur/calendar/ui/EditEventComposeTest.kt+++ b/calendar/src/test/java/com/vayunmathur/calendar/ui/EditEventComposeTest.kt@@ -22,14 +22,18 @@ import com.vayunmathur.library.ui.rememberOdfMarkdownEditorController import com.vayunmathur.library.util.NavBackStack import kotlinx.datetime.DayOfWeek import kotlinx.datetime.LocalDate+import kotlinx.datetime.LocalDateTime import kotlinx.datetime.LocalTime import kotlinx.datetime.TimeZone import kotlinx.datetime.plus+import kotlinx.datetime.toInstant import androidx.compose.ui.unit.dp import org.junit.Rule import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner import java.util.Locale+import kotlin.test.AfterTest+import kotlin.test.BeforeTest import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertNotNull@@ -45,6 +49,22 @@ class EditEventComposeTest {     private val context: Context get() = ApplicationProvider.getApplicationContext()     private fun backStack() = NavBackStack<Route>(arrayOf(Route.Calendar)) +    // Test data is built in UTC (CalendarTestData.at), while Instance renders timed+    // events in the system zone. Pin UTC so a CI box in another zone cannot move+    // the 09:00 event to a different hour (or off the visible grid).+    private var previousTimeZone: java.util.TimeZone? = null++    @BeforeTest+    fun pinTimeZoneToUtc() {+        previousTimeZone = java.util.TimeZone.getDefault()+        java.util.TimeZone.setDefault(java.util.TimeZone.getTimeZone("UTC"))+    }++    @AfterTest+    fun restoreTimeZone() {+        java.util.TimeZone.setDefault(previousTimeZone)+    }+     // --- reminderLabel / presets ------------------------------------------      @Test@@ -311,8 +331,16 @@ class EditEventComposeTest {     @Test     fun `hourly grid shows timed event and click fires`() {         var clicked: com.vayunmathur.calendar.data.Instance? = null-        val inst = D.instance()-        val timed = mapOf(D.TODAY to mapOf(9 to listOf(inst)))+        // Instance renders timed events in the system zone, so build the fixture+        // at 01:00 in that zone (not UTC): another zone would otherwise move the+        // event to a different hour, and 01:00 stays near the top of the 24-hour+        // scroll view so it is displayed without scrolling on any viewport.+        val zone = TimeZone.currentSystemDefault()+        val inst = D.instance().copy(+            begin = LocalDateTime(D.TODAY, LocalTime(1, 0)).toInstant(zone).toEpochMilliseconds(),+            end = LocalDateTime(D.TODAY, LocalTime(2, 0)).toInstant(zone).toEpochMilliseconds(),+        )+        val timed = mapOf(D.TODAY to mapOf(1 to listOf(inst)))         rule.mainClock.autoAdvance = false         rule.setContent {             HourlyGrid(context, timed, listOf(D.TODAY), shrinkEmptyHours = false, onEventClick = { clicked = it }, innerPadding = androidx.compose.foundation.layout.PaddingValues(0.dp))