Skip to content
Snippets Groups Projects
Commit c714abee authored by YK Hung's avatar YK Hung Committed by Android (Google) Code Review
Browse files

Merge "[Spa] Add contentDescription for CardButton" into main

parents 0bfa4b4b 5e7cbd4f
No related branches found
No related tags found
No related merge requests found
......@@ -21,6 +21,7 @@ import androidx.compose.ui.graphics.vector.ImageVector
data class CardButton(
val text: String,
val contentDescription: String? = null,
val onClick: () -> Unit,
)
......
......@@ -45,6 +45,8 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.takeOrElse
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.unit.dp
import com.android.settingslib.spa.debug.UiModePreviews
import com.android.settingslib.spa.framework.theme.SettingsDimension
......@@ -182,7 +184,11 @@ private fun Buttons(buttons: List<CardButton>, color: Color) {
@Composable
private fun Button(button: CardButton, color: Color) {
TextButton(onClick = button.onClick) {
TextButton(
onClick = button.onClick,
modifier =
Modifier.semantics { button.contentDescription?.let { this.contentDescription = it } }
) {
Text(text = button.text, color = color)
}
}
......
......@@ -36,8 +36,7 @@ import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class SettingsCardTest {
@get:Rule
val composeTestRule = createComposeRule()
@get:Rule val composeTestRule = createComposeRule()
private val context: Context = ApplicationProvider.getApplicationContext()
......@@ -76,9 +75,7 @@ class SettingsCardTest {
CardModel(
title = "",
text = "",
buttons = listOf(
CardButton(text = TEXT) {}
),
buttons = listOf(CardButton(text = TEXT) {}),
)
)
}
......@@ -94,9 +91,7 @@ class SettingsCardTest {
CardModel(
title = "",
text = "",
buttons = listOf(
CardButton(text = TEXT) { buttonClicked = true }
),
buttons = listOf(CardButton(text = TEXT) { buttonClicked = true }),
)
)
}
......@@ -106,6 +101,25 @@ class SettingsCardTest {
assertThat(buttonClicked).isTrue()
}
@Test
fun settingsCard_buttonHaveContentDescription() {
composeTestRule.setContent {
SettingsCard(
CardModel(
title = "",
text = "",
buttons = listOf(CardButton(
text = TEXT,
contentDescription = CONTENT_DESCRIPTION,
) {}
),
)
)
}
composeTestRule.onNodeWithContentDescription(CONTENT_DESCRIPTION).assertIsDisplayed()
}
@Test
fun settingsCard_dismiss() {
composeTestRule.setContent {
......@@ -130,5 +144,6 @@ class SettingsCardTest {
private companion object {
const val TITLE = "Title"
const val TEXT = "Text"
const val CONTENT_DESCRIPTION = "content-description"
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment