package com.cottondb.notes import android.app.Application import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.ui.Modifier import androidx.compose.ui.platform.testTag import androidx.compose.ui.semantics.SemanticsProperties import androidx.compose.ui.test.getUnclippedBoundsInRoot import androidx.compose.ui.test.junit4.createComposeRule import androidx.compose.ui.test.onAllNodesWithText import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.text.AnnotatedString import androidx.compose.ui.text.font.FontFamily import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.width import com.cottondb.writing.editor.StyleBuilder import com.cottondb.writing.list.Row import com.cottondb.writing.list.spokenRow 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.assertEquals 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 /** * 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) } }