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

Explicitly configure layouts in snapshot tests #2389

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class ComposeUiFlexContainerTest(
backgroundColor: Int,
): ComposeTestFlexContainer {
return ComposeTestFlexContainer(direction, backgroundColor)
.apply { applyDefaults() }
}

override fun row() = flexContainer(FlexDirection.Row)
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.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,21 @@ abstract class AbstractFlexContainerTest<T : Any> {
backgroundColor: Int = argb(51, 0, 0, 255),
): TestFlexContainer<T>

/**
* Yoga node’s default values for properties like alignment are different from Redwood's default
* values, so we explicitly apply those defaults here. This is only necessary in tests; in
* production the framework explicitly sets every property.
*/
protected fun TestFlexContainer<*>.applyDefaults() {
width(Constraint.Wrap)
height(Constraint.Wrap)
margin(Margin.Zero)
overflow(Overflow.Clip)
crossAxisAlignment(CrossAxisAlignment.Start)
mainAxisAlignment(MainAxisAlignment.Start)
onScroll(null)
}

/** Returns a non-lazy flex container row, even if the test is for a LazyList. */
abstract fun row(): Row<T>

Expand Down Expand Up @@ -119,7 +134,14 @@ abstract class AbstractFlexContainerTest<T : Any> {
val container = flexContainer(flexDirection)
container.width(width)
container.height(height)
container.add(widgetFactory.text(movies.first()))
container.add(
widgetFactory.text(
text = movies.first(),
modifier = Modifier
.then(HorizontalAlignmentImpl(CrossAxisAlignment.Stretch))
.then(VerticalAlignmentImpl(CrossAxisAlignment.Stretch)),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This restores the old behavior to preserve the expectation of the test

),
)
container.onEndChanges()
snapshotter(container.value).snapshot()
}
Expand Down Expand Up @@ -484,7 +506,10 @@ abstract class AbstractFlexContainerTest<T : Any> {
parent.children.insert(
0,
flexContainer(FlexDirection.Column).apply {
modifier = GrowImpl(1.0)
modifier = Modifier
.then(GrowImpl(1.0))
.then(HorizontalAlignmentImpl(CrossAxisAlignment.Stretch))
.then(VerticalAlignmentImpl(CrossAxisAlignment.Stretch))
width(Constraint.Fill)
mainAxisAlignment(MainAxisAlignment.SpaceBetween)
add(
Expand All @@ -505,7 +530,10 @@ abstract class AbstractFlexContainerTest<T : Any> {
parent.children.insert(
1,
flexContainer(FlexDirection.Column).apply {
modifier = GrowImpl(1.0)
modifier = Modifier
.then(GrowImpl(1.0))
.then(HorizontalAlignmentImpl(CrossAxisAlignment.Stretch))
.then(VerticalAlignmentImpl(CrossAxisAlignment.Stretch))
width(Constraint.Fill)
mainAxisAlignment(MainAxisAlignment.SpaceBetween)
add(
Expand Down Expand Up @@ -777,12 +805,20 @@ abstract class AbstractFlexContainerTest<T : Any> {
}
.also { column.add(it) }

val rowA1 = widgetFactory.text("A1 ".repeat(50))
.apply { modifier = FlexImpl(1.0) }
.also { rowA.children.insert(0, it) }
val rowA2 = widgetFactory.text("A-TWO ".repeat(50))
.apply { modifier = FlexImpl(1.0) }
.also { rowA.children.insert(1, it) }
val rowA1 = widgetFactory.text(
text = "A1 ".repeat(50),
modifier = Modifier
.then(FlexImpl(1.0))
.then(HorizontalAlignmentImpl(CrossAxisAlignment.Stretch))
.then(VerticalAlignmentImpl(CrossAxisAlignment.Stretch)),
).also { rowA.children.insert(0, it) }
val rowA2 = widgetFactory.text(
text = "A-TWO ".repeat(50),
modifier = Modifier
.then(FlexImpl(1.0))
.then(HorizontalAlignmentImpl(CrossAxisAlignment.Stretch))
.then(VerticalAlignmentImpl(CrossAxisAlignment.Stretch)),
).also { rowA.children.insert(1, it) }

val rowB = widgetFactory.text("B1 ".repeat(5))
.apply {
Expand Down Expand Up @@ -811,13 +847,12 @@ abstract class AbstractFlexContainerTest<T : Any> {
height(Constraint.Fill)
}

val alignStart = HorizontalAlignmentImpl(CrossAxisAlignment.Start)
flexContainer(FlexDirection.Column)
.apply {
width(Constraint.Fill)
modifier = WidthImpl(25.dp)
add(widgetFactory.text("ok", alignStart)) // This is under 25.dp in width.
add(widgetFactory.text("1 2 3 4", alignStart)) // Each character is under 25.dp in width.
add(widgetFactory.text("ok")) // This is under 25.dp in width.
add(widgetFactory.text("1 2 3 4")) // Each character is under 25.dp in width.
onEndChanges()
}
.also { fullWidthParent.children.insert(0, it) }
Expand All @@ -826,8 +861,8 @@ abstract class AbstractFlexContainerTest<T : Any> {
.apply {
width(Constraint.Fill)
modifier = WidthImpl(25.dp)
add(widgetFactory.text("overflows parent", alignStart)) // This is over 25.dp in width.
add(widgetFactory.text("1 2 3 4", alignStart)) // Each character is under 25.dp in width.
add(widgetFactory.text("overflows parent")) // This is over 25.dp in width.
add(widgetFactory.text("1 2 3 4")) // Each character is under 25.dp in width.
onEndChanges()
}
.also { fullWidthParent.children.insert(1, it) }
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.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class UIViewFlexContainerTest(
override fun invalidateSize() {
}
}

applyDefaults()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class ViewFlexContainerTest(
value.setBackgroundColor(backgroundColor)
}
return ViewTestFlexContainer(delegate)
.apply { applyDefaults() }
}

override fun row() = flexContainer(FlexDirection.Row)
Expand Down
Loading