Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
219 additions
and
159 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
paparazzi/paparazzi-gradle-plugin/src/test/projects/widgets/build.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
105 changes: 105 additions & 0 deletions
105
.../test/projects/widgets/src/test/java/app/cash/paparazzi/plugin/test/RenderingModesTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
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" | ||
} | ||
) | ||
} | ||
} | ||
} |
159 changes: 0 additions & 159 deletions
159
paparazzi/paparazzi/src/test/java/app/cash/paparazzi/RenderingModeTest.kt
This file was deleted.
Oops, something went wrong.
89 changes: 89 additions & 0 deletions
89
sample/src/test/java/app/cash/paparazzi/sample/WidgetTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package app.cash.paparazzi.sample | ||
|
||
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 | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
class WidgetTest { | ||
@get:Rule | ||
val paparazzi = Paparazzi( | ||
deviceConfig = DeviceConfig.PIXEL_3.copy(softButtons = false), | ||
renderingMode = SessionParams.RenderingMode.SHRINK, | ||
) | ||
|
||
@Test fun default() { | ||
paparazzi.snapshot(buildView(paparazzi.context)) | ||
} | ||
|
||
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" | ||
} | ||
) | ||
} | ||
} | ||
} |