package com.cottondb.notes import android.app.Application import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.platform.testTag import androidx.compose.ui.test.getUnclippedBoundsInRoot import androidx.compose.ui.test.junit4.createComposeRule import androidx.compose.ui.test.onNodeWithContentDescription import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.test.performClick import androidx.compose.ui.text.font.FontFamily import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.height import androidx.compose.ui.unit.width 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 /** * The list search's clear mark (the launch walk, 22 Nov 2026, Words on emulator-5556, 4,000 invented notes): TalkBack * read it as "close", a raw key, and it was 20 dp each way. It now says the core's words and is 48 dp to touch, and * the field keeps its height when the first letter brings the mark. */ @RunWith(RobolectricTestRunner::class) @Config(sdk = [35], qualifiers = "w400dp-h700dp-mdpi", application = Application::class) class NotesSearchClearTest { @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) private var query by mutableStateOf("") private fun show() { compose.setContent { Writing(theme, type) { androidx.compose.foundation.layout.Box(Modifier.testTag("search")) { SearchField("Search your notes", "Clear the search", query, 16.dp) { query = it.orEmpty() } } } } compose.waitForIdle() } @Test fun the_clear_mark_says_what_it_does_and_is_big_enough_to_touch() { query = "lantern" show() val clear = compose.onNodeWithContentDescription("Clear the search").assertExistsReturning() val bounds = clear.getUnclippedBoundsInRoot() assertTrue("the clear mark is ${bounds.width} wide", bounds.width >= 48.dp) assertTrue("the clear mark is ${bounds.height} tall", bounds.height >= 48.dp) clear.performClick() compose.waitForIdle() assertEquals("", query) } @Test fun the_field_keeps_its_height_when_the_mark_comes() { show() val before = compose.onNodeWithTag("search").getUnclippedBoundsInRoot().height compose.runOnIdle { query = "l" } compose.waitForIdle() assertEquals(before, compose.onNodeWithTag("search").getUnclippedBoundsInRoot().height) } private fun androidx.compose.ui.test.SemanticsNodeInteraction.assertExistsReturning() = also { assertExists() } }