package com.cottondb.days import android.app.Application import androidx.compose.ui.Modifier import androidx.compose.ui.platform.testTag import androidx.compose.ui.semantics.SemanticsActions import androidx.compose.ui.test.junit4.createComposeRule import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.text.TextLayoutResult import androidx.compose.ui.text.font.FontFamily import androidx.test.core.app.ApplicationProvider import com.cottondb.days.pen.PenTheme import com.cottondb.days.pen.Words import com.cottondb.shell.look.LookFaces import com.cottondb.shell.look.LookState import kotlinx.serialization.json.Json import kotlinx.serialization.json.JsonArray import kotlinx.serialization.json.JsonObject import kotlinx.serialization.json.jsonArray import kotlinx.serialization.json.jsonObject import kotlinx.serialization.json.jsonPrimitive import org.junit.Assert.assertEquals import org.junit.Assert.assertNotEquals import org.junit.Assert.assertNotNull import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner import org.robolectric.annotation.Config /** * A face chosen in Look reaches the words Days draws (owner, 23 Nov 2026: on his iPhone a font changed nothing while * size, papers and inks did). Each of Look's faces, as the kit names them, stands in turn; the day's words are then * laid out in that face's family, built from the files this build carries, and never in DM Mono. */ @RunWith(RobolectricTestRunner::class) @Config(sdk = [35], application = Application::class) class DaysLookFaceTest { @get:Rule val compose = createComposeRule() private val kit: JsonObject by lazy { var dir = java.io.File("").absoluteFile while (!java.io.File(dir, "crates/cotton-core/kits/look/look.json").isFile) dir = dir.parentFile Json.parseToJsonElement(java.io.File(dir, "crates/cotton-core/kits/look/look.json").readText()).jsonObject } private fun answer(face: String): JsonObject { val faces = kit["faces"]!!.jsonArray.filter { it.jsonObject["id"]!!.jsonPrimitive.content in LOOK_FACES } return Json.parseToJsonElement("""{"app":"days","light":"grey","dark":"grey","ink":"blue","face":"$face","size":1.0,"sizes_are":"scale","colours":{"light":{},"dark":{}}}""") .jsonObject.let { JsonObject(it + ("faces" to JsonArray(faces))) } } @Test fun every_chosen_face_reaches_the_drawn_words() { val assets = ApplicationProvider.getApplicationContext().assets LookState.standForTest(answer("own")) try { compose.setContent { PenTheme { Words("Tuesday 24", Modifier.testTag("words")) } } val own = drawnFamily() LOOK_FACES.forEach { face -> val given = answer(face) val family = LookFaces.chosen(assets, given) assertNotNull("this build carries no file of $face", family) compose.runOnIdle { LookState.standForTest(given) } assertEquals("Days' words in $face", family, drawnFamily()) assertNotEquals("$face is drawn as Days' own face", own, drawnFamily()) } } finally { LookState.standForTest(null) } } private fun drawnFamily(): FontFamily? { compose.waitForIdle() val laid = mutableListOf() compose.onNodeWithTag("words", useUnmergedTree = true).fetchSemanticsNode().config[SemanticsActions.GetTextLayoutResult].action?.invoke(laid) return laid.single().layoutInput.style.fontFamily } private companion object { val LOOK_FACES = listOf("serif", "typewriter", "hyperlegible", "dyslexic") } }