Skip to content

Commit

Permalink
Merge pull request #136 from sergio-sastre/release/2.6.0
Browse files Browse the repository at this point in the history
Prepare CrossLibrary features for 2.6.0
  • Loading branch information
sergio-sastre authored Nov 19, 2024
2 parents c2a1c42 + 841b866 commit 3498402
Show file tree
Hide file tree
Showing 30 changed files with 207 additions and 102 deletions.
2 changes: 1 addition & 1 deletion android-testify/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ publishing {
release(MavenPublication) {
groupId = 'com.github.sergio-sastre'
artifactId = "android-testify"
version = '2.5.0'
version = '2.6.0'

afterEvaluate {
from components.release
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package sergio.sastre.uitesting.android_testify

import android.graphics.Rect
import android.view.ViewGroup
import androidx.annotation.ColorInt
import dev.testify.CompareMethod
import dev.testify.core.ExclusionRectProvider
import sergio.sastre.uitesting.utils.crosslibrary.config.BitmapCaptureMethod
import sergio.sastre.uitesting.utils.crosslibrary.config.LibraryConfig

class AndroidTestifyConfig(
data class AndroidTestifyConfig(
val bitmapCaptureMethod: BitmapCaptureMethod? = null,
val exactness: Float = 0.9f,
val enableReporter: Boolean = false,
Expand Down
2 changes: 1 addition & 1 deletion dropshots/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ publishing {
release(MavenPublication) {
groupId = 'com.github.sergio-sastre'
artifactId = "dropshots"
version = '2.5.0'
version = '2.6.0'

afterEvaluate {
from components.release
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import com.dropbox.dropshots.ResultValidator
import sergio.sastre.uitesting.utils.crosslibrary.config.BitmapCaptureMethod
import sergio.sastre.uitesting.utils.crosslibrary.config.LibraryConfig

class DropshotsConfig(
data class DropshotsConfig(
val resultValidator: ResultValidator = CountValidator(0),
val imageComparator: ImageComparator = SimpleImageComparator(maxDistance = 0.004f),
val bitmapCaptureMethod: BitmapCaptureMethod? = null,
Expand Down
2 changes: 1 addition & 1 deletion mapper-paparazzi/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ publishing {
release(MavenPublication) {
groupId = 'com.github.sergio-sastre'
artifactId = "mapper-paparazzi"
version = '2.5.0'
version = '2.6.0'

afterEvaluate {
from components.release
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package sergio.sastre.uitesting.mapper.paparazzi

import sergio.sastre.uitesting.mapper.paparazzi.wrapper.AccessibilityRenderExtension
import sergio.sastre.uitesting.mapper.paparazzi.wrapper.DeviceConfig
import sergio.sastre.uitesting.mapper.paparazzi.wrapper.Environment
import sergio.sastre.uitesting.mapper.paparazzi.wrapper.RenderExtension
Expand All @@ -18,17 +19,29 @@ import sergio.sastre.uitesting.utils.crosslibrary.config.LibraryConfig
* considering the orientation (e.g. width and height switched for Landscape)
* @param softButtons: false for all wrapped DeviceConfigs, contrary to Paparazzi's default.
* That's because of this default renderingMode: if softButtons == true, they overlap
* the view, and are displaded on top of it.
* the view, and are displaced on top of it.
*/
class PaparazziConfig(
data class PaparazziConfig(
val maxPercentageDiff: Double = 0.1,
val deviceConfig: DeviceConfig = DeviceConfig.NEXUS_5,
val deviceSystemUiVisibility: DeviceSystemUiVisibility = DeviceSystemUiVisibility(),
val environment: Environment? = null,
val snapshotViewOffsetMillis: Long = 0L,
val renderingMode: RenderingMode? = null,
val renderExtensions: Set<RenderExtension> = emptySet(),
) : LibraryConfig
val useDeviceResolution: Boolean = false,
val validateAccessibility: Boolean = false,
) : LibraryConfig {

fun overrideForDefaultAccessibility(): PaparazziConfig {
return this.copy(
deviceConfig = this.deviceConfig.increaseWidthForAccessibilityExtension(),
renderingMode = RenderingMode.NORMAL,
renderExtensions = setOf(AccessibilityRenderExtension()),
validateAccessibility = false, // Paparazzi does not support it together with RenderExtensions
)
}
}

data class DeviceSystemUiVisibility(
val softButtons: Boolean = false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
package sergio.sastre.uitesting.mapper.paparazzi.wrapper

enum class Density {
XXXHIGH,
DPI_560,
XXHIGH,
DPI_440,
DPI_420,
DPI_400,
DPI_360,
XHIGH,
DPI_260,
DPI_280,
DPI_300,
DPI_340,
HIGH,
DPI_220,
TV,
DPI_200,
DPI_180,
MEDIUM,
DPI_140,
LOW,
ANYDPI,
NODPI,
interface DpiDensity {
val dpi: Int
class Value(override val dpi: Int) : DpiDensity
}

enum class Density(override val dpi: Int) : DpiDensity {
XXXHIGH(640),
DPI_560(560),
XXHIGH(480),
DPI_440(440),
DPI_420(420),
DPI_400(400),
DPI_360(360),
XHIGH(480),
DPI_260(260),
DPI_280(280),
DPI_300(300),
DPI_340(340),
HIGH(240),
DPI_220(220),
TV(213),
DPI_200(200),
DPI_180(180),
MEDIUM(160),
DPI_140(140),
LOW(120),
ANYDPI(0xFFFE),
NODPI(0xFFFF)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,22 @@ data class DeviceConfig(
val screenWidth: Int = 768,
val xdpi: Int = 320,
val ydpi: Int = 320,
val density: Density = Density.XHIGH,
val density: DpiDensity = Density.XHIGH,
val ratio: ScreenRatio = ScreenRatio.NOTLONG,
val size: ScreenSize = ScreenSize.NORMAL,
val navigation: Navigation = Navigation.NONAV,
val released: String = "November 13, 2012"
) {

/**
* The accessibilityExtension takes up half the width, therefore use this to expand it
*/
fun increaseWidthForAccessibilityExtension() : DeviceConfig {
return copy(
screenWidth = this.screenWidth * 2
)
}

companion object {
@JvmField
val NEXUS_4 = DeviceConfig()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package sergio.sastre.uitesting.mapper.paparazzi.wrapper
import java.util.*

data class Environment(
val platformDir: String? = null,
val compileSdkVersion: Int? = null,
val appTestDir: String? = null,
val packageName: String? = null,
Expand Down
2 changes: 1 addition & 1 deletion mapper-roborazzi/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ publishing {
release(MavenPublication) {
groupId = 'com.github.sergio-sastre'
artifactId = "mapper-roborazzi"
version = '2.5.0'
version = '2.6.0'

afterEvaluate {
from components.release
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package sergio.sastre.uitesting.mapper.roborazzi

import androidx.annotation.ColorInt
import sergio.sastre.uitesting.mapper.roborazzi.wrapper.CaptureType
import sergio.sastre.uitesting.mapper.roborazzi.wrapper.DumpExplanation.AccessibilityExplanation
import sergio.sastre.uitesting.mapper.roborazzi.wrapper.RoborazziOptions
import sergio.sastre.uitesting.mapper.roborazzi.wrapper.screen.DeviceScreen
import sergio.sastre.uitesting.utils.crosslibrary.config.BitmapCaptureMethod
Expand All @@ -14,6 +16,14 @@ data class RoborazziConfig(
val bitmapCaptureMethod: BitmapCaptureMethod? = null,
) : LibraryConfig {

fun overrideForDefaultAccessibility(): RoborazziConfig {
return copy(
roborazziOptions = roborazziOptions.copy(
captureType = CaptureType.Dump(AccessibilityExplanation)
),
)
}

companion object {
const val DEFAULT_ROBORAZZI_OUTPUT_DIR_PATH = "build/outputs/roborazzi"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package sergio.sastre.uitesting.mapper.roborazzi.wrapper

data class AiAssertion(
val assertionPrompt: String,
val requiredFulfillmentPercent: Int,
val failIfNotFulfilled: Boolean = true
)

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package sergio.sastre.uitesting.mapper.roborazzi.wrapper
import sergio.sastre.uitesting.mapper.roborazzi.wrapper.DumpExplanation.DefaultExplanation

sealed interface CaptureType {
object Screenshot : CaptureType
data object Screenshot : CaptureType
data class Dump(val explanation: DumpExplanation = DefaultExplanation) : CaptureType
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package sergio.sastre.uitesting.mapper.roborazzi.wrapper

enum class ImageIoFormat {
LosslessWebPImageIoFormat,
ImageIoFormat
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ package sergio.sastre.uitesting.mapper.roborazzi.wrapper
data class RecordOptions(
val resizeScale: Double =
checkNotNull(System.getProperty("roborazzi.record.resizeScale", "1.0")).toDouble(),
val applyDeviceCrop: Boolean = false
val applyDeviceCrop: Boolean = false,
val imageIoFormat: ImageIoFormat = ImageIoFormat.ImageIoFormat,
)
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
package sergio.sastre.uitesting.mapper.roborazzi.wrapper

/**
* WARNING:
* @param aiAssertions requires you to add the corresponding Roborazzi module, namely one of these:
* 1. roborazzi-ai-gemini -> testImplementation(io.github.takahirom.roborazzi:roborazzi-ai-gemini)
* 2. roborazzi-ai-openai -> testImplementation(io.github.takahirom.roborazzi:roborazzi-ai-openai)
*/
data class RoborazziOptions(
val captureType: CaptureType = CaptureType.Screenshot,
val compareOptions: CompareOptions = CompareOptions(),
val recordOptions: RecordOptions = RecordOptions(),
val contextData: Map<String, Any> = emptyMap(),
val aiAssertions: List<AiAssertion> = emptyList()
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ data class DeviceScreen(
val heightDp: Int,
val size: ScreenSize = ScreenSize.NORMAL,
val aspect: ScreenAspect = ScreenAspect.NOTLONG,
val density: ScreenDensity = ScreenDensity.MDPI,
val density: DpiDensity = ScreenDensity.MDPI,
val defaultOrientation: ScreenOrientation = ScreenOrientation.PORTRAIT,
val round: RoundScreen? = null,
val type: ScreenType? = null,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
package sergio.sastre.uitesting.mapper.roborazzi.wrapper.screen

enum class ScreenDensity(val qualifier: String) {
XXXHDPI("xxxhdpi"),
DPI_560("560dpi"),
XXHDPI("xxhdpi"),
DPI_440("440dpi"),
DPI_420("420dpi"),
DPI_400("400dpi"),
DPI_360("360dpi"),
XHDPI("xhdpi"),
DPI_260("260dpi"),
DPI_280("280dpi"),
DPI_300("300dpi"),
DPI_340("340dpi"),
HDPI("hdpi"),
DPI_220("220dpi"),
TVDPI("tvdpi"),
DPI_200("200dpi"),
DPI_180("180dpi"),
MDPI("mdpi"),
DPI_140("140dpi"),
LDPI("ldpi"),
ANYDPI("anydpi"),
NODPI("nodpi"),
interface DpiDensity {
val dpi: Int
class Value(override val dpi: Int) : DpiDensity
}

enum class ScreenDensity(val qualifier: String, override val dpi: Int): DpiDensity {
XXXHDPI("xxxhdpi", 640),
DPI_560("560dpi", 560),
XXHDPI("xxhdpi", 480),
DPI_440("440dpi", 440),
DPI_420("420dpi", 420),
DPI_400("400dpi", 400),
DPI_360("360dpi", 360),
XHDPI("xhdpi", 480),
DPI_260("260dpi", 260),
DPI_280("280dpi", 280),
DPI_300("300dpi", 300),
DPI_340("340dpi", 340),
HDPI("hdpi", 240),
DPI_220("220dpi", 220),
TVDPI("tvdpi", 213),
DPI_200("200dpi", 200),
DPI_180("180dpi", 180),
MDPI("mdpi", 160),
DPI_140("140dpi", 140),
LDPI("ldpi", 120),
ANYDPI("anydpi", 0xFFFE),
NODPI("nodpi", 0xFFFF),
}
4 changes: 2 additions & 2 deletions paparazzi/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ android {
dependencies {
implementation project(':utils')
api project(':mapper-paparazzi')
api('app.cash.paparazzi:paparazzi:1.3.4')
api('app.cash.paparazzi:paparazzi:1.3.5')
}

//https://www.talentica.com/blogs/publish-your-android-library-on-jitpack-for-better-reachability/
Expand All @@ -57,7 +57,7 @@ publishing {
release(MavenPublication) {
groupId = 'com.github.sergio-sastre'
artifactId = "paparazzi"
version = '2.5.0'
version = '2.6.0'

afterEvaluate {
from components.release
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class PaparazziForComposableTestRuleBuilder {
maxPercentDifference = paparazziConfig.maxPercentageDiff,
environment = sharedTestAdapter.asEnvironment(),
renderExtensions = sharedTestAdapter.asRenderExtensions(),
useDeviceResolution = paparazziConfig.useDeviceResolution,
validateAccessibility = paparazziConfig.validateAccessibility,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ internal class PaparazziWrapperConfigAdapter(
PaparazziWrapperDensity.LOW -> Density.LOW
PaparazziWrapperDensity.ANYDPI -> Density.ANYDPI
PaparazziWrapperDensity.NODPI -> Density.NODPI
else -> Density(config.density.dpi)
}

fun asPaparazziScreenRatio(): ScreenRatio =
Expand Down Expand Up @@ -99,7 +100,6 @@ internal class PaparazziWrapperConfigAdapter(
val environment = detectEnvironment()
val configEnvironment = paparazziConfig.environment
return environment.copy(
platformDir = configEnvironment?.platformDir ?: environment.platformDir,
compileSdkVersion = configEnvironment?.compileSdkVersion
?: environment.compileSdkVersion,
appTestDir = configEnvironment?.appTestDir ?: environment.appTestDir,
Expand Down
4 changes: 2 additions & 2 deletions robolectric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ android {

dependencies {
implementation project(':utils')
implementation "org.robolectric:robolectric:4.13"
implementation "org.robolectric:robolectric:4.14"
}

//https://www.talentica.com/blogs/publish-your-android-library-on-jitpack-for-better-reachability/
Expand All @@ -50,7 +50,7 @@ publishing {
release(MavenPublication) {
groupId = 'com.github.sergio-sastre'
artifactId = "robolectric"
version = '2.5.0'
version = '2.6.0'

afterEvaluate {
from components.release
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ object RobolectricQualifiersBuilder {
round?.let { listOfQualifiers.add(it.qualifier) }
orientationQualifier(configOrientation).let { listOfQualifiers.add(it) }
type?.let { listOfQualifiers.add(it.qualifier) }
density.let { listOfQualifiers.add(it.qualifier) }
density.let { listOfQualifiers.add(it.valueAsQualifier()) }

setQualifiers(listOfQualifiers.joinToString(separator = "-"))
}
Expand Down
Loading

0 comments on commit 3498402

Please sign in to comment.