Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for EdgeButton and IconButton padding in TransformingLazyColumn #2455

Merged
merged 10 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions compose-layout/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ dependencies {
debugImplementation(libs.androidx.activity.compose)
debugImplementation(libs.compose.ui.test.manifest)

testImplementation(libs.compose.material.iconscore)
testImplementation(libs.compose.material.iconsext)
testImplementation(libs.androidx.wear.compose.material3)
testImplementation(libs.junit)
testImplementation(libs.truth)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,25 @@ package com.google.android.horologist.compose.layout

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.ArrowUpward
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.wear.compose.foundation.lazy.TransformingLazyColumn
import androidx.wear.compose.foundation.lazy.TransformingLazyColumnState
import androidx.wear.compose.foundation.lazy.rememberTransformingLazyColumnState
import androidx.wear.compose.material3.AppScaffold
import androidx.wear.compose.material3.EdgeButton
import androidx.wear.compose.material3.EdgeButtonSize
import androidx.wear.compose.material3.Icon
import androidx.wear.compose.material3.IconButton
import androidx.wear.compose.material3.ListHeader
import androidx.wear.compose.material3.MaterialTheme
import androidx.wear.compose.material3.ScreenScaffold
import androidx.wear.compose.material3.ScreenScaffoldDefaults
import androidx.wear.compose.material3.Text
import androidx.wear.compose.material3.TimeText
import androidx.wear.compose.material3.TitleCard
Expand All @@ -41,6 +50,11 @@ import org.robolectric.ParameterizedRobolectricTestRunner

@RunWith(ParameterizedRobolectricTestRunner::class)
class TransformingLazyColumnDefaultsTest(override val device: WearDevice) : WearScreenshotTest() {

override fun testName(suffix: String): String =
"src/test/screenshots/${this.javaClass.simpleName}_${testInfo.methodName}_" +
"${device.id}$suffix.png"

@Composable
override fun TestScaffold(content: @Composable (() -> Unit)) {
content()
Expand All @@ -67,7 +81,9 @@ class TransformingLazyColumnDefaultsTest(override val device: WearDevice) : Wear
first = ColumnItemType.ListHeader,
last = ColumnItemType.Card,
),
modifier = Modifier.fillMaxSize().testTag("TransformingLazyColumn"),
modifier = Modifier
.fillMaxSize()
.testTag("TransformingLazyColumn"),
) {
item {
ListHeader(modifier = Modifier.scrollTransform(this)) {
Expand Down Expand Up @@ -96,6 +112,133 @@ class TransformingLazyColumnDefaultsTest(override val device: WearDevice) : Wear
captureScreenshot("_end")
}

class EdgeButtonPadding(val buttonSize: EdgeButtonSize) : ColumnItemType {
@Composable
override fun topPadding(horizontalPercent: Float): Dp = 0.dp

@Composable
override fun bottomPadding(horizontalPercent: Float): Dp =
ScreenScaffoldDefaults.contentPaddingWithEdgeButton(buttonSize).calculateBottomPadding()
}

@Test
fun ButtonAndEdgeButton() {
lateinit var columnState: TransformingLazyColumnState
runTest {
AppScaffold(
timeText = {
TimeText {
text("10:10")
}
},
// Why black needed here
modifier = Modifier.background(MaterialTheme.colorScheme.background),
) {
columnState = rememberTransformingLazyColumnState()
ScreenScaffold(scrollState = columnState, edgeButton = {
EdgeButton(onClick = { }, buttonSize = EdgeButtonSize.Large) {
Text("To top")
}
}) {
TransformingLazyColumn(
state = columnState,
contentPadding = rememberResponsiveColumnPadding(
first = ColumnItemType.IconButton,
last = EdgeButtonPadding(buttonSize = EdgeButtonSize.Large),
),
modifier = Modifier
.fillMaxSize()
.testTag("TransformingLazyColumn"),
) {
item {
IconButton(onClick = {}) {
Icon(
imageVector = Icons.Rounded.ArrowUpward,
contentDescription = null,
)
}
}
items(3) {
TitleCard(
modifier = Modifier.scrollTransform(this),
onClick = { /* Do something */ },
title = { Text("Title card") },
time = { Text("now") },
) { Text("Card content") }
}
}
}
}
}

composeRule.waitForIdle()

runBlocking {
columnState.scrollToItem(5)
}

captureScreenshot("_end")
}

@Test
fun ButtonAndExtraSmallEdgeButton() {
yschimke marked this conversation as resolved.
Show resolved Hide resolved
lateinit var columnState: TransformingLazyColumnState
runTest {
AppScaffold(
timeText = {
TimeText {
text("10:10")
}
},
// Why black needed here
modifier = Modifier.background(MaterialTheme.colorScheme.background),
) {
columnState = rememberTransformingLazyColumnState()
ScreenScaffold(scrollState = columnState, edgeButton = {
EdgeButton(onClick = { }, buttonSize = EdgeButtonSize.ExtraSmall) {
Text("To top")
}
}) {
TransformingLazyColumn(
state = columnState,
contentPadding = rememberResponsiveColumnPadding(
first = ColumnItemType.IconButton,
last = EdgeButtonPadding(buttonSize = EdgeButtonSize.ExtraSmall),
),
modifier = Modifier
.fillMaxSize()
.testTag("TransformingLazyColumn"),
) {
item {
IconButton(onClick = {}) {
Icon(
imageVector = Icons.Rounded.ArrowUpward,
yschimke marked this conversation as resolved.
Show resolved Hide resolved
contentDescription = null,
)
}
}
items(3) {
TitleCard(
modifier = Modifier.scrollTransform(this),
onClick = { /* Do something */ },
title = { Text("Title card") },
time = { Text("now") },
) { Text("Card content") }
}
}
}
}
}

composeRule.waitForIdle()

runBlocking {
columnState.scrollToItem(5)
}

captureScreenshot("_end")
}

companion object {
@JvmStatic
@ParameterizedRobolectricTestRunner.Parameters
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Loading