package com.cottondb.days import android.app.Application import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.test.assertIsNotSelected import androidx.compose.ui.test.assertIsSelected import androidx.compose.ui.test.junit4.createComposeRule import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.test.onNodeWithText import androidx.compose.ui.test.performClick import com.cottondb.days.book.Item import com.cottondb.days.pen.DaysCardLook import com.cottondb.days.pen.penFonts import com.cottondb.days.ui.AlertChoices import com.cottondb.shell.LocalCardLook import com.cottondb.shell.core.CottonCore import kotlinx.serialization.json.JsonPrimitive import kotlinx.serialization.json.jsonObject import org.junit.Assert.assertEquals import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner import org.robolectric.annotation.Config /** * "No alert" did nothing (launch walk of Days, 22 Nov 2026): an event with no alert stored drew No alert chosen though * the core reminds it ten minutes before, and choosing No alert wrote the same empty alert, so it still reminded. Now * the sheet draws the choices the core answers, marks the one that stands, and No alert is written as "none". */ @RunWith(RobolectricTestRunner::class) @Config(sdk = [35], qualifiers = "w411dp-h914dp-xhdpi", application = Application::class) class DaysAlertChoicesTest { @get:Rule val compose = createComposeRule() private val words = mapOf("change.no_alert" to "No alert", "change.alert_at" to "At the time", "change.alert_before" to "{n} min before") private fun say(key: String, fills: Map) = fills.entries.fold(words.getValue(key)) { line, (k, v) -> line.replace("{$k}", v) } /** The sheet's answer for an invented event, as `days.item` gives it with [standing] on. */ private fun item(standing: String) = Item.of("event", "e", CottonCore.json.parseToJsonElement( """{"table":"event","id":"e","whose":"yours","says":"Yours","words":"Invented dentist","day":"2026-11-24","time":"10:00","end":null, "mark":null,"note":null,"alert":$standing,"done":false,"repeats":false, "alerts":[{"alert":"none","on":${standing == "\"none\""}},{"alert":0,"on":${standing == "0"}},{"alert":10,"on":${standing == "10"}}, {"alert":30,"on":${standing == "30"}},{"alert":60,"on":${standing == "60"}}], "canChange":{"title":true,"time":true,"mark":true,"note":true,"alert":true}}""").jsonObject) private var written: JsonPrimitive? = null private fun show(item: Item) = compose.setContent { CompositionLocalProvider(LocalCardLook provides DaysCardLook(penFonts(LocalContext.current))) { val standing = item.alerts.firstOrNull { it.on }?.alert var chosen by remember { mutableStateOf(standing) } AlertChoices(item.alerts, chosen, ::say) { chosen = it; written = it } } } @Test fun an_event_with_no_alert_stored_shows_its_ten_minutes_chosen_not_no_alert() { show(item("10")) compose.onNodeWithTag("days-change-alert-10").assertIsSelected() compose.onNodeWithTag("days-change-alert-none").assertIsNotSelected() compose.onNodeWithText("10 min before").assertExists() compose.onNodeWithText("At the time").assertExists() } @Test fun choosing_no_alert_chooses_none_and_it_shows_chosen() { show(item("10")) compose.onNodeWithTag("days-change-alert-none").performClick() compose.waitForIdle() assertEquals("No alert is written as none, never as the empty default", JsonPrimitive("none"), written) compose.onNodeWithTag("days-change-alert-none").assertIsSelected() compose.onNodeWithTag("days-change-alert-10").assertIsNotSelected() } @Test fun an_event_set_to_no_alert_shows_no_alert_chosen() { show(item("\"none\"")) compose.onNodeWithTag("days-change-alert-none").assertIsSelected() compose.onNodeWithTag("days-change-alert-10").assertIsNotSelected() compose.onNodeWithTag("days-change-alert-30").performClick() compose.waitForIdle() assertEquals(JsonPrimitive(30), written) } }