package com.cottondb.daysimport android.app.Applicationimport androidx.compose.runtime.CompositionLocalProviderimport androidx.compose.ui.platform.LocalContextimport androidx.compose.ui.test.assertIsDisplayedimport androidx.compose.ui.test.junit4.createComposeRuleimport androidx.compose.ui.test.onNodeWithTextimport androidx.compose.ui.test.performClickimport com.cottondb.days.book.CoreDaysBookimport com.cottondb.days.pen.DaysCardLookimport com.cottondb.days.pen.penFontsimport com.cottondb.days.ui.LeaveNoticeimport com.cottondb.shell.LocalCardLookimport com.cottondb.shell.core.CottonCoreimport com.cottondb.shell.strimport kotlinx.coroutines.runBlockingimport kotlinx.serialization.json.JsonObjectimport kotlinx.serialization.json.jsonObjectimport org.junit.Assert.assertEqualsimport org.junit.Ruleimport org.junit.Testimport org.junit.runner.RunWithimport org.robolectric.RobolectricTestRunnerimport org.robolectric.annotation.Config/** * Leave to notify is asked with its reason shown first (LAUNCH.md section 4; the launch walk of 22 Nov 2026): the first * timed event put Android's "Allow Days to send you notifications?" straight over the list, with nothing in Days * saying why. The core's answer now carries `leave` (title, body, go, notNow); Days shows it, and only Continue goes on * to the OS's ask. */@RunWith(RobolectricTestRunner::class)@Config(sdk = [35], qualifiers = "w411dp-h914dp-xhdpi", application = Application::class)classDaysLeaveNoticeTest { @get:Ruleval compose = createComposeRule()privatefun answer(json: String): JsonObject = CottonCore.json.parseToJsonElement(json).jsonObjectprivateval why = """{"title":"Reminders","body":"Days can remind you shortly before this.","go":"Continue","notNow":"Not now"}"""/** RULE: the book hands the core's reason on with the ask, so the phone can say why before the OS asks. */ @Test fun the_book_hands_on_why() = runBlocking {val handed = mutableListOf<JsonObject?>()CoreDaysBook(asked = { _, _ -> answer("""{"table":"event","id":"e1","platform_action":"request_notifications","leave":$why}""") }, leave = { handed += it }) .add("Invented dentist", "days", null, "2026-11-24", "10:00", null) assertEquals("Reminders", handed.single()?.str("title")) }/** RULE: the reason stands first; Not now asks nothing; Continue goes on to the OS. */ @Test fun why_stands_before_the_os_asks() {var went = 0var not = 0 compose.setContent {CompositionLocalProvider(LocalCardLook provides DaysCardLook(penFonts(LocalContext.current))) {LeaveNotice(answer(why), onGo = { went++ }, onNotNow = { not++ }) } } compose.onNodeWithText("Days can remind you shortly before this.").assertIsDisplayed() compose.onNodeWithText("Not now").performClick() assertEquals(0 to 1, went to not) compose.onNodeWithText("Continue").performClick() assertEquals(1, went) }/** RULE: Days' surface draws the reason, and its parts point the core's answer at it. */ @Test fun days_draws_why_before_the_shells_ask() {val repo = generateSequence(java.io.File("").absoluteFile) { it.parentFile }.first { java.io.File(it, "apps/registry.json").isFile }val surface = java.io.File(repo, "apps/android/app/src/days/kotlin/com/cottondb/days/DaysSurface.kt").readText()val parts = java.io.File(repo, "apps/android/app/src/days/kotlin/com/cottondb/days/DaysParts.kt").readText() assertEquals(true, surface.contains("LeaveNotice(")) assertEquals(true, parts.contains("state.leaving = why")) }}