package com.cottondb.notes import android.app.Application import androidx.compose.ui.semantics.SemanticsActions import androidx.compose.ui.test.junit4.createAndroidComposeRule import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.text.TextLayoutResult import androidx.compose.ui.text.font.FontFamily import com.cottondb.writing.editor.Span import com.cottondb.writing.editor.Styling import com.cottondb.writing.theme.Writing import com.cottondb.writing.theme.WritingTheme import com.cottondb.writing.theme.WritingType import kotlinx.serialization.json.Json import kotlinx.serialization.json.jsonObject import org.junit.Assert.assertTrue import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner import org.robolectric.annotation.Config import org.robolectric.annotation.GraphicsMode import kotlin.math.abs /** * Settings' theme cards (the launch walk, 22 Nov 2026, Words on emulator-5554): the sample's ticked checklist line * stood crossed out with no box beside it, where the editor draws a ticked box. The card now paints what the editor * paints behind the words: the ticked box in the theme's accent. */ @RunWith(RobolectricTestRunner::class) @GraphicsMode(GraphicsMode.Mode.NATIVE) @Config(sdk = [35], application = Application::class) class ThemeSampleBoxTest { @get:Rule val compose = createAndroidComposeRule() private val theme = WritingTheme.of("linen", "Linen", Json.parseToJsonElement("""{"ground":"#F7F5F0","text":"#2E2E31","heading":"#1C1C1E","secondary":"#8A8A8F","accent":"#D2453A"}""").jsonObject) private val type = WritingType(FontFamily.Default, 17f, 1.5f, 600f, FontFamily.Monospace) /** RULE: the sample's ticked item has its ticked box, as in the editor. */ @Test fun the_ticked_item_has_its_box() { val text = "- [x] Checklist" compose.setContent { Writing(theme, type) { ThemeSample(theme, type, text, Styling(listOf(Span(0, 6, "mark", "glyph", glyph = "ticked"))), chosen = false) {} } } compose.waitForIdle() val node = compose.onNodeWithTag("theme-sample", useUnmergedTree = true) val out = ArrayList() node.fetchSemanticsNode().config[SemanticsActions.GetTextLayoutResult].action!!.invoke(out) val laid = out.single() val box = laid.getBoundingBox(0).let { a -> laid.getBoundingBox(5).let { b -> androidx.compose.ui.geometry.Rect(a.left, a.top, b.right, b.bottom) } } val at = node.fetchSemanticsNode().positionInWindow val view = compose.activity.window.decorView val shot = android.graphics.Bitmap.createBitmap(view.width, view.height, android.graphics.Bitmap.Config.ARGB_8888) compose.runOnIdle { view.draw(android.graphics.Canvas(shot)) } val accent = android.graphics.Color.valueOf(0xFFD2453A.toInt()) var hits = 0 for (x in (at.x + box.left).toInt() until (at.x + box.right).toInt()) for (y in (at.y + box.top).toInt() until (at.y + box.bottom).toInt()) { val c = android.graphics.Color.valueOf(shot.getPixel(x, y)) if (abs(c.red() - accent.red()) < 0.08f && abs(c.green() - accent.green()) < 0.08f && abs(c.blue() - accent.blue()) < 0.08f) hits++ } assertTrue("no ticked box drawn beside the item ($hits accent pixels)", hits > 20) } }