Skip to content

Commit

Permalink
Add screenshot tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yschimke committed Feb 23, 2024
1 parent 11bb14d commit d3a3b6d
Show file tree
Hide file tree
Showing 25 changed files with 30 additions and 3 deletions.
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.Default.copy(
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
Expand Up @@ -12,6 +12,7 @@ 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
Expand All @@ -28,6 +29,8 @@ abstract class ClockScreenshotTest {
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)
Expand All @@ -37,6 +40,6 @@ abstract class ClockScreenshotTest {
}

composeRule.onRoot()
.captureRoboImage("src/test/screenshots/${this.javaClass.simpleName}_${device.id}${if (isAmbient) "_interactive" else ""}.png")
.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
Expand Up @@ -17,7 +17,7 @@ abstract class DeviceClockScreenshotTest(override val device: WearDevice): Clock
}

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
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",
Expand Down
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.
Binary file not shown.

0 comments on commit d3a3b6d

Please sign in to comment.