Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5e7cbd4f authored by pajacechen's avatar pajacechen
Browse files

[Spa] Add contentDescription for CardButton

Test: Unit test
Bug: 305856149
Change-Id: Ife9204badfa6d3397db761a802d44f9f0dcbbc82
parent 158d7e32
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import androidx.compose.ui.graphics.vector.ImageVector

data class CardButton(
    val text: String,
    val contentDescription: String? = null,
    val onClick: () -> Unit,
)

+7 −1
Original line number Diff line number Diff line
@@ -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)
    }
}
+23 −8
Original line number Diff line number Diff line
@@ -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"
    }
}