Skip to content

Commit

Permalink
Snapshot test for RedwoodView (#2331)
Browse files Browse the repository at this point in the history
* Snapshot test for RedwoodView

Closes: #1859

* Actually exercise the interesting bit from the bug report

* Track rebase
  • Loading branch information
squarejesse authored Sep 26, 2024
1 parent fa38c71 commit 616e91c
Show file tree
Hide file tree
Showing 19 changed files with 856 additions and 0 deletions.
31 changes: 31 additions & 0 deletions redwood-widget-shared-test/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import static app.cash.redwood.buildsupport.TargetGroup.ToolkitAllWithoutAndroid

redwoodBuild {
targets(ToolkitAllWithoutAndroid)
}

kotlin {
sourceSets {
commonMain {
dependencies {
api projects.redwoodLayoutApi
api projects.redwoodLayoutModifiers
api projects.redwoodLayoutWidget
api projects.redwoodRuntime
api projects.redwoodSnapshotTesting
api projects.redwoodTesting
api projects.redwoodWidget
api projects.redwoodYoga
api libs.kotlin.test
}
}
jvmMain {
dependencies {
// The kotlin.test library provides JVM variants for multiple testing frameworks. When used
// as a test dependency this selection is transparent. But since we are publishing a library
// we need to select one ourselves at compilation time.
api libs.kotlin.test.junit
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (C) 2024 Square, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package app.cash.redwood.widget

import app.cash.redwood.snapshot.testing.Snapshotter
import app.cash.redwood.snapshot.testing.TestWidgetFactory
import app.cash.redwood.snapshot.testing.text
import kotlin.test.Test

abstract class AbstractRedwoodViewTest<W : Any, R : RedwoodView<W>> {

abstract val widgetFactory: TestWidgetFactory<W>

abstract fun redwoodView(): R

abstract fun snapshotter(redwoodView: R): Snapshotter

/**
* This test uses a string that wraps to confirm the root view's dimensions aren't unbounded.
* https://github.com/cashapp/redwood/issues/2128
*/
@Test
fun testSingleChildElement() {
val redwoodView = redwoodView()
redwoodView.children.insert(0, widgetFactory.text("Hello ".repeat(50)))
snapshotter(redwoodView).snapshot()
}
}
Loading

0 comments on commit 616e91c

Please sign in to comment.