Cotton code
43 lines · 2.2 KB · KotlinRaw
package com.cottondb.daysimport com.cottondb.days.book.CoreDaysBookimport kotlinx.coroutines.runBlockingimport kotlinx.serialization.json.JsonObjectimport kotlinx.serialization.json.JsonPrimitiveimport org.junit.Assert.assertEqualsimport org.junit.Test/** * Days asks leave to notify the moment an item first earns a reminder (LAUNCH.md, 22 Nov 2026): the core's answer to * `days.add`, `days.change` or `days.move` says `platform_action: request_notifications`, and Days hands it to the * shell's ask (DaysParts sets `askingNotifications`, DaysSurface draws `AskingNotifications`). Nothing else asks. */class DaysAsksLeaveTest {    private fun book(answer: Map<String, String>, asks: MutableList<String>) = CoreDaysBook(        asked = { _, _ -> JsonObject(answer.mapValues { JsonPrimitive(it.value) }) },        leave = { asks += "leave" },    )    /** RULE: an answer that asks for leave asks the OS once; an answer that does not, never. */    @Test    fun an_answer_that_asks_for_leave_asks_the_os() = runBlocking {        val asks = mutableListOf<String>()        book(mapOf("table" to "event", "id" to "e1", "platform_action" to "request_notifications"), asks)            .add("Invented dentist", "days", null, "2026-11-24", "10:00", null)        assertEquals(listOf("leave"), asks)        val quiet = mutableListOf<String>()        book(mapOf("table" to "todo", "id" to "t1"), quiet).add("Invented plant the bulbs", "days", null, "2026-11-24", null, null)        assertEquals(emptyList<String>(), quiet)    }    /** RULE: Days' own surface draws the shell's ask, and Days' parts point the core's answer at it. */    @Test    fun days_draws_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("AskingNotifications(shell)"))        assertEquals(true, parts.contains("askingNotifications = true"))    }}