Skip to content

Commit

Permalink
Test layout content changes (#1687)
Browse files Browse the repository at this point in the history
* Test layout content changes

We were missing tests for items being removed from
Column, etc.

* Add iOS snapshots for the new test

* Spotless
  • Loading branch information
squarejesse authored Nov 17, 2023
1 parent f40b384 commit 59a6600
Show file tree
Hide file tree
Showing 34 changed files with 163 additions and 6 deletions.
Original file line number Diff line number Diff line change
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 @@ -12,6 +12,8 @@ final class SnapshotTestingCallback : UIViewSnapshotCallback {
}

func verifySnapshot(view: UIView, name: String?) {
assertSnapshot(of: view, as: .image, named: name, file: fileName, testName: testName)
// Set `record` to true to generate new snapshots. Be sure to revert that before committing!
// Note that tests always fail when `record` is true.
assertSnapshot(of: view, as: .image, named: name, record: false, file: fileName, testName: testName)
}
}
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 @@ -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 @@ -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.

0 comments on commit 59a6600

Please sign in to comment.