Cotton code
93 lines · 4.5 KB · KotlinRaw
package com.cottondb.notesimport android.app.Applicationimport androidx.compose.foundation.layout.Boximport androidx.compose.foundation.layout.fillMaxWidthimport androidx.compose.foundation.layout.heightimport androidx.compose.ui.Modifierimport androidx.compose.ui.platform.testTagimport androidx.compose.ui.semantics.SemanticsPropertiesimport androidx.compose.ui.test.getUnclippedBoundsInRootimport androidx.compose.ui.test.junit4.createComposeRuleimport androidx.compose.ui.test.onAllNodesWithTextimport androidx.compose.ui.test.onNodeWithTagimport androidx.compose.ui.text.AnnotatedStringimport androidx.compose.ui.text.font.FontFamilyimport androidx.compose.ui.unit.dpimport androidx.compose.ui.unit.widthimport com.cottondb.writing.editor.StyleBuilderimport com.cottondb.writing.list.Rowimport com.cottondb.writing.list.spokenRowimport com.cottondb.writing.theme.Writingimport com.cottondb.writing.theme.WritingThemeimport com.cottondb.writing.theme.WritingTypeimport kotlinx.serialization.json.Jsonimport kotlinx.serialization.json.jsonObjectimport org.junit.Assert.assertEqualsimport org.junit.Assert.assertTrueimport org.junit.Ruleimport org.junit.Testimport org.junit.runner.RunWithimport org.robolectric.RobolectricTestRunnerimport org.robolectric.annotation.Config/** * What the Play-readiness walk found on emulator-5604 (26 Nov 2026, text size 2.0, night, a small phone, a tablet, * TalkBack): the list's search field read "Edit box" with no name; a row with no preview read "Third, , 3:20 am"; Look's * sample note read its hidden marks aloud; Settings' rows stretched across a tablet, each chevron 800 dp from its name. */@RunWith(RobolectricTestRunner::class)@Config(sdk = [35], qualifiers = "w400dp-h700dp-mdpi", application = Application::class)class WordsPlayWalkTest {    @get:Rule val compose = createComposeRule()    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)    @Test fun the_search_field_is_named_by_its_hint_and_the_hint_is_not_read_twice() {        compose.setContent { Writing(theme, type) { SearchField("Search your notes", "Clear the search", "", 16.dp) {} } }        compose.waitForIdle()        val field = compose.onNodeWithTag("list-search-field").fetchSemanticsNode()        assertEquals(listOf("Search your notes"), field.config[SemanticsProperties.ContentDescription])        assertEquals(0, compose.onAllNodesWithText("Search your notes", useUnmergedTree = true).fetchSemanticsNodes().size)    }    @Test fun a_row_reads_only_the_parts_it_has() {        assertEquals("Third, 3:20 am", spokenRow(Row("1", "Third", "", "3:20 am", 2)))        assertEquals("Groceries, eggs and rice, Yesterday", spokenRow(Row("2", "Groceries", "eggs and rice", "Yesterday", 2)))        assertEquals("eggs, 23 Nov", spokenRow(Row("3", null, "eggs", "23 Nov", 2)))    }    @Test fun the_look_sample_is_read_without_its_hidden_marks() {        val text = AnnotatedString.Builder("# Saturday market\nBring the **green bag**").apply {            addStyle(StyleBuilder.hidden, 0, 2)            addStyle(StyleBuilder.hidden, 28, 30)            addStyle(StyleBuilder.hidden, 39, 41)        }.toAnnotatedString()        assertEquals("Saturday market\nBring the green bag", shownWords(text))    }    @Test @Config(qualifiers = "w1280dp-h800dp-mdpi")    fun a_settings_page_stands_in_a_readable_column_on_a_tablet() {        compose.setContent {            Writing(theme, type) {                NotesSkin.Page("Settings", "Back", "settings-top", {}) { Box(Modifier.fillMaxWidth().height(40.dp).testTag("a-row")) }            }        }        compose.waitForIdle()        val row = compose.onNodeWithTag("a-row").getUnclippedBoundsInRoot()        assertTrue("the row is ${row.width} wide", row.width <= PAGE_MOST)        val left = row.left        assertTrue("the column stands at ${left} from the left, not centred", left > 200.dp)    }    @Test fun a_settings_page_keeps_the_phone_width_on_a_phone() {        compose.setContent {            Writing(theme, type) {                NotesSkin.Page("Settings", "Back", "settings-top", {}) { Box(Modifier.fillMaxWidth().height(40.dp).testTag("a-row")) }            }        }        compose.waitForIdle()        assertEquals(360.dp, compose.onNodeWithTag("a-row").getUnclippedBoundsInRoot().width)    }}