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

Adopt Burst in Redwood #2388

Merged
merged 3 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ buildscript {
classpath libs.kotlin.serializationPlugin
classpath libs.atomicFuPlugin
classpath libs.buildConfigPlugin
classpath libs.burst.gradle.plugin
classpath libs.zipline.gradlePlugin
classpath libs.paparazzi.gradlePlugin
classpath libs.poko.gradlePlugin
Expand Down
4 changes: 3 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ paparazzi = "1.3.2"
zipline = "1.17.0"
coil = "3.0.0-rc01"
okio = "3.9.1"
burst = "0.4.0"

[libraries]
kotlin-compiler = { module = "org.jetbrains.kotlin:kotlin-compiler", version.ref = "kotlin" }
Expand Down Expand Up @@ -69,10 +70,11 @@ jetbrains-compose-ui-tooling = { module = "org.jetbrains.compose.ui:ui-tooling",
jetbrains-compose-ui-tooling-preview = { module = "org.jetbrains.compose.ui:ui-tooling-preview", version.ref = "jbCompose" }

androidGradlePlugin = { module = "com.android.tools.build:gradle", version = "8.7.1" }
burst = { module = "app.cash.burst:burst", version.ref = "burst" }
burst-gradle-plugin = { module = "app.cash.burst:burst-gradle-plugin", version.ref = "burst" }
kotlinPoet = { module = "com.squareup:kotlinpoet", version = "1.18.1" }
clikt = "com.github.ajalt.clikt:clikt:5.0.1"
junit = { module = "junit:junit", version = "4.13.2" }
testParameterInjector = { module = "com.google.testparameterinjector:test-parameter-injector", version = "1.18" }
assertk = "com.willowtreeapps.assertk:assertk:0.28.1"
robolectric = { module = "org.robolectric:robolectric", version = "4.13" }
okio = { module = "com.squareup.okio:okio", version.ref = "okio" }
Expand Down
1 change: 1 addition & 0 deletions redwood-compose/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ redwoodBuild {
}

apply plugin: 'org.jetbrains.kotlin.plugin.compose'
apply plugin: 'app.cash.burst'

kotlin {
applyDefaultHierarchyTemplate {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ package app.cash.redwood.compose
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import app.cash.burst.Burst
import app.cash.redwood.Modifier
import app.cash.redwood.RedwoodCodegenApi
import app.cash.redwood.layout.testing.RedwoodLayoutTestingWidgetFactory
import app.cash.redwood.lazylayout.testing.RedwoodLazyLayoutTestingWidgetFactory
import app.cash.redwood.leaks.LeakDetector
Expand Down Expand Up @@ -47,44 +47,65 @@ import kotlin.test.Test
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.test.runTest

class DirectChangeListenerTest : AbstractChangeListenerTest() {
override fun <T> CoroutineScope.launchComposition(
widgetSystem: TestSchemaWidgetSystem<WidgetValue>,
snapshot: () -> T,
) = TestRedwoodComposition(this, widgetSystem, MutableListChildren(), createSnapshot = snapshot)
}

class ProtocolChangeListenerTest : AbstractChangeListenerTest() {
override fun <T> CoroutineScope.launchComposition(
widgetSystem: TestSchemaWidgetSystem<WidgetValue>,
snapshot: () -> T,
): TestRedwoodComposition<T> {
val guestAdapter = DefaultGuestProtocolAdapter(
hostVersion = hostRedwoodVersion,
widgetSystemFactory = TestSchemaProtocolWidgetSystemFactory,
)
val hostAdapter = HostProtocolAdapter(
guestVersion = guestRedwoodVersion,
enum class ComposeLauncher {
Direct {
override fun <T> launchComposition(
scope: CoroutineScope,
widgetSystem: TestSchemaWidgetSystem<WidgetValue>,
snapshot: () -> T,
) = TestRedwoodComposition(
scope = scope,
widgetSystem = widgetSystem,
container = MutableListChildren(),
factory = TestSchemaProtocolFactory(widgetSystem),
eventSink = { throw AssertionError() },
leakDetector = LeakDetector.none(),
createSnapshot = snapshot,
)
guestAdapter.initChangesSink(hostAdapter)
return TestRedwoodComposition(this, guestAdapter.widgetSystem, guestAdapter.root) {
guestAdapter.emitChanges()
snapshot()
},

Protocol {
override fun <T> launchComposition(
scope: CoroutineScope,
widgetSystem: TestSchemaWidgetSystem<WidgetValue>,
snapshot: () -> T,
): TestRedwoodComposition<T> {
val guestAdapter = DefaultGuestProtocolAdapter(
hostVersion = hostRedwoodVersion,
widgetSystemFactory = TestSchemaProtocolWidgetSystemFactory,
)
val hostAdapter = HostProtocolAdapter(
guestVersion = guestRedwoodVersion,
container = MutableListChildren(),
factory = TestSchemaProtocolFactory(widgetSystem),
eventSink = { throw AssertionError() },
leakDetector = LeakDetector.none(),
)
guestAdapter.initChangesSink(hostAdapter)
return TestRedwoodComposition(
scope = scope,
widgetSystem = guestAdapter.widgetSystem,
container = guestAdapter.root,
) {
guestAdapter.emitChanges()
snapshot()
}
}
}
}
},
;

@OptIn(RedwoodCodegenApi::class)
abstract class AbstractChangeListenerTest {
// There is no test parameter injector in multiplatform, so we fake it with subtypes.
abstract fun <T> CoroutineScope.launchComposition(
abstract fun <T> launchComposition(
scope: CoroutineScope,
widgetSystem: TestSchemaWidgetSystem<WidgetValue>,
snapshot: () -> T,
): TestRedwoodComposition<T>
}

@Burst
class ChangeListenerTest(
private val launcher: ComposeLauncher,
) {
private fun <T> CoroutineScope.launchComposition(
widgetSystem: TestSchemaWidgetSystem<WidgetValue>,
snapshot: () -> T,
): TestRedwoodComposition<T> = launcher.launchComposition(this, widgetSystem, snapshot)

@Test
fun propertyChangeNotifiesWidget() = runTest {
Expand Down
1 change: 0 additions & 1 deletion redwood-gradle-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ dependencies {
compileOnly libs.androidGradlePlugin

testImplementation libs.junit
testImplementation libs.testParameterInjector
testImplementation libs.assertk
testImplementation gradleTestKit()

Expand Down
2 changes: 1 addition & 1 deletion redwood-layout-composeui/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ redwoodBuild {

apply plugin: 'org.jetbrains.kotlin.plugin.compose'
apply plugin: 'org.jetbrains.kotlin.plugin.serialization'
apply plugin: 'app.cash.burst'
apply plugin: 'app.cash.paparazzi'

kotlin {
Expand All @@ -25,7 +26,6 @@ kotlin {
dependencies {
implementation projects.redwoodLayoutSharedTest
implementation projects.redwoodSnapshotTesting
implementation libs.testParameterInjector
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,19 @@
package app.cash.redwood.layout.composeui

import androidx.compose.runtime.Composable
import app.cash.burst.Burst
import app.cash.paparazzi.DeviceConfig
import app.cash.paparazzi.Paparazzi
import app.cash.redwood.layout.AbstractBoxTest
import app.cash.redwood.layout.widget.Box
import app.cash.redwood.snapshot.testing.ComposeSnapshotter
import app.cash.redwood.snapshot.testing.ComposeUiTestWidgetFactory
import com.android.resources.LayoutDirection
import com.google.testing.junit.testparameterinjector.TestParameter
import com.google.testing.junit.testparameterinjector.TestParameterInjector
import org.junit.Rule
import org.junit.runner.RunWith

@RunWith(TestParameterInjector::class)
@Burst
class ComposeUiBoxTest(
@TestParameter layoutDirection: LayoutDirection,
layoutDirection: LayoutDirection,
) : AbstractBoxTest<@Composable () -> Unit>() {

@get:Rule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import androidx.compose.foundation.background
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import app.cash.burst.Burst
import app.cash.paparazzi.DeviceConfig
import app.cash.paparazzi.Paparazzi
import app.cash.redwood.layout.AbstractFlexContainerTest
Expand All @@ -32,15 +33,12 @@ import app.cash.redwood.widget.Widget
import app.cash.redwood.widget.compose.ComposeWidgetChildren
import app.cash.redwood.yoga.FlexDirection
import com.android.resources.LayoutDirection
import com.google.testing.junit.testparameterinjector.TestParameter
import com.google.testing.junit.testparameterinjector.TestParameterInjector
import kotlinx.coroutines.runBlocking
import org.junit.Rule
import org.junit.runner.RunWith

@RunWith(TestParameterInjector::class)
@Burst
class ComposeUiFlexContainerTest(
@TestParameter layoutDirection: LayoutDirection,
layoutDirection: LayoutDirection,
) : AbstractFlexContainerTest<@Composable () -> Unit>() {

override val widgetFactory = ComposeUiTestWidgetFactory
Expand Down
3 changes: 2 additions & 1 deletion redwood-layout-view/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ redwoodBuild {
}

apply plugin: 'org.jetbrains.kotlin.plugin.serialization'
apply plugin: 'app.cash.burst'
apply plugin: 'app.cash.paparazzi'

dependencies {
api projects.redwoodLayoutWidget
implementation projects.redwoodYoga
implementation libs.androidx.core
testImplementation libs.burst
testImplementation projects.redwoodLayoutSharedTest
testImplementation projects.redwoodSnapshotTesting
testImplementation libs.testParameterInjector
}

android {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package app.cash.redwood.layout.view
import android.graphics.drawable.ColorDrawable
import android.view.View
import android.widget.FrameLayout
import app.cash.burst.Burst
import app.cash.paparazzi.DeviceConfig
import app.cash.paparazzi.Paparazzi
import app.cash.redwood.layout.AbstractBoxTest
Expand All @@ -26,14 +27,11 @@ import app.cash.redwood.snapshot.testing.Snapshotter
import app.cash.redwood.snapshot.testing.ViewSnapshotter
import app.cash.redwood.snapshot.testing.ViewTestWidgetFactory
import com.android.resources.LayoutDirection
import com.google.testing.junit.testparameterinjector.TestParameter
import com.google.testing.junit.testparameterinjector.TestParameterInjector
import org.junit.Rule
import org.junit.runner.RunWith

@RunWith(TestParameterInjector::class)
@Burst
class ViewBoxTest(
@TestParameter layoutDirection: LayoutDirection,
layoutDirection: LayoutDirection,
) : AbstractBoxTest<View>() {

@get:Rule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package app.cash.redwood.layout.view

import android.view.View
import app.cash.burst.Burst
import app.cash.paparazzi.DeviceConfig
import app.cash.paparazzi.Paparazzi
import app.cash.redwood.layout.AbstractFlexContainerTest
Expand All @@ -30,14 +31,11 @@ import app.cash.redwood.widget.ViewGroupChildren
import app.cash.redwood.widget.Widget
import app.cash.redwood.yoga.FlexDirection
import com.android.resources.LayoutDirection
import com.google.testing.junit.testparameterinjector.TestParameter
import com.google.testing.junit.testparameterinjector.TestParameterInjector
import org.junit.Rule
import org.junit.runner.RunWith

@RunWith(TestParameterInjector::class)
@Burst
class ViewFlexContainerTest(
@TestParameter layoutDirection: LayoutDirection,
layoutDirection: LayoutDirection,
) : AbstractFlexContainerTest<View>() {

@get:Rule
Expand Down
Loading
Loading