Skip to content

Commit

Permalink
chore: added screenshot testing (#659)
Browse files Browse the repository at this point in the history
* chore: added screenshot testing

* chore: added GitHub flow integration

* chore: upload build report

* chore: reset cluster

* chore: reset cluster

* chore: reset cluster

* chore: added threshold

* chore: changed threshold

* chore: changed threshold to 5%

* chore: increased version

* chore: new reference version

* chore: changed threshold

* chore: changed threshold

* chore: changed threshold

* chore: changed threshold

* chore: added test for DisappearingScaleBar
  • Loading branch information
kikoso authored Dec 10, 2024
1 parent c50ac61 commit de8f4a9
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 7 deletions.
12 changes: 11 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020 Google LLC
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -45,3 +45,13 @@ jobs:

- name: Build modules
run: ./gradlew build jacocoTestReport --stacktrace

- name: Run Screenshot Tests
run: ./gradlew validateDebugScreenshotTest

- name: Upload build reports
uses: actions/upload-artifact@v4
if: always()
with:
name: my-artifact
path: app/build/reports
11 changes: 11 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ plugins {
id("kotlin-android")
id("com.google.android.libraries.mapsplatform.secrets-gradle-plugin")
alias(libs.plugins.compose.compiler)
alias(libs.plugins.screenshot)
}

android {
Expand Down Expand Up @@ -46,6 +47,14 @@ android {
jvmTarget = "1.8"
freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn"
}

experimentalProperties["android.experimental.enableScreenshotTest"] = true

testOptions {
screenshotTests {
imageDifferenceThreshold = 0.035f // 3.5%
}
}
}

dependencies {
Expand All @@ -68,6 +77,8 @@ dependencies {
androidTestImplementation(libs.androidx.test.compose.ui)
androidTestImplementation(libs.kotlinx.coroutines.test)

screenshotTestImplementation(libs.androidx.compose.ui.tooling)

// Instead of the lines below, regular apps would load these libraries from Maven according to
// the README installation instructions
implementation(project(":maps-compose"))
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.
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,18 @@ import androidx.compose.foundation.layout.systemBarsPadding
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.material.CircularProgressIndicator
import androidx.compose.material.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.google.android.gms.maps.model.CameraPosition
import com.google.android.gms.maps.model.LatLng
import com.google.maps.android.compose.theme.MapsComposeSampleTheme
import com.google.maps.android.compose.widgets.DarkGray
import com.google.maps.android.compose.widgets.DisappearingScaleBar
import com.google.maps.android.compose.widgets.ScaleBar
Expand Down Expand Up @@ -126,4 +131,26 @@ class ScaleBarActivity : ComponentActivity() {
}
}
}
}

@Preview
@Composable
fun PreviewScaleBar() {
val cameraPositionState = remember {
CameraPositionState(
position = CameraPosition(
LatLng(48.137154, 11.576124), // Example coordinates: Munich, Germany
12f,
0f,
0f
)
)
}

MapsComposeSampleTheme {
ScaleBar(
modifier = Modifier.padding(end = 4.dp),
cameraPositionState = cameraPositionState
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ fun CustomRendererClustering(items: List<MyItem>) {
},
clusterManager = clusterManager,
)

SideEffect {
clusterManager ?: return@SideEffect
clusterManager.setOnClusterClickListener {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.google.maps.android.compose

import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.google.android.gms.maps.model.CameraPosition
import com.google.android.gms.maps.model.LatLng
import com.google.maps.android.compose.theme.MapsComposeSampleTheme
import com.google.maps.android.compose.widgets.DisappearingScaleBar
import com.google.maps.android.compose.widgets.ScaleBar


class ScaleBarTest() {
@Preview
@Composable
fun PreviewScaleBar() {
val cameraPositionState = remember {
CameraPositionState(
position = CameraPosition(
LatLng(48.137154, 11.576124), // Example coordinates: Munich, Germany
12f,
0f,
0f
)
)
}

MapsComposeSampleTheme {
ScaleBar(
modifier = Modifier.padding(end = 4.dp),
cameraPositionState = cameraPositionState
)
}
}

@Preview
@Composable
fun PreviewDisappearingScaleBar() {
val cameraPositionState = remember {
CameraPositionState(
position = CameraPosition(
LatLng(48.137154, 11.576124), // Example coordinates: Munich, Germany
12f,
0f,
0f
)
)
}

MapsComposeSampleTheme {
DisappearingScaleBar(
modifier = Modifier.padding(end = 4.dp),
cameraPositionState = cameraPositionState
)
}
}
}
4 changes: 3 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ sonatypeToken=
sonatypeTokenPassword=

android.nonTransitiveRClass=false
android.nonFinalResIds=false
android.nonFinalResIds=false

android.experimental.enableScreenshotTest=true
13 changes: 8 additions & 5 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
[versions]
activitycompose = "1.9.3"
agp = "8.7.2"
androidxtest = "1.6.1"
compose-bom = "2024.10.01"
androidxtest = "1.6.2"
androidCore = "1.6.1"
compose-bom = "2024.11.00"
dokka = "1.9.20"
espresso = "3.6.1"
jacoco-plugin = "0.2.1"
Expand All @@ -14,6 +15,7 @@ mapsktx = "5.1.1"
mapsecrets = "2.0.1"
org-jacoco-core = "0.8.11"
androidx-core = "1.15.0"
screenshot = "0.0.1-alpha08"

[libraries]
android-gradle-plugin = { module = "com.android.tools.build:gradle", version.ref = "agp" }
Expand All @@ -26,10 +28,10 @@ androidx-compose-ui-preview-tooling = { module = "androidx.compose.ui:ui-tooling
androidx-compose-ui-tooling = { module = "androidx.compose.ui:ui-tooling" }
androidx-core = { module = "androidx.core:core-ktx", version.ref = "androidx-core" }
androidx-test-compose-ui = { module = "androidx.compose.ui:ui-test-junit4" }
androidx-test-core = { module = "androidx.test:core", version.ref = "androidxtest" }
androidx-test-core = { module = "androidx.test:core", version.ref = "androidCore" }
androidx-test-espresso = { module = "androidx.test.espresso:espresso-core", version.ref = "espresso" }
androidx-test-junit-ktx = { module = "androidx.test.ext:junit-ktx", version.ref = "junitktx" }
androidx-test-rules = { module = "androidx.test:rules", version.ref = "androidxtest" }
androidx-test-rules = { module = "androidx.test:rules", version.ref = "androidCore" }
androidx-test-runner = { module = "androidx.test:runner", version.ref = "androidxtest" }
dokka-plugin = { module = "org.jetbrains.dokka:dokka-gradle-plugin", version.ref = "dokka" }
jacoco-android-plugin = { module = "com.mxalbert.gradle:jacoco-android", version.ref = "jacoco-plugin", version.require = "0.2.1" }
Expand All @@ -45,4 +47,5 @@ test-junit = { module = "junit:junit", version.ref = "junit" }

[plugins]
dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
screenshot = { id = "com.android.compose.screenshot", version.ref = "screenshot"}

0 comments on commit de8f4a9

Please sign in to comment.