package com.cottondb.storyimport android.app.Applicationimport androidx.compose.runtime.getValueimport androidx.compose.runtime.mutableStateOfimport androidx.compose.runtime.setValueimport androidx.compose.ui.test.assertCountEqualsimport androidx.compose.ui.test.junit4.createAndroidComposeRuleimport androidx.compose.ui.test.onAllNodesWithTextimport androidx.compose.ui.test.onNodeWithTagimport com.cottondb.story.ink.InkThemeimport com.cottondb.story.ink.Saidimport org.junit.Assert.assertFalseimport org.junit.Assert.assertTrueimport org.junit.Ruleimport org.junit.Testimport org.junit.runner.RunWithimport org.robolectric.RobolectricTestRunnerimport org.robolectric.annotation.Configimport org.robolectric.annotation.GraphicsModeimport java.io.Fileimport kotlin.math.abs/** * The old shared toast cannot stand in Story (OLD-LOOK item 1, owner, 22 Nov 2026: on his iPhone a line was said twice * at once, on the old torn-paper strip in a typewriter face and in the app's own pill). On Android the paper strip is * drawn only by the shell's fan surface (`PaperToasts` in `AppSurface`, the default `ShellParts.Surface`); Story draws * its own surface, and every `shell.said` is said in Story's own Ink pill, once. Invented words. */@RunWith(RobolectricTestRunner::class)@GraphicsMode(GraphicsMode.Mode.NATIVE)@Config(sdk = [35], qualifiers = "w400dp-h700dp-mdpi", application = Application::class)classStoryOwnToastTest { @get:Ruleval compose = createAndroidComposeRule<androidx.activity.ComponentActivity>()privateval approved = "Approved. Invented Tablet is signing in." @Test fun the_shells_paper_toast_is_never_composed_in_story() { assertTrue("Story draws its own surface, so the fan's (and its paper strip) never stands", StoryParts::class.java.declaredMethods.any { it.name == "Surface" })val app = generateSequence(File("").absoluteFile) { it.parentFile }.first { File(it, "src/story/kotlin/com/cottondb/story").isDirectory }File(app, "src/story").walk().filter { it.extension == "kt" }.forEach { source ->val text = source.readText() listOf("AppSurface(", "PaperToasts(", "SendReceipt(").forEach { raise -> assertFalse("${source.name} raises the old toast ($raise)", raise in text) } } assertTrue(File(app, "src/story/kotlin/com/cottondb/story/StorySurface.kt").readText().contains("Said(shell)")) } @Test fun a_said_line_stands_once_in_storys_own_pill_and_goes() {var said by mutableStateOf<String?>(approved) compose.setContent { InkTheme { Said(said) { said = null } } } compose.waitForIdle() compose.onAllNodesWithText(approved).assertCountEquals(1)val (own, paper) = colours("story-said", 0xFF161A3A.toInt()) assertTrue("drawn on Story's own pill, the Ink navy ($own of the line's pixels)", own > 0.5f) assertTrue("not on the paper strip ($paper of the line's pixels cream)", paper < 0.05f) compose.mainClock.advanceTimeBy(3600) compose.waitForIdle() compose.onAllNodesWithText(approved).assertCountEquals(0) }/** The share of the pixels inside the node [tag] of [own] colour, and of the shell's paper cream (Paper.cream, #F0E5D8). */privatefun colours(tag: String, own: Int): Pair<Float, Float> {val bounds = compose.onNodeWithTag(tag, useUnmergedTree = true).fetchSemanticsNode().boundsInWindowval view = compose.activity.window.decorViewval shot = android.graphics.Bitmap.createBitmap(view.width, view.height, android.graphics.Bitmap.Config.ARGB_8888) compose.runOnIdle { view.draw(android.graphics.Canvas(shot)) }fun near(c: android.graphics.Color, to: Int) = android.graphics.Color.valueOf(to).let { abs(c.red() - it.red()) < 0.04f && abs(c.green() - it.green()) < 0.04f && abs(c.blue() - it.blue()) < 0.04f }var mine = 0; var cream = 0for (x in bounds.left.toInt() until bounds.right.toInt()) for (y in bounds.top.toInt() until bounds.bottom.toInt()) {val c = android.graphics.Color.valueOf(shot.getPixel(x, y))if (near(c, own)) mine++if (near(c, 0xFFF0E5D8.toInt())) cream++ }val all = ((bounds.right.toInt() - bounds.left.toInt()) * (bounds.bottom.toInt() - bounds.top.toInt())).coerceAtLeast(1).toFloat()return mine / all to cream / all }}