Skip to content

Commit

Permalink
Add UIKit screenshot tests for layout's Spacer
Browse files Browse the repository at this point in the history
This adds the start of a new setup for hosting Kotlin tests within an iOS project so that we can use a Swift screenshot testing library. For now you have to prefix your test functions with "test" and any before/after-annotated functions need to
be named "setUp" and "tearDown" (very JUnit 3). We also do not support anything JVM-specific like rules or parameterization for now.
  • Loading branch information
JakeWharton committed Sep 29, 2023
1 parent cda5a95 commit 3d4411e
Show file tree
Hide file tree
Showing 24 changed files with 667 additions and 32 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ jobs:
path: build/dokka/htmlMultiModule/
if-no-files-found: error

paparazzi:
runs-on: ubuntu-latest
screenshot-tests:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -91,6 +91,8 @@ jobs:

- run: ./gradlew verifyPaparazziDebug

- run: xcodebuild -project redwood-layout-uiview/RedwoodLayoutUIViewTests.xcodeproj -scheme RedwoodLayoutUIViewTests -destination 'platform=iOS Simulator,name=iPhone 12,OS=latest' test

sample-counter:
runs-on: macos-latest
steps:
Expand Down Expand Up @@ -161,9 +163,9 @@ jobs:
- build
- connected
- dokka
- paparazzi
- sample-counter
- sample-emoji
- screenshot-tests
- test-app
steps:
- uses: actions/checkout@v4
Expand Down
38 changes: 28 additions & 10 deletions redwood-layout-shared-test/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
apply plugin: 'org.jetbrains.kotlin.jvm'
import app.cash.redwood.buildsupport.KmpTargets

dependencies {
api projects.redwoodLayoutApi
api projects.redwoodLayoutModifiers
api projects.redwoodLayoutWidget
api projects.redwoodRuntime
api projects.redwoodWidget
api projects.redwoodYoga
api libs.junit
api libs.testParameterInjector
apply plugin: 'org.jetbrains.kotlin.multiplatform'

kotlin {
KmpTargets.addAllTargets(project)

sourceSets {
commonMain {
dependencies {
api projects.redwoodLayoutApi
api projects.redwoodLayoutModifiers
api projects.redwoodLayoutWidget
api projects.redwoodRuntime
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
api libs.testParameterInjector
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package app.cash.redwood.layout
import app.cash.redwood.layout.widget.Spacer
import app.cash.redwood.ui.dp
import app.cash.redwood.widget.Widget
import org.junit.Test
import kotlin.test.Test

abstract class AbstractSpacerTest<T : Any> {

Expand All @@ -33,22 +33,22 @@ abstract class AbstractSpacerTest<T : Any> {
height(height.dp)
}

@Test fun zeroSpacer() {
@Test fun testZeroSpacer() {
val widget = widget(width = 0, height = 0)
verifySnapshot(wrap(widget, horizontal = true))
}

@Test fun widthOnlySpacer() {
@Test fun testWidthOnlySpacer() {
val widget = widget(width = 100, height = 0)
verifySnapshot(wrap(widget, horizontal = true))
}

@Test fun heightOnlySpacer() {
@Test fun testHeightOnlySpacer() {
val widget = widget(width = 0, height = 100)
verifySnapshot(wrap(widget, horizontal = false))
}

@Test fun bothSpacer() {
@Test fun testBothSpacer() {
val widget = widget(width = 100, height = 100)
verifySnapshot(wrap(widget, horizontal = false))
}
Expand Down
Loading

0 comments on commit 3d4411e

Please sign in to comment.