Skip to content

Commit

Permalink
Test layout content changes
Browse files Browse the repository at this point in the history
We were missing tests for items being removed from
Column, etc.
  • Loading branch information
squarejesse committed Nov 17, 2023
1 parent f40b384 commit 924ed65
Show file tree
Hide file tree
Showing 30 changed files with 153 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package app.cash.redwood.layout.composeui

import app.cash.redwood.Modifier as RedwoodModifier
import androidx.compose.foundation.background
import androidx.compose.foundation.text.BasicText
import androidx.compose.runtime.Composable
Expand All @@ -27,7 +28,6 @@ import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.sp
import app.cash.paparazzi.DeviceConfig
import app.cash.paparazzi.Paparazzi
import app.cash.redwood.Modifier as RedwoodModifier
import app.cash.redwood.layout.AbstractFlexContainerTest
import app.cash.redwood.layout.TestFlexContainer
import app.cash.redwood.layout.Text
Expand Down Expand Up @@ -90,7 +90,17 @@ class ComposeUiFlexContainerTest(
)

override fun add(widget: Widget<@Composable () -> Unit>) {
delegate.children.insert(childCount++, widget)
addAt(childCount, widget)
}

override fun addAt(index: Int, widget: Widget<() -> Unit>) {
delegate.children.insert(index, widget)
childCount++
}

override fun removeAt(index: Int) {
delegate.children.remove(index = index, count = 1)
childCount--
}

override fun onEndChanges() {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,28 @@ abstract class AbstractFlexContainerTest<T : Any> {
verifySnapshot(column)
}

@Test
fun testDynamicElementUpdates() {
val container = flexContainer(FlexDirection.Column)
container.width(Constraint.Fill)
container.height(Constraint.Fill)
container.add(widget("A"))
container.add(widget("B"))
container.add(widget("D"))
container.add(widget("E"))

container.onEndChanges()
verifySnapshot(container, "ABDE")

container.addAt(index = 2, widget = widget("C"))
container.onEndChanges()
verifySnapshot(container, "ABCDE")

container.removeAt(index = 0)
container.onEndChanges()
verifySnapshot(container, "BCDE")
}

/** We don't have assume() on kotlin.test. Tests that fail here should be skipped instead. */
private fun assumeTrue(b: Boolean) {
assertTrue(b)
Expand All @@ -429,6 +451,8 @@ interface TestFlexContainer<T : Any> : Widget<T>, ChangeListener {
fun mainAxisAlignment(mainAxisAlignment: MainAxisAlignment)
fun margin(margin: Margin)
fun add(widget: Widget<T>)
fun addAt(index: Int, widget: Widget<T>)
fun removeAt(index: Int)
}

interface Text<T : Any> : Widget<T> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,17 @@ class UIViewFlexContainerTest(
}

override fun add(widget: Widget<UIView>) {
delegate.children.insert(childCount++, widget)
addAt(childCount, widget)
}

override fun addAt(index: Int, widget: Widget<UIView>) {
delegate.children.insert(index, widget)
childCount++
}

override fun removeAt(index: Int) {
delegate.children.remove(index = index, count = 1)
childCount--
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,17 @@ class ViewFlexContainerTest(
)

override fun add(widget: Widget<View>) {
delegate.children.insert(childCount++, widget)
addAt(childCount, widget)
}

override fun addAt(index: Int, widget: Widget<View>) {
delegate.children.insert(index, widget)
childCount++
}

override fun removeAt(index: Int) {
delegate.children.remove(index = index, count = 1)
childCount--
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package app.cash.redwood.layout.composeui

import app.cash.redwood.Modifier as RedwoodModifier
import androidx.compose.foundation.background
import androidx.compose.foundation.text.BasicText
import androidx.compose.runtime.Composable
Expand All @@ -27,7 +28,6 @@ import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.sp
import app.cash.paparazzi.DeviceConfig
import app.cash.paparazzi.Paparazzi
import app.cash.redwood.Modifier as RedwoodModifier
import app.cash.redwood.layout.AbstractFlexContainerTest
import app.cash.redwood.layout.TestFlexContainer
import app.cash.redwood.layout.Text
Expand Down Expand Up @@ -96,7 +96,17 @@ class ComposeUiLazyListTest(
}

override fun add(widget: Widget<@Composable () -> Unit>) {
delegate.items.insert(childCount++, widget)
addAt(childCount, widget)
}

override fun addAt(index: Int, widget: Widget<() -> Unit>) {
delegate.items.insert(index, widget)
childCount++
}

override fun removeAt(index: Int) {
delegate.items.remove(index = index, count = 1)
childCount--
}

override fun onEndChanges() {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,17 @@ class ViewLazyListTest(
}

override fun add(widget: Widget<View>) {
delegate.items.insert(childCount++, widget)
addAt(childCount, widget)
}

override fun addAt(index: Int, widget: Widget<View>) {
delegate.items.insert(index, widget)
childCount++
}

override fun removeAt(index: Int) {
delegate.items.remove(index = index, count = 1)
childCount--
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 924ed65

Please sign in to comment.