Skip to content

Commit

Permalink
Apply Defaults explicitly
Browse files Browse the repository at this point in the history
  • Loading branch information
squarejesse committed Oct 22, 2024
1 parent 12420a5 commit 9b96641
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class ComposeUiBoxTest(
override val widgetFactory = ComposeUiTestWidgetFactory

override fun box(): Box<@Composable () -> Unit> = ComposeUiBox(0x88000000.toInt())
.apply { applyDefaults() }

override fun snapshotter(widget: @Composable () -> Unit) = ComposeSnapshotter(paparazzi, widget)
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ abstract class AbstractBoxTest<T : Any> {

abstract fun box(): Box<T>

/**
* Explicitly apply defaults to our Box instance. This is only necessary in tests; in production
* the framework explicitly sets every property.
*/
protected fun Box<T>.applyDefaults() {
width(Constraint.Wrap)
height(Constraint.Wrap)
margin(Margin.Zero)
horizontalAlignment(CrossAxisAlignment.Start)
verticalAlignment(CrossAxisAlignment.Start)
}

abstract fun snapshotter(widget: T): Snapshotter

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class UIViewBoxTest(
override fun box(): Box<UIView> {
return UIViewBox().apply {
value.backgroundColor = UIColor(red = 0.0, green = 0.0, blue = 0.0, alpha = 0.5)
applyDefaults()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class ViewBoxTest(
override fun box(): Box<View> {
return ViewBox(paparazzi.context).apply {
background = ColorDrawable(0x88000000.toInt())
applyDefaults()
}
}

Expand Down

0 comments on commit 9b96641

Please sign in to comment.