Skip to content

Commit

Permalink
Migrate tests from #497
Browse files Browse the repository at this point in the history
  • Loading branch information
jrodbx committed Dec 14, 2022
1 parent 6a721a7 commit 7bcbcef
Show file tree
Hide file tree
Showing 10 changed files with 236 additions and 159 deletions.
Expand Up @@ -573,6 +573,24 @@ class PaparazziPluginTest {
assertThat(snapshots[2]).isSimilarTo(verticalScroll).withDefaultThreshold()
}

@Test
fun widgets() {
val fixtureRoot = File("src/test/projects/widgets")

gradleRunner
.withArguments("testDebug", "--stacktrace")
.runFixture(fixtureRoot) { build() }

val snapshotsDir = File(fixtureRoot, "build/reports/paparazzi/images")
val snapshots = snapshotsDir.listFiles()?.sortedBy { it.lastModified() }
assertThat(snapshots!!).hasSize(2)

val widgetImage = File(fixtureRoot, "src/test/resources/widget.png")
val fullScreenImage = File(fixtureRoot, "src/test/resources/full_screen.png")
assertThat(snapshots[0]).isSimilarTo(widgetImage).withDefaultThreshold()
assertThat(snapshots[1]).isSimilarTo(fullScreenImage).withDefaultThreshold()
}

@Test
fun verifyResourcesGeneratedForJavaProject() {
val fixtureRoot = File("src/test/projects/verify-resources-java")
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,25 @@
plugins {
id 'com.android.library'
id 'kotlin-android'
id 'app.cash.paparazzi'
}

repositories {
maven {
url "file://${projectDir.absolutePath}/../../../../../build/localMaven"
}
mavenCentral()
//mavenLocal()
google()
}

android {
compileSdk libs.versions.compileSdk.get() as int
defaultConfig {
minSdk libs.versions.minSdk.get() as int
}
}

dependencies {
testImplementation libs.testParameterInjector
}
@@ -0,0 +1,104 @@
package app.cash.paparazzi.plugin.test

import android.content.Context
import android.graphics.Color
import android.graphics.drawable.GradientDrawable
import android.view.Gravity
import android.view.View
import android.view.ViewGroup
import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
import android.widget.Button
import android.widget.LinearLayout
import android.widget.TextView
import app.cash.paparazzi.DeviceConfig
import app.cash.paparazzi.Paparazzi
import com.android.ide.common.rendering.api.SessionParams.RenderingMode
import com.android.ide.common.rendering.api.SessionParams.RenderingMode.NORMAL
import com.android.ide.common.rendering.api.SessionParams.RenderingMode.SHRINK
import com.google.testing.junit.testparameterinjector.TestParameter
import com.google.testing.junit.testparameterinjector.TestParameterInjector
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(TestParameterInjector::class)
class RenderingModeTest(
@TestParameter val mode: Mode
) {
@get:Rule
val paparazzi = Paparazzi(
deviceConfig = DeviceConfig.PIXEL_3.copy(softButtons = false),
renderingMode = mode.renderingMode
)

@Test fun default() {
paparazzi.snapshot(buildView(paparazzi.context))
}

enum class Mode(
val renderingMode: RenderingMode
) {
WIDGET(renderingMode = SHRINK),
FULL_SCREEN(renderingMode = NORMAL)
}

private fun buildView(context: Context): View {
return LinearLayout(context).apply {
orientation = LinearLayout.VERTICAL
layoutParams = ViewGroup.LayoutParams(WRAP_CONTENT, WRAP_CONTENT)
addView(
TextView(context).apply {
id = 1
text = "Text View Sample"
}
)

addView(
View(context).apply {
id = 2
layoutParams = LinearLayout.LayoutParams(100, 100)
contentDescription = "Content Description Sample"
}
)

addView(
View(context).apply {
id = 3
layoutParams = LinearLayout.LayoutParams(100, 100).apply {
setMargins(20, 20, 20, 20)
}
contentDescription = "Margin Sample"
}
)

addView(
View(context).apply {
id = 4
layoutParams = LinearLayout.LayoutParams(100, 100).apply {
setMargins(20, 20, 20, 20)
}
foreground = GradientDrawable(
GradientDrawable.Orientation.TL_BR,
intArrayOf(Color.YELLOW, Color.BLUE)
).apply {
shape = GradientDrawable.OVAL
}
contentDescription = "Foreground Drawable"
}
)

addView(
Button(context).apply {
id = 5
layoutParams = LinearLayout.LayoutParams(
WRAP_CONTENT,
WRAP_CONTENT
).apply {
gravity = Gravity.CENTER
}
text = "Button Sample"
}
)
}
}
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

This file was deleted.

Binary file not shown.
Binary file not shown.

0 comments on commit 7bcbcef

Please sign in to comment.