Skip to content

Commit 0739d0a

Browse files
Start using Burst's TestInterceptor in snapshot tests (#2784)
* Start using Burst's TestInterceptor in snapshot tests * Unframed --------- Co-authored-by: Jesse Wilson <jesse@swank.ca>
1 parent c4fcc63 commit 0739d0a

File tree

29 files changed

+179
-155
lines changed

29 files changed

+179
-155
lines changed

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ paparazzi = "1.3.2"
1111
zipline = "1.22.0"
1212
coil = "3.3.0"
1313
okio = "3.16.0"
14-
burst = "2.7.0"
14+
burst = "2.7.1"
1515

1616
[libraries]
1717
kotlin-compiler = { module = "org.jetbrains.kotlin:kotlin-compiler", version.ref = "kotlin" }

redwood-layout-composeui/src/androidUnitTest/kotlin/app/cash/redwood/layout/composeui/ComposeUiBoxTest.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,10 @@ class ComposeUiBoxTest(
3838
theme = "android:Theme.Material.Light.NoActionBar",
3939
supportsRtl = true,
4040
)
41+
override val snapshotterFactory = ComposeSnapshotter.Factory(paparazzi)
4142

4243
override val widgetFactory = ComposeUiTestWidgetFactory
4344

4445
override fun box(): Box<@Composable (Modifier) -> Unit> = ComposeUiBox(0x88000000.toInt())
4546
.apply { applyDefaults() }
46-
47-
override fun snapshotter(widget: @Composable (Modifier) -> Unit) = ComposeSnapshotter(paparazzi, widget)
4847
}

redwood-layout-composeui/src/androidUnitTest/kotlin/app/cash/redwood/layout/composeui/ComposeUiFlexContainerTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ class ComposeUiFlexContainerTest(
5252
supportsRtl = true,
5353
)
5454

55+
override val snapshotterFactory = ComposeSnapshotter.Factory(paparazzi)
56+
5557
override fun flexContainer(
5658
direction: FlexDirection,
5759
backgroundColor: Int,
@@ -78,8 +80,6 @@ class ComposeUiFlexContainerTest(
7880
}
7981
}
8082

81-
override fun snapshotter(widget: @Composable (Modifier) -> Unit) = ComposeSnapshotter(paparazzi, widget)
82-
8383
class ComposeTestFlexContainer private constructor(
8484
private val delegate: ComposeUiFlexContainer,
8585
) : TestFlexContainer<@Composable (Modifier) -> Unit>,

redwood-layout-composeui/src/androidUnitTest/kotlin/app/cash/redwood/layout/composeui/ComposeUiSpacerTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ class ComposeUiSpacerTest : AbstractSpacerTest<@Composable (Modifier) -> Unit>()
4141
renderingMode = SessionParams.RenderingMode.SHRINK,
4242
)
4343

44+
override val snapshotterFactory = ComposeSnapshotter.Factory(paparazzi)
45+
4446
override fun widget(): Spacer<@Composable (Modifier) -> Unit> = ComposeUiSpacer()
4547

4648
override fun wrap(
@@ -61,6 +63,4 @@ class ComposeUiSpacerTest : AbstractSpacerTest<@Composable (Modifier) -> Unit>()
6163
}
6264
}
6365
}
64-
65-
override fun snapshotter(widget: @Composable (Modifier) -> Unit) = ComposeSnapshotter(paparazzi, widget)
6666
}

redwood-layout-shared-test/src/commonMain/kotlin/app/cash/redwood/layout/AbstractBoxTest.kt

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package app.cash.redwood.layout
1717

1818
import app.cash.burst.Burst
19+
import app.cash.burst.InterceptTest
1920
import app.cash.burst.burstValues
2021
import app.cash.redwood.Modifier
2122
import app.cash.redwood.layout.api.Constraint
@@ -36,6 +37,9 @@ import kotlin.test.Test
3637
@Burst
3738
abstract class AbstractBoxTest<T : Any> {
3839

40+
@InterceptTest
41+
abstract val snapshotterFactory: Snapshotter.Factory<T>
42+
3943
abstract val widgetFactory: TestWidgetFactory<T>
4044

4145
abstract fun box(): Box<T>
@@ -52,12 +56,10 @@ abstract class AbstractBoxTest<T : Any> {
5256
verticalAlignment(CrossAxisAlignment.Start)
5357
}
5458

55-
abstract fun snapshotter(widget: T): Snapshotter
56-
5759
@Test
5860
fun testEmpty_Defaults() {
5961
val widget = box()
60-
snapshotter(widget.value).snapshot()
62+
snapshotterFactory(widget.value).snapshot()
6163
}
6264

6365
@Test
@@ -66,7 +68,7 @@ abstract class AbstractBoxTest<T : Any> {
6668
width(Constraint.Wrap)
6769
height(Constraint.Wrap)
6870
}
69-
snapshotter(widget.value).snapshot()
71+
snapshotterFactory(widget.value).snapshot()
7072
}
7173

7274
@Test
@@ -75,7 +77,7 @@ abstract class AbstractBoxTest<T : Any> {
7577
width(Constraint.Fill)
7678
height(Constraint.Fill)
7779
}
78-
snapshotter(widget.value).snapshot()
80+
snapshotterFactory(widget.value).snapshot()
7981
}
8082

8183
@Test
@@ -124,7 +126,7 @@ abstract class AbstractBoxTest<T : Any> {
124126
),
125127
)
126128
}
127-
snapshotter(widget.value).snapshot()
129+
snapshotterFactory(widget.value).snapshot()
128130
}
129131

130132
@Test
@@ -150,7 +152,7 @@ abstract class AbstractBoxTest<T : Any> {
150152
),
151153
)
152154
}
153-
snapshotter(widget.value).snapshot()
155+
snapshotterFactory(widget.value).snapshot()
154156
}
155157

156158
@Test
@@ -193,7 +195,7 @@ abstract class AbstractBoxTest<T : Any> {
193195

194196
val scrollWrapper = widgetFactory.scrollWrapper()
195197
scrollWrapper.content = container.value
196-
snapshotter(scrollWrapper.value).snapshot()
198+
snapshotterFactory(scrollWrapper.value).snapshot()
197199
}
198200

199201
@Test
@@ -236,7 +238,7 @@ abstract class AbstractBoxTest<T : Any> {
236238
),
237239
)
238240
}
239-
snapshotter(widget.value).snapshot()
241+
snapshotterFactory(widget.value).snapshot()
240242
}
241243

242244
@Test
@@ -279,7 +281,7 @@ abstract class AbstractBoxTest<T : Any> {
279281
),
280282
)
281283
}
282-
snapshotter(widget.value).snapshot()
284+
snapshotterFactory(widget.value).snapshot()
283285
}
284286

285287
@Test
@@ -308,7 +310,7 @@ abstract class AbstractBoxTest<T : Any> {
308310
),
309311
)
310312
}
311-
val snapshotter = snapshotter(widget.value)
313+
val snapshotter = snapshotterFactory(widget.value)
312314
snapshotter.snapshot("Margin")
313315
redColor.modifier = Modifier
314316
widget.children.onModifierUpdated(0, redColor)
@@ -324,7 +326,7 @@ abstract class AbstractBoxTest<T : Any> {
324326
horizontalAlignment(CrossAxisAlignment.Start)
325327
verticalAlignment(CrossAxisAlignment.Start)
326328
}
327-
val snapshotter = snapshotter(widget.value)
329+
val snapshotter = snapshotterFactory(widget.value)
328330

329331
// Render before calling detach().
330332
widget.children.insert(
@@ -367,7 +369,7 @@ abstract class AbstractBoxTest<T : Any> {
367369
horizontalAlignment(CrossAxisAlignment.Start)
368370
verticalAlignment(CrossAxisAlignment.Start)
369371
}
370-
val snapshotter = snapshotter(container.value)
372+
val snapshotter = snapshotterFactory(container.value)
371373

372374
val a = widgetFactory.text(
373375
modifier = HorizontalAlignmentImpl(CrossAxisAlignment.Start),
@@ -393,7 +395,7 @@ abstract class AbstractBoxTest<T : Any> {
393395
@Test
394396
fun testLayoutUpdatesWithoutSizeChanges() {
395397
val container = widgetFactory.column()
396-
val snapshotter = snapshotter(container.value)
398+
val snapshotter = snapshotterFactory(container.value)
397399

398400
val box = box()
399401
.apply {
@@ -427,7 +429,7 @@ abstract class AbstractBoxTest<T : Any> {
427429
horizontalAlignment(CrossAxisAlignment.Stretch)
428430
verticalAlignment(CrossAxisAlignment.Center)
429431
}
430-
val snapshotter = snapshotter(container.value)
432+
val snapshotter = snapshotterFactory(container.value)
431433

432434
val box = box()
433435
.apply {
@@ -459,7 +461,7 @@ abstract class AbstractBoxTest<T : Any> {
459461
horizontalAlignment(CrossAxisAlignment.Center)
460462
verticalAlignment(CrossAxisAlignment.Stretch)
461463
}
462-
val snapshotter = snapshotter(container.value)
464+
val snapshotter = snapshotterFactory(container.value)
463465

464466
val box = box()
465467
.apply {
@@ -492,7 +494,7 @@ abstract class AbstractBoxTest<T : Any> {
492494
horizontalAlignment(CrossAxisAlignment.Start)
493495
verticalAlignment(CrossAxisAlignment.Start)
494496
}
495-
val snapshotter = snapshotter(container.value)
497+
val snapshotter = snapshotterFactory(container.value)
496498

497499
val box = box()
498500
.apply {

0 commit comments

Comments
 (0)