diff --git a/redwood-layout-shared-test/build.gradle b/redwood-layout-shared-test/build.gradle index a1afd1f4a0..783901928e 100644 --- a/redwood-layout-shared-test/build.gradle +++ b/redwood-layout-shared-test/build.gradle @@ -5,6 +5,8 @@ redwoodBuild { sharedSnapshotTests() } +apply plugin: 'app.cash.burst' + kotlin { sourceSets { commonMain { @@ -17,6 +19,7 @@ kotlin { api projects.redwoodWidget api projects.redwoodYoga api libs.kotlin.test + implementation libs.burst } } jvmMain { diff --git a/redwood-layout-shared-test/src/commonMain/kotlin/app/cash/redwood/layout/AbstractFlexContainerTest.kt b/redwood-layout-shared-test/src/commonMain/kotlin/app/cash/redwood/layout/AbstractFlexContainerTest.kt index f82c74c06a..d034d6c988 100644 --- a/redwood-layout-shared-test/src/commonMain/kotlin/app/cash/redwood/layout/AbstractFlexContainerTest.kt +++ b/redwood-layout-shared-test/src/commonMain/kotlin/app/cash/redwood/layout/AbstractFlexContainerTest.kt @@ -15,6 +15,7 @@ */ package app.cash.redwood.layout +import app.cash.burst.Burst import app.cash.redwood.Modifier import app.cash.redwood.layout.api.Constraint import app.cash.redwood.layout.api.CrossAxisAlignment @@ -40,6 +41,7 @@ import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertTrue +@Burst abstract class AbstractFlexContainerTest { abstract val widgetFactory: TestWidgetFactory @@ -75,65 +77,23 @@ abstract class AbstractFlexContainerTest { abstract fun snapshotter(widget: T): Snapshotter - @Test fun testEmptyLayout_Column() { - emptyLayout(FlexDirection.Column) - } - - @Test fun testEmptyLayout_Row() { - emptyLayout(FlexDirection.Row) - } - - private fun emptyLayout( - flexDirection: FlexDirection, + @Test fun testEmptyLayout( + flexDirection: FlexDirections, ) { - assumeTrue(flexDirection in listOf(FlexDirection.Row, FlexDirection.Column)) - val container = flexContainer(flexDirection) + val container = flexContainer(flexDirection.value) container.crossAxisAlignment(CrossAxisAlignment.Start) container.onEndChanges() snapshotter(container.value).snapshot() } - @Test fun testLayoutWithConstraints_Column_Wrap_Wrap() { - layoutWithConstraints(FlexDirection.Column, Constraint.Wrap, Constraint.Wrap) - } - - @Test fun testLayoutWithConstraints_Column_Wrap_Fill() { - layoutWithConstraints(FlexDirection.Column, Constraint.Wrap, Constraint.Fill) - } - - @Test fun testLayoutWithConstraints_Column_Fill_Wrap() { - layoutWithConstraints(FlexDirection.Column, Constraint.Fill, Constraint.Wrap) - } - - @Test fun testLayoutWithConstraints_Column_Fill_Fill() { - layoutWithConstraints(FlexDirection.Column, Constraint.Fill, Constraint.Fill) - } - - @Test fun testLayoutWithConstraints_Row_Wrap_Wrap() { - layoutWithConstraints(FlexDirection.Row, Constraint.Wrap, Constraint.Wrap) - } - - @Test fun testLayoutWithConstraints_Row_Wrap_Fill() { - layoutWithConstraints(FlexDirection.Row, Constraint.Wrap, Constraint.Fill) - } - - @Test fun testLayoutWithConstraints_Row_Fill_Wrap() { - layoutWithConstraints(FlexDirection.Row, Constraint.Fill, Constraint.Wrap) - } - - @Test fun testLayoutWithConstraints_Row_Fill_Fill() { - layoutWithConstraints(FlexDirection.Row, Constraint.Fill, Constraint.Fill) - } - - private fun layoutWithConstraints( - flexDirection: FlexDirection, - width: Constraint, - height: Constraint, + @Test fun testLayoutWithConstraints( + flexDirection: FlexDirections, + width: Constraints, + height: Constraints, ) { - assumeTrue(flexDirection in listOf(FlexDirection.Row, FlexDirection.Column)) - val container = flexContainer(flexDirection) - container.width(width) - container.height(height) + val container = flexContainer(flexDirection.value) + container.width(width.value) + container.height(height.value) container.add( widgetFactory.text( text = movies.first(), @@ -146,19 +106,10 @@ abstract class AbstractFlexContainerTest { snapshotter(container.value).snapshot() } - @Test fun testShortLayout_Column() { - shortLayout(FlexDirection.Column) - } - - @Test fun testShortLayout_Row() { - shortLayout(FlexDirection.Row) - } - - private fun shortLayout( - flexDirection: FlexDirection, + @Test fun testShortLayout( + flexDirection: FlexDirections, ) { - assumeTrue(flexDirection in listOf(FlexDirection.Row, FlexDirection.Column)) - val container = flexContainer(flexDirection) + val container = flexContainer(flexDirection.value) container.crossAxisAlignment(CrossAxisAlignment.Start) movies.take(5).forEach { movie -> container.add(widgetFactory.text(movie)) @@ -167,19 +118,10 @@ abstract class AbstractFlexContainerTest { snapshotter(container.value).snapshot() } - @Test fun testLongLayout_Column() { - longLayout(FlexDirection.Column) - } - - @Test fun testLongLayout_Row() { - longLayout(FlexDirection.Row) - } - - private fun longLayout( - flexDirection: FlexDirection, + @Test fun testLongLayout( + flexDirection: FlexDirections, ) { - assumeTrue(flexDirection in listOf(FlexDirection.Row, FlexDirection.Column)) - val container = flexContainer(flexDirection) + val container = flexContainer(flexDirection.value) container.crossAxisAlignment(CrossAxisAlignment.Start) movies.forEach { movie -> container.add(widgetFactory.text(movie)) @@ -188,19 +130,10 @@ abstract class AbstractFlexContainerTest { snapshotter(container.value).snapshot() } - @Test fun testLayoutWithMarginAndDifferentAlignments_Column() { - layoutWithMarginAndDifferentAlignments(FlexDirection.Column) - } - - @Test fun testLayoutWithMarginAndDifferentAlignments_Row() { - layoutWithMarginAndDifferentAlignments(FlexDirection.Row) - } - - private fun layoutWithMarginAndDifferentAlignments( - flexDirection: FlexDirection, + @Test fun testLayoutWithMarginAndDifferentAlignments( + flexDirection: FlexDirections, ) { - assumeTrue(flexDirection in listOf(FlexDirection.Row, FlexDirection.Column)) - val container = flexContainer(flexDirection) + val container = flexContainer(flexDirection.value) container.width(Constraint.Fill) container.height(Constraint.Fill) container.margin(Margin(start = 5.dp, end = 10.dp, top = 20.dp, bottom = 20.dp)) @@ -217,47 +150,14 @@ abstract class AbstractFlexContainerTest { snapshotter(container.value).snapshot() } - @Test fun testLayoutWithCrossAxisAlignment_Column_Start() { - layoutWithCrossAxisAlignment(FlexDirection.Column, CrossAxisAlignment.Start) - } - - @Test fun testLayoutWithCrossAxisAlignment_Column_Center() { - layoutWithCrossAxisAlignment(FlexDirection.Column, CrossAxisAlignment.Center) - } - - @Test fun testLayoutWithCrossAxisAlignment_Column_End() { - layoutWithCrossAxisAlignment(FlexDirection.Column, CrossAxisAlignment.End) - } - - @Test fun testLayoutWithCrossAxisAlignment_Column_Stretch() { - layoutWithCrossAxisAlignment(FlexDirection.Column, CrossAxisAlignment.Stretch) - } - - @Test fun testLayoutWithCrossAxisAlignment_Row_Start() { - layoutWithCrossAxisAlignment(FlexDirection.Row, CrossAxisAlignment.Start) - } - - @Test fun testLayoutWithCrossAxisAlignment_Row_Center() { - layoutWithCrossAxisAlignment(FlexDirection.Row, CrossAxisAlignment.Center) - } - - @Test fun testLayoutWithCrossAxisAlignment_Row_End() { - layoutWithCrossAxisAlignment(FlexDirection.Row, CrossAxisAlignment.End) - } - - @Test fun testLayoutWithCrossAxisAlignment_Row_Stretch() { - layoutWithCrossAxisAlignment(FlexDirection.Row, CrossAxisAlignment.Stretch) - } - - private fun layoutWithCrossAxisAlignment( - flexDirection: FlexDirection, - crossAxisAlignment: CrossAxisAlignment, + @Test fun testLayoutWithCrossAxisAlignment( + flexDirection: FlexDirections, + crossAxisAlignment: CrossAxisAlignments, ) { - assumeTrue(flexDirection in listOf(FlexDirection.Row, FlexDirection.Column)) - val container = flexContainer(flexDirection) + val container = flexContainer(flexDirection.value) container.width(Constraint.Fill) container.height(Constraint.Fill) - container.crossAxisAlignment(crossAxisAlignment) + container.crossAxisAlignment(crossAxisAlignment.value) movies.forEach { movie -> container.add(widgetFactory.text(movie)) } @@ -281,27 +181,22 @@ abstract class AbstractFlexContainerTest { snapshotter.snapshot("FlexEnd") } - @Test fun testColumnWithMainAxisAlignment_Center() { - columnWithMainAxisAlignment(MainAxisAlignment.Center) - } - - @Test fun testColumnWithMainAxisAlignment_SpaceBetween() { - columnWithMainAxisAlignment(MainAxisAlignment.SpaceBetween) - } - - @Test fun testColumnWithMainAxisAlignment_SpaceAround() { - columnWithMainAxisAlignment(MainAxisAlignment.SpaceAround) + private enum class ColumnMainAxisAlignments( + val value: MainAxisAlignment, + ) { + Center(MainAxisAlignment.Center), + SpaceBetween(MainAxisAlignment.SpaceBetween), + SpaceAround(MainAxisAlignment.SpaceAround), } - private fun columnWithMainAxisAlignment( - mainAxisAlignment: MainAxisAlignment, + private fun testColumnWithMainAxisAlignment( + mainAxisAlignment: ColumnMainAxisAlignments, ) { - assumeTrue(mainAxisAlignment in listOf(MainAxisAlignment.Center, MainAxisAlignment.SpaceBetween, MainAxisAlignment.SpaceAround)) val container = flexContainer(FlexDirection.Column) container.width(Constraint.Fill) container.height(Constraint.Fill) container.crossAxisAlignment(CrossAxisAlignment.Start) - container.mainAxisAlignment(mainAxisAlignment) + container.mainAxisAlignment(mainAxisAlignment.value) movies.forEach { movie -> container.add(widgetFactory.text(movie)) } diff --git a/redwood-layout-shared-test/src/commonMain/kotlin/app/cash/redwood/layout/burst.kt b/redwood-layout-shared-test/src/commonMain/kotlin/app/cash/redwood/layout/burst.kt new file mode 100644 index 0000000000..89fb5c323d --- /dev/null +++ b/redwood-layout-shared-test/src/commonMain/kotlin/app/cash/redwood/layout/burst.kt @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2024 Square, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package app.cash.redwood.layout + +import app.cash.redwood.layout.api.Constraint +import app.cash.redwood.layout.api.CrossAxisAlignment +import app.cash.redwood.yoga.FlexDirection + +enum class Constraints( + val value: Constraint, +) { + Wrap(Constraint.Wrap), + Fill(Constraint.Fill), + ; +} + +enum class CrossAxisAlignments( + val value: CrossAxisAlignment, +) { + Start(CrossAxisAlignment.Start), + Center(CrossAxisAlignment.Center), + End(CrossAxisAlignment.End), + Stretch(CrossAxisAlignment.Stretch), + ; +} + +enum class FlexDirections( + val value: FlexDirection, +) { + Row(FlexDirection.Row), + Column(FlexDirection.Column), + ; +}