@@ -33,6 +33,7 @@ import app.cash.redwood.snapshot.testing.text
33
33
import app.cash.redwood.ui.Margin
34
34
import app.cash.redwood.ui.dp
35
35
import kotlin.test.Test
36
+ import kotlinx.coroutines.test.runTest
36
37
37
38
@Burst
38
39
abstract class AbstractBoxTest <T : Any > {
@@ -48,7 +49,7 @@ abstract class AbstractBoxTest<T : Any> {
48
49
* Explicitly apply defaults to our Box instance. This is only necessary in tests; in production
49
50
* the framework explicitly sets every property.
50
51
*/
51
- protected fun Box<T>.applyDefaults () {
52
+ protected fun Box<T>.applyDefaults () = runTest {
52
53
width(Constraint .Wrap )
53
54
height(Constraint .Wrap )
54
55
margin(Margin .Zero )
@@ -57,13 +58,13 @@ abstract class AbstractBoxTest<T : Any> {
57
58
}
58
59
59
60
@Test
60
- fun testEmpty_Defaults () {
61
+ fun testEmpty_Defaults () = runTest {
61
62
val widget = box()
62
63
snapshotterFactory(widget.value).snapshot()
63
64
}
64
65
65
66
@Test
66
- fun testEmpty_Wrap () {
67
+ fun testEmpty_Wrap () = runTest {
67
68
val widget = box().apply {
68
69
width(Constraint .Wrap )
69
70
height(Constraint .Wrap )
@@ -72,7 +73,7 @@ abstract class AbstractBoxTest<T : Any> {
72
73
}
73
74
74
75
@Test
75
- fun testEmpty_Fill () {
76
+ fun testEmpty_Fill () = runTest {
76
77
val widget = box().apply {
77
78
width(Constraint .Fill )
78
79
height(Constraint .Fill )
@@ -98,7 +99,7 @@ abstract class AbstractBoxTest<T : Any> {
98
99
CrossAxisAlignment .End ,
99
100
CrossAxisAlignment .Stretch ,
100
101
),
101
- ) {
102
+ ) = runTest {
102
103
val widget = box().apply {
103
104
width(constraint)
104
105
height(constraint)
@@ -130,7 +131,7 @@ abstract class AbstractBoxTest<T : Any> {
130
131
}
131
132
132
133
@Test
133
- fun testMargins () {
134
+ fun testMargins () = runTest {
134
135
// Different margins allow us to know which direction start and end get applied.
135
136
val asymmetric = Margin (start = 10 .dp, top = 20 .dp, end = 30 .dp, bottom = 40 .dp)
136
137
@@ -156,7 +157,7 @@ abstract class AbstractBoxTest<T : Any> {
156
157
}
157
158
158
159
@Test
159
- fun testBoxMeasurementIncludesMargins () {
160
+ fun testBoxMeasurementIncludesMargins () = runTest {
160
161
val container = widgetFactory.column()
161
162
container.add(
162
163
box().apply {
@@ -199,7 +200,7 @@ abstract class AbstractBoxTest<T : Any> {
199
200
}
200
201
201
202
@Test
202
- fun testMarginsAndAlignment () {
203
+ fun testMarginsAndAlignment () = runTest {
203
204
val widget = box().apply {
204
205
width(Constraint .Fill )
205
206
height(Constraint .Fill )
@@ -242,7 +243,7 @@ abstract class AbstractBoxTest<T : Any> {
242
243
}
243
244
244
245
@Test
245
- fun testMarginsAndStretch () {
246
+ fun testMarginsAndStretch () = runTest {
246
247
val widget = box().apply {
247
248
width(Constraint .Fill )
248
249
height(Constraint .Fill )
@@ -285,7 +286,7 @@ abstract class AbstractBoxTest<T : Any> {
285
286
}
286
287
287
288
@Test
288
- fun testChildrenModifierChanges () {
289
+ fun testChildrenModifierChanges () = runTest {
289
290
val redColor = widgetFactory.text(
290
291
modifier = MarginImpl (30 .dp),
291
292
text = longText(),
@@ -319,7 +320,7 @@ abstract class AbstractBoxTest<T : Any> {
319
320
320
321
/* * The view shouldn't crash if its displayed after being detached. */
321
322
@Test
322
- fun testLayoutAfterDetach () {
323
+ fun testLayoutAfterDetach () = runTest {
323
324
val widget = box().apply {
324
325
width(Constraint .Wrap )
325
326
height(Constraint .Wrap )
@@ -361,7 +362,7 @@ abstract class AbstractBoxTest<T : Any> {
361
362
}
362
363
363
364
@Test
364
- fun testDynamicWidgetResizing () {
365
+ fun testDynamicWidgetResizing () = runTest {
365
366
val container = box()
366
367
.apply {
367
368
width(Constraint .Fill )
@@ -393,7 +394,7 @@ abstract class AbstractBoxTest<T : Any> {
393
394
}
394
395
395
396
@Test
396
- fun testLayoutUpdatesWithoutSizeChanges () {
397
+ fun testLayoutUpdatesWithoutSizeChanges () = runTest {
397
398
val container = widgetFactory.column()
398
399
val snapshotter = snapshotterFactory(container.value)
399
400
@@ -421,7 +422,7 @@ abstract class AbstractBoxTest<T : Any> {
421
422
}
422
423
423
424
@Test
424
- fun testChildExplicitHeight () {
425
+ fun testChildExplicitHeight () = runTest {
425
426
val container = box()
426
427
.apply {
427
428
width(Constraint .Fill )
@@ -453,7 +454,7 @@ abstract class AbstractBoxTest<T : Any> {
453
454
}
454
455
455
456
@Test
456
- fun testChildExplicitWidth () {
457
+ fun testChildExplicitWidth () = runTest {
457
458
val container = box()
458
459
.apply {
459
460
width(Constraint .Fill )
@@ -486,7 +487,7 @@ abstract class AbstractBoxTest<T : Any> {
486
487
487
488
/* * We had a bug where stretch alignment impacted measurement. It shouldn't. */
488
489
@Test
489
- fun testStretchDoesNotImpactMeasurement () {
490
+ fun testStretchDoesNotImpactMeasurement () = runTest {
490
491
val container = box()
491
492
.apply {
492
493
width(Constraint .Fill )
0 commit comments