package com.cottondb.notes import android.app.Application import androidx.test.core.app.ApplicationProvider import com.cottondb.shell.look.LookFaces 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.Test import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner import org.robolectric.annotation.Config /** * A face chosen in Look reaches the note's words in Words (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 `notes.settings`' answer in * turn (`face`, and the `font` builds before Look read); the writing type every note is drawn in then carries that * face's family, built from the files this build carries, and never Figtree. */ @RunWith(RobolectricTestRunner::class) @Config(sdk = [35], application = Application::class) class NotesLookFaceTest { 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 look(face: String): JsonObject { val faces = kit["faces"]!!.jsonArray.filter { it.jsonObject["id"]!!.jsonPrimitive.content in LOOK_FACES } return Json.parseToJsonElement("""{"app":"notes","face":"$face"}""").jsonObject.let { JsonObject(it + ("faces" to JsonArray(faces))) } } private fun settings(face: String) = Json.parseToJsonElement("""{"face":"$face","font":"$face","font_size":17,"line_height":1.5,"line_width":0}""").jsonObject @Test fun every_chosen_face_reaches_the_writing_type() { val assets = ApplicationProvider.getApplicationContext().assets val model = NotesModel() val figtree = NotesLook.faces(assets).first model.settings = settings("own"); model.look = look("own") assertEquals("Words' own face is Figtree", figtree, model.type(assets)!!.face) LOOK_FACES.forEach { face -> model.look = look(face); model.settings = settings(face) val family = LookFaces.chosen(assets, model.look) assertNotNull("this build carries no file of $face", family) assertEquals("a note's words in $face", family, model.type(assets)!!.face) assertNotEquals("$face is drawn as Figtree", figtree, model.type(assets)!!.face) } } private companion object { val LOOK_FACES = listOf("serif", "typewriter", "hyperlegible", "dyslexic") } }