package com.cottondb.story 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.story.ink.InkTheme import com.cottondb.story.ink.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 Story draws (a scene's action and dialogue; titles keep Courier Prime) (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 scene's words are then * laid out in that face's family, built from the files this build carries, and never in IBM Plex Mono. */ @RunWith(RobolectricTestRunner::class) @Config(sdk = [35], application = Application::class) class StoryLookFaceTest { @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":"story","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 { InkTheme { Words("She opens the door.", 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("Story's words in $face", family, drawnFamily()) assertNotEquals("$face is drawn as Story's 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") } }