diff --git a/redwood-layout-composeui/src/androidUnitTest/kotlin/app/cash/redwood/layout/composeui/ComposeUiFlexContainerTest.kt b/redwood-layout-composeui/src/androidUnitTest/kotlin/app/cash/redwood/layout/composeui/ComposeUiFlexContainerTest.kt index 1daa4acfb6..271fc763ae 100644 --- a/redwood-layout-composeui/src/androidUnitTest/kotlin/app/cash/redwood/layout/composeui/ComposeUiFlexContainerTest.kt +++ b/redwood-layout-composeui/src/androidUnitTest/kotlin/app/cash/redwood/layout/composeui/ComposeUiFlexContainerTest.kt @@ -54,8 +54,8 @@ class ComposeUiFlexContainerTest( override fun flexContainer(direction: FlexDirection) = ComposeTestFlexContainer(direction) - override fun widget(text: String, modifier: RedwoodModifier) = object : Text<@Composable () -> Unit> { - private var text by mutableStateOf(text) + override fun widget() = object : Text<@Composable () -> Unit> { + private var text by mutableStateOf("") override val value = @Composable { BasicText( @@ -65,7 +65,7 @@ class ComposeUiFlexContainerTest( ) } - override var modifier = modifier + override var modifier: RedwoodModifier = RedwoodModifier override fun text(text: String) { this.text = text diff --git a/redwood-layout-composeui/src/androidUnitTest/kotlin/app/cash/redwood/layout/composeui/ComposeUiSpacerTest.kt b/redwood-layout-composeui/src/androidUnitTest/kotlin/app/cash/redwood/layout/composeui/ComposeUiSpacerTest.kt index 7ac206a303..4e820dfaf2 100644 --- a/redwood-layout-composeui/src/androidUnitTest/kotlin/app/cash/redwood/layout/composeui/ComposeUiSpacerTest.kt +++ b/redwood-layout-composeui/src/androidUnitTest/kotlin/app/cash/redwood/layout/composeui/ComposeUiSpacerTest.kt @@ -21,10 +21,8 @@ import androidx.compose.foundation.text.BasicText import androidx.compose.runtime.Composable import app.cash.paparazzi.DeviceConfig import app.cash.paparazzi.Paparazzi -import app.cash.redwood.Modifier import app.cash.redwood.layout.AbstractSpacerTest import app.cash.redwood.layout.widget.Spacer -import app.cash.redwood.ui.dp import app.cash.redwood.widget.Widget import com.android.ide.common.rendering.api.SessionParams import org.junit.Rule @@ -41,15 +39,7 @@ class ComposeUiSpacerTest : AbstractSpacerTest<@Composable () -> Unit>() { renderingMode = SessionParams.RenderingMode.SHRINK, ) - override fun widget( - width: Int, - height: Int, - modifier: Modifier, - ): Spacer<@Composable () -> Unit> = ComposeUiSpacer().apply { - this.modifier = modifier - width(width.dp) - height(height.dp) - } + override fun widget(): Spacer<@Composable () -> Unit> = ComposeUiSpacer() override fun wrap(widget: Widget<@Composable () -> Unit>, horizontal: Boolean) = @Composable { if (horizontal) { diff --git a/redwood-layout-shared-test/build.gradle b/redwood-layout-shared-test/build.gradle index 351325c661..98fd9881bc 100644 --- a/redwood-layout-shared-test/build.gradle +++ b/redwood-layout-shared-test/build.gradle @@ -1,16 +1,12 @@ -apply plugin: 'com.android.library' -apply plugin: 'org.jetbrains.kotlin.android' +apply plugin: 'org.jetbrains.kotlin.jvm' dependencies { api projects.redwoodLayoutApi api projects.redwoodLayoutModifiers + api projects.redwoodLayoutWidget api projects.redwoodRuntime api projects.redwoodWidget api projects.redwoodYoga api libs.junit api libs.testParameterInjector } - -android { - namespace 'app.cash.redwood.redwoodlayoutsharedtest' -} diff --git a/redwood-layout-shared-test/src/main/kotlin/app/cash/redwood/layout/AbstractFlexContainerTest.kt b/redwood-layout-shared-test/src/main/kotlin/app/cash/redwood/layout/AbstractFlexContainerTest.kt index 42f536d037..2c93cbe90d 100644 --- a/redwood-layout-shared-test/src/main/kotlin/app/cash/redwood/layout/AbstractFlexContainerTest.kt +++ b/redwood-layout-shared-test/src/main/kotlin/app/cash/redwood/layout/AbstractFlexContainerTest.kt @@ -37,9 +37,14 @@ import org.junit.Test @Suppress("JUnitMalformedDeclaration") abstract class AbstractFlexContainerTest { abstract fun flexContainer(direction: FlexDirection): TestFlexContainer - abstract fun widget(text: String, modifier: Modifier = Modifier): Text + abstract fun widget(): Text abstract fun verifySnapshot(container: TestFlexContainer, name: String? = null) + private fun widget(text: String, modifier: Modifier = Modifier): Text = widget().apply { + text(text) + this.modifier = modifier + } + @Test fun emptyLayout( @TestParameter flexDirectionEnum: FlexDirectionEnum, ) { diff --git a/redwood-layout-shared-test/src/main/kotlin/app/cash/redwood/layout/AbstractSpacerTest.kt b/redwood-layout-shared-test/src/main/kotlin/app/cash/redwood/layout/AbstractSpacerTest.kt index 78bbcfc279..66b1628433 100644 --- a/redwood-layout-shared-test/src/main/kotlin/app/cash/redwood/layout/AbstractSpacerTest.kt +++ b/redwood-layout-shared-test/src/main/kotlin/app/cash/redwood/layout/AbstractSpacerTest.kt @@ -15,22 +15,24 @@ */ package app.cash.redwood.layout -import app.cash.redwood.Modifier +import app.cash.redwood.layout.widget.Spacer +import app.cash.redwood.ui.dp import app.cash.redwood.widget.Widget import org.junit.Test abstract class AbstractSpacerTest { - abstract fun widget( - width: Int = 0, - height: Int = 0, - modifier: Modifier = Modifier, - ): Widget + abstract fun widget(): Spacer abstract fun wrap(widget: Widget, horizontal: Boolean): T abstract fun verifySnapshot(value: T) + private fun widget(width: Int, height: Int): Spacer = widget().apply { + width(width.dp) + height(height.dp) + } + @Test fun zeroSpacer() { val widget = widget(width = 0, height = 0) verifySnapshot(wrap(widget, horizontal = true)) diff --git a/redwood-layout-view/src/test/kotlin/app/cash/redwood/layout/view/ViewFlexContainerTest.kt b/redwood-layout-view/src/test/kotlin/app/cash/redwood/layout/view/ViewFlexContainerTest.kt index d7c796e266..42be330380 100644 --- a/redwood-layout-view/src/test/kotlin/app/cash/redwood/layout/view/ViewFlexContainerTest.kt +++ b/redwood-layout-view/src/test/kotlin/app/cash/redwood/layout/view/ViewFlexContainerTest.kt @@ -51,16 +51,15 @@ class ViewFlexContainerTest( return ViewTestFlexContainer(paparazzi.context, direction) } - override fun widget(text: String, modifier: Modifier) = object : Text { + override fun widget() = object : Text { override val value = TextView(paparazzi.context).apply { background = ColorDrawable(Color.GREEN) textSize = 18f textDirection = View.TEXT_DIRECTION_LOCALE setTextColor(Color.BLACK) - this.text = text } - override var modifier = modifier + override var modifier: Modifier = Modifier override fun text(text: String) { value.text = text diff --git a/redwood-layout-view/src/test/kotlin/app/cash/redwood/layout/view/ViewSpacerTest.kt b/redwood-layout-view/src/test/kotlin/app/cash/redwood/layout/view/ViewSpacerTest.kt index 49c7b2b4e6..a33725ccbd 100644 --- a/redwood-layout-view/src/test/kotlin/app/cash/redwood/layout/view/ViewSpacerTest.kt +++ b/redwood-layout-view/src/test/kotlin/app/cash/redwood/layout/view/ViewSpacerTest.kt @@ -22,10 +22,8 @@ import android.widget.LinearLayout.VERTICAL import android.widget.TextView import app.cash.paparazzi.DeviceConfig import app.cash.paparazzi.Paparazzi -import app.cash.redwood.Modifier import app.cash.redwood.layout.AbstractSpacerTest import app.cash.redwood.layout.widget.Spacer -import app.cash.redwood.ui.dp import app.cash.redwood.widget.Widget import com.android.ide.common.rendering.api.SessionParams import org.junit.Rule @@ -42,15 +40,7 @@ class ViewSpacerTest : AbstractSpacerTest() { renderingMode = SessionParams.RenderingMode.SHRINK, ) - override fun widget( - width: Int, - height: Int, - modifier: Modifier, - ): Spacer = ViewSpacer(paparazzi.context).apply { - this.modifier = modifier - width(width.dp) - height(height.dp) - } + override fun widget(): Spacer = ViewSpacer(paparazzi.context) override fun wrap(widget: Widget, horizontal: Boolean): View { return LinearLayout(paparazzi.context).apply { diff --git a/redwood-lazylayout-composeui/src/androidUnitTest/kotlin/app/cash/redwood/layout/composeui/ComposeUiLazyListTest.kt b/redwood-lazylayout-composeui/src/androidUnitTest/kotlin/app/cash/redwood/layout/composeui/ComposeUiLazyListTest.kt index c3c7500a0c..6f44ddcef8 100644 --- a/redwood-lazylayout-composeui/src/androidUnitTest/kotlin/app/cash/redwood/layout/composeui/ComposeUiLazyListTest.kt +++ b/redwood-lazylayout-composeui/src/androidUnitTest/kotlin/app/cash/redwood/layout/composeui/ComposeUiLazyListTest.kt @@ -56,8 +56,8 @@ class ComposeUiLazyListTest( override fun flexContainer(direction: FlexDirection) = ComposeTestFlexContainer(direction) - override fun widget(text: String, modifier: RedwoodModifier) = object : Text<@Composable () -> Unit> { - private var text by mutableStateOf(text) + override fun widget() = object : Text<@Composable () -> Unit> { + private var text by mutableStateOf("") override val value = @Composable { BasicText( @@ -67,7 +67,7 @@ class ComposeUiLazyListTest( ) } - override var modifier = modifier + override var modifier: RedwoodModifier = RedwoodModifier override fun text(text: String) { this.text = text diff --git a/redwood-lazylayout-view/src/test/kotlin/app/cash/redwood/lazylayout/view/ViewLazyListTest.kt b/redwood-lazylayout-view/src/test/kotlin/app/cash/redwood/lazylayout/view/ViewLazyListTest.kt index 9a7be4db40..708f512b33 100644 --- a/redwood-lazylayout-view/src/test/kotlin/app/cash/redwood/lazylayout/view/ViewLazyListTest.kt +++ b/redwood-lazylayout-view/src/test/kotlin/app/cash/redwood/lazylayout/view/ViewLazyListTest.kt @@ -50,15 +50,14 @@ class ViewLazyListTest( override fun flexContainer(direction: FlexDirection) = ViewTestFlexContainer(paparazzi.context, direction) - override fun widget(text: String, modifier: Modifier) = object : Text { + override fun widget() = object : Text { override val value = TextView(paparazzi.context).apply { background = ColorDrawable(Color.GREEN) textSize = 18f setTextColor(Color.BLACK) - this.text = text } - override var modifier = modifier + override var modifier: Modifier = Modifier override fun text(text: String) { value.text = text