Skip to content

Commit

Permalink
Merge pull request Splitties#4 from yschimke/screenshot
Browse files Browse the repository at this point in the history
Add device specific screenshot tests
  • Loading branch information
LouisCAD committed Feb 23, 2024
2 parents 39c538f + 4233d28 commit 3610760
Show file tree
Hide file tree
Showing 29 changed files with 184 additions and 1 deletion.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ plugins {
id("com.android.application") apply false
id("com.android.library") apply false
kotlin("android") apply false
alias(libs.plugins.roborazzi) apply false
}
8 changes: 8 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
[plugins]

roborazzi = { id = "io.github.takahirom.roborazzi", version.ref = "roborazzi" }

[versions]
composeOClock = "0.1.0-SNAPSHOT"
roborazzi = "1.10.1"

[libraries]
compose-oclock-core = { group = "org.splitties.compose.oclock", name = "core", version.ref = "composeOClock" }
compose-oclock-watchface-renderer = { group = "org.splitties.compose.oclock", name = "watchface-renderer", version.ref = "composeOClock" }
roborazzi = { group = "io.github.takahirom.roborazzi", name = "roborazzi", version.ref = "roborazzi" }
roborazzi-compose = { group = "io.github.takahirom.roborazzi", name = "roborazzi-compose", version.ref = "roborazzi" }
roborazzi-rule = { group = "io.github.takahirom.roborazzi", name = "roborazzi-junit-rule", version.ref = "roborazzi" }
17 changes: 17 additions & 0 deletions shared/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
@file:Suppress("UnstableApiUsage")

import de.fayard.refreshVersions.core.versionFor

plugins {
id("android-lib")
alias(libs.plugins.roborazzi)
}

android {
Expand All @@ -21,6 +24,12 @@ android {
compileOptions {
isCoreLibraryDesugaringEnabled = true
}

testOptions {
unitTests {
isIncludeAndroidResources = true
}
}
}

dependencies {
Expand All @@ -44,9 +53,17 @@ dependencies {
}
debugImplementation {
AndroidX.compose.ui.tooling() //Important so previews can work.
AndroidX.compose.ui.testManifest() // import for tests
}
testImplementation {
Testing.junit4()
Testing.robolectric()
AndroidX.test.ext.junit.ktx()
AndroidX.test.runner()
AndroidX.compose.ui.testJunit4()
libs.roborazzi()
libs.roborazzi.compose()
libs.roborazzi.rule()
}
androidTestImplementation {
AndroidX.test.ext.junit.ktx()
Expand Down
2 changes: 1 addition & 1 deletion shared/src/main/kotlin/ComposeOClockWatermark.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fun ComposeOClockWatermark(finalBrush: Brush) {
val result = runCatching {
font.typefaceLoader.awaitLoad(context, font)
}
value = if (result.isSuccess) finalBrush else Brush.linearGradient(listOf(Color.Red))
value = if (result.isSuccess) finalBrush else SolidColor(Color.Red)
}
val interactiveTextStyle = remember(fontFamily, brush) {
TextStyle(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.splitties.compose.oclock.sample.watchfaces

import androidx.compose.runtime.Composable

class BasicAnalogClockTest(device: WearDevice) : DeviceClockScreenshotTest(device) {
@Composable
override fun Clock() {
BasicAnalogClock()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.splitties.compose.oclock.sample.watchfaces

import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onRoot
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.github.takahirom.roborazzi.captureRoboImage
import kotlinx.coroutines.flow.MutableStateFlow
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.ParameterizedRobolectricTestRunner
import org.robolectric.RuntimeEnvironment
import org.robolectric.annotation.Config
import org.robolectric.annotation.GraphicsMode
import org.splitties.compose.oclock.OClockRootCanvas

@Config(
sdk = [33],
qualifiers = "w227dp-h227dp-small-notlong-round-watch-xhdpi-keyshidden-nonav",
)
@GraphicsMode(GraphicsMode.Mode.NATIVE)
abstract class ClockScreenshotTest {
@get:Rule
val composeRule = createComposeRule()

abstract val device: WearDevice

fun runTest(isAmbient: Boolean = false, clock: @Composable () -> Unit) {
RuntimeEnvironment.setQualifiers("+w${device.dp}dp-h${device.dp}dp")

composeRule.setContent {
OClockRootCanvas(
modifier = Modifier.fillMaxSize(), isAmbientFlow = MutableStateFlow(isAmbient)
) {
clock()
}
}

composeRule.onRoot()
.captureRoboImage("src/test/screenshots/${this.javaClass.simpleName}_${device.id}${if (isAmbient) "_ambient" else ""}.png")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.splitties.compose.oclock.sample.watchfaces

import androidx.compose.runtime.Composable

class ComposeFanClockTest(device: WearDevice) : DeviceClockScreenshotTest(device) {
@Composable
override fun Clock() {
ComposeFanClock()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.splitties.compose.oclock.sample.watchfaces

import androidx.compose.runtime.Composable
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.ParameterizedRobolectricTestRunner
import org.splitties.compose.oclock.sample.watchfaces.WearDevice.Companion.GooglePixelWatch
import org.splitties.compose.oclock.sample.watchfaces.WearDevice.Companion.MobvoiTicWatchPro5
import org.splitties.compose.oclock.sample.watchfaces.WearDevice.Companion.SamsungGalaxyWatch5

@RunWith(ParameterizedRobolectricTestRunner::class)
abstract class DeviceClockScreenshotTest(override val device: WearDevice): ClockScreenshotTest() {

@Test
fun interactive() = runTest {
Clock()
}

@Test
fun ambient() = runTest(isAmbient = true) {
Clock()
}

@Composable
abstract fun Clock()

companion object {
@JvmStatic
@ParameterizedRobolectricTestRunner.Parameters
fun devices() = listOf(
MobvoiTicWatchPro5,
SamsungGalaxyWatch5,
GooglePixelWatch,
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.splitties.compose.oclock.sample.watchfaces

import kotlin.math.roundToInt

data class WearDevice(
val id: String,
val modelName: String,
val px: Int,
val density: Float
) {
val dp: Int = (px / density).roundToInt()

companion object {
val MobvoiTicWatchPro5: WearDevice = WearDevice(
id = "ticwatch_pro_5",
modelName = "Mobvoi TicWatch Pro 5",
px = 466,
density = 2.0f,
)

val SamsungGalaxyWatch5: WearDevice = WearDevice(
id = "galaxy_watch_5",
modelName = "Samsung Galaxy Watch 5",
px = 396,
density = 2.0f,
)

val GooglePixelWatch: WearDevice = WearDevice(
id = "pixelwatch",
modelName = "Google Pixel Watch",
px = 384,
density = 2.0f,
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.splitties.compose.oclock.sample.watchfaces

import androidx.compose.runtime.Composable

class KotlinFanClockTest(device: WearDevice) : DeviceClockScreenshotTest(device) {
@Composable
override fun Clock() {
KotlinFanClock()
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions versions.properties
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ version.androidx.test.ext.junit=1.1.5
## # available=1.2.0-alpha02
## # available=1.2.0-alpha03

version.androidx.test.runner=1.5.2
## # available=1.5.3-alpha01
## # available=1.6.0-alpha01
## # available=1.6.0-alpha02
## # available=1.6.0-alpha03
## # available=1.6.0-alpha04
## # available=1.6.0-alpha05
## # available=1.6.0-alpha06

version.androidx.wear.compose=1.3.0
## # available=1.4.0-alpha01

Expand All @@ -87,5 +96,7 @@ version.junit.junit=4.13.2

version.kotlin=1.9.22

version.robolectric=4.11.1

version.splitties=3.0.0
## # available=3.1.0-SNAPSHOT

0 comments on commit 3610760

Please sign in to comment.