diff --git a/audio-ui/build.gradle b/audio-ui/build.gradle index afb4a6156e..1b127bf765 100644 --- a/audio-ui/build.gradle +++ b/audio-ui/build.gradle @@ -112,13 +112,12 @@ dependencies { implementation libs.androidx.wear implementation libs.androidx.lifecycle.viewmodel.compose - debugImplementation libs.androidx.customview - debugImplementation libs.androidx.customview.pooling debugImplementation libs.compose.ui.toolingpreview - debugImplementation libs.androidx.activity.compose + debugImplementation projects.composeTesting testImplementation libs.junit testImplementation projects.paparazzi + testImplementation projects.composeTesting androidTestImplementation libs.compose.ui.test.junit4 debugImplementation libs.compose.ui.test.manifest diff --git a/audio-ui/src/debug/java/com/google/android/horologist/audio/ui/VolumeScreenPreview.kt b/audio-ui/src/debug/java/com/google/android/horologist/audio/ui/VolumeScreenPreview.kt index ec7a78ad3f..42e25c0c06 100644 --- a/audio-ui/src/debug/java/com/google/android/horologist/audio/ui/VolumeScreenPreview.kt +++ b/audio-ui/src/debug/java/com/google/android/horologist/audio/ui/VolumeScreenPreview.kt @@ -27,6 +27,8 @@ import androidx.compose.ui.tooling.preview.PreviewParameterProvider import androidx.wear.compose.material.Scaffold import com.google.android.horologist.audio.AudioOutput import com.google.android.horologist.audio.VolumeState +import com.google.android.horologist.compose.testing.WearPreviewDevices +import com.google.android.horologist.compose.testing.WearPreviewFontSizes @Preview( device = Devices.WEAR_OS_LARGE_ROUND, @@ -60,24 +62,8 @@ fun VolumeScreenGuide() { } } -@Preview( - device = Devices.WEAR_OS_LARGE_ROUND, - showSystemUi = true, - backgroundColor = 0xff000000, - showBackground = true -) -@Preview( - device = Devices.WEAR_OS_SMALL_ROUND, - showSystemUi = true, - backgroundColor = 0xff000000, - showBackground = true -) -@Preview( - device = Devices.WEAR_OS_SQUARE, - showSystemUi = true, - backgroundColor = 0xff000000, - showBackground = true -) +@WearPreviewDevices +@WearPreviewFontSizes @Composable @OptIn(ExperimentalHorologistAudioUiApi::class) fun VolumeScreenPreview( diff --git a/composables/build.gradle b/composables/build.gradle index cc4276aeda..e3bd9eff0d 100644 --- a/composables/build.gradle +++ b/composables/build.gradle @@ -86,8 +86,6 @@ dependencies { implementation libs.compose.material.iconscore implementation libs.compose.material.iconsext - debugImplementation libs.androidx.customview - debugImplementation libs.androidx.customview.pooling debugImplementation libs.compose.ui.test.manifest debugImplementation libs.compose.ui.toolingpreview diff --git a/compose-layout/build.gradle b/compose-layout/build.gradle index 65e67e616d..37df607e04 100644 --- a/compose-layout/build.gradle +++ b/compose-layout/build.gradle @@ -105,6 +105,7 @@ dependencies { implementation libs.compose.ui.util implementation libs.androidx.wear implementation libs.androidx.lifecycle.viewmodel.compose + debugImplementation projects.composeTesting debugImplementation libs.compose.ui.toolingpreview debugImplementation libs.androidx.activity.compose diff --git a/compose-layout/src/debug/java/com/google/android/horologist/compose/layout/fillMaxRectanglePreview.kt b/compose-layout/src/debug/java/com/google/android/horologist/compose/layout/fillMaxRectanglePreview.kt index d3ec2b5ef8..b9948adcf6 100644 --- a/compose-layout/src/debug/java/com/google/android/horologist/compose/layout/fillMaxRectanglePreview.kt +++ b/compose-layout/src/debug/java/com/google/android/horologist/compose/layout/fillMaxRectanglePreview.kt @@ -24,22 +24,10 @@ import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color -import androidx.compose.ui.tooling.preview.Devices -import androidx.compose.ui.tooling.preview.Preview import androidx.wear.compose.material.Text +import com.google.android.horologist.compose.testing.WearPreviewDevices -@Preview( - device = Devices.WEAR_OS_LARGE_ROUND, - showSystemUi = true, - backgroundColor = 0xff000000, - showBackground = true -) -@Preview( - device = Devices.WEAR_OS_SQUARE, - showSystemUi = true, - backgroundColor = 0xff000000, - showBackground = true -) +@WearPreviewDevices @Composable fun Preview() { Box(modifier = Modifier.fillMaxSize()) { diff --git a/compose-testing/README.md b/compose-testing/README.md new file mode 100644 index 0000000000..bfb698d372 --- /dev/null +++ b/compose-testing/README.md @@ -0,0 +1,22 @@ +# Testing Library + +[![Maven Central](https://img.shields.io/maven-central/v/com.google.android.horologist/horologist-compose-testing)](https://search.maven.org/search?q=g:com.google.android.horologist) + +For more information, visit the documentation: https://google.github.io/horologist/compose-testing + +## Download + +```groovy +repositories { + mavenCentral() +} + +dependencies { + implementation "com.google.android.horologist:horologist-compose-testing:" +} +``` + +Snapshots of the development version are available in [Sonatype's `snapshots` repository][snap]. +These are updated on every commit. + + [snap]: https://oss.sonatype.org/content/repositories/snapshots/com/google/android/horologist/horologist-compose-testing/ diff --git a/compose-testing/api/current.api b/compose-testing/api/current.api new file mode 100644 index 0000000000..f1b10e67b6 --- /dev/null +++ b/compose-testing/api/current.api @@ -0,0 +1,11 @@ +// Signature format: 4.0 +package com.google.android.horologist.compose.testing { + + @androidx.compose.ui.tooling.preview.Preview(device=androidx.compose.ui.tooling.preview.Devices.WEAR_OS_LARGE_ROUND, showSystemUi=true, backgroundColor=4278190080L, showBackground=true, name="Large Round") @androidx.compose.ui.tooling.preview.Preview(device=androidx.compose.ui.tooling.preview.Devices.WEAR_OS_SMALL_ROUND, showSystemUi=true, backgroundColor=4278190080L, showBackground=true, name="Small Round") @androidx.compose.ui.tooling.preview.Preview(device=androidx.compose.ui.tooling.preview.Devices.WEAR_OS_SQUARE, showSystemUi=true, backgroundColor=4278190080L, showBackground=true, name="Square") public @interface WearPreviewDevices { + } + + @androidx.compose.ui.tooling.preview.Preview(device=androidx.compose.ui.tooling.preview.Devices.WEAR_OS_SMALL_ROUND, showSystemUi=true, backgroundColor=4278190080L, showBackground=true, name="Small", fontScale=0.94f) @androidx.compose.ui.tooling.preview.Preview(device=androidx.compose.ui.tooling.preview.Devices.WEAR_OS_SMALL_ROUND, showSystemUi=true, backgroundColor=4278190080L, showBackground=true, name="Normal", fontScale=1.0f) @androidx.compose.ui.tooling.preview.Preview(device=androidx.compose.ui.tooling.preview.Devices.WEAR_OS_SMALL_ROUND, showSystemUi=true, backgroundColor=4278190080L, showBackground=true, name="Medium", fontScale=1.06f) @androidx.compose.ui.tooling.preview.Preview(device=androidx.compose.ui.tooling.preview.Devices.WEAR_OS_SMALL_ROUND, showSystemUi=true, backgroundColor=4278190080L, showBackground=true, name="Large", fontScale=1.12f) @androidx.compose.ui.tooling.preview.Preview(device=androidx.compose.ui.tooling.preview.Devices.WEAR_OS_SMALL_ROUND, showSystemUi=true, backgroundColor=4278190080L, showBackground=true, name="Larger", fontScale=1.18f) @androidx.compose.ui.tooling.preview.Preview(device=androidx.compose.ui.tooling.preview.Devices.WEAR_OS_SMALL_ROUND, showSystemUi=true, backgroundColor=4278190080L, showBackground=true, name="Largest", fontScale=1.24f) public @interface WearPreviewFontSizes { + } + +} + diff --git a/compose-testing/build.gradle b/compose-testing/build.gradle new file mode 100644 index 0000000000..3524a76c18 --- /dev/null +++ b/compose-testing/build.gradle @@ -0,0 +1,107 @@ +/* + * Copyright 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +plugins { + id 'com.android.library' + id 'kotlin-android' + id 'org.jetbrains.dokka' + id "org.jetbrains.kotlin.kapt" +} + +android { + compileSdkVersion 31 + + defaultConfig { + minSdk 25 + targetSdk 30 + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + + buildFeatures { + buildConfig false + } + + kotlinOptions { + jvmTarget = "1.8" + } + + composeOptions { + kotlinCompilerExtensionVersion libs.versions.compose.get() + } + + lintOptions { + textReport true + textOutput 'stdout' + // We run a full lint analysis as build part in CI, so skip vital checks for assemble tasks + checkReleaseBuilds false + } + + packagingOptions { + // Some of the META-INF files conflict with coroutines-test. Exclude them to enable + // our test APK to build (has no effect on our AARs) + excludes += "/META-INF/AL2.0" + excludes += "/META-INF/LGPL2.1" + } + + testOptions { + unitTests { + includeAndroidResources = true + } + animationsDisabled true + } + + sourceSets { + test { + java.srcDirs += 'src/sharedTest/kotlin' + res.srcDirs += 'src/sharedTest/res' + } + androidTest { + java.srcDirs += 'src/sharedTest/kotlin' + res.srcDirs += 'src/sharedTest/res' + } + } +} + +kapt { + correctErrorTypes true +} + +project.tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile.class).configureEach { task -> + // Workaround for https://youtrack.jetbrains.com/issue/KT-37652 + if (!task.name.endsWith("TestKotlin") && !task.name.startsWith("compileDebug")) { + task.kotlinOptions.freeCompilerArgs.add("-Xexplicit-api=strict") + } +} + +dependencies { + implementation libs.kotlin.stdlib + + implementation libs.compose.ui.tooling + + implementation libs.wearcompose.material + implementation libs.wearcompose.foundation + implementation libs.wearcompose.navigation + + debugImplementation libs.compose.ui.test.manifest + debugImplementation libs.compose.ui.toolingpreview +} + +apply plugin: "com.vanniktech.maven.publish" diff --git a/compose-testing/gradle.properties b/compose-testing/gradle.properties new file mode 100644 index 0000000000..f2c00117a2 --- /dev/null +++ b/compose-testing/gradle.properties @@ -0,0 +1,3 @@ +POM_ARTIFACT_ID=horologist-compose-testing +POM_NAME=Horologist Compose Testing library +POM_PACKAGING=aar diff --git a/compose-testing/src/main/AndroidManifest.xml b/compose-testing/src/main/AndroidManifest.xml new file mode 100644 index 0000000000..635d185acf --- /dev/null +++ b/compose-testing/src/main/AndroidManifest.xml @@ -0,0 +1,21 @@ + + + + + + diff --git a/compose-testing/src/main/java/com/google/android/horologist/compose/testing/WearPreviewDevices.kt b/compose-testing/src/main/java/com/google/android/horologist/compose/testing/WearPreviewDevices.kt new file mode 100644 index 0000000000..ac06a61bf4 --- /dev/null +++ b/compose-testing/src/main/java/com/google/android/horologist/compose/testing/WearPreviewDevices.kt @@ -0,0 +1,43 @@ +/* + * Copyright 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.android.horologist.compose.testing + +import androidx.compose.ui.tooling.preview.Devices +import androidx.compose.ui.tooling.preview.Preview + +@Preview( + device = Devices.WEAR_OS_LARGE_ROUND, + showSystemUi = true, + backgroundColor = 0xff000000, + showBackground = true, + group = "Devices - Large Round", +) +@Preview( + device = Devices.WEAR_OS_SMALL_ROUND, + showSystemUi = true, + backgroundColor = 0xff000000, + showBackground = true, + group = "Devices - Small Round", +) +@Preview( + device = Devices.WEAR_OS_SQUARE, + showSystemUi = true, + backgroundColor = 0xff000000, + showBackground = true, + group = "Devices - Square", +) +public annotation class WearPreviewDevices diff --git a/compose-testing/src/main/java/com/google/android/horologist/compose/testing/WearPreviewFontSizes.kt b/compose-testing/src/main/java/com/google/android/horologist/compose/testing/WearPreviewFontSizes.kt new file mode 100644 index 0000000000..3019c53cc6 --- /dev/null +++ b/compose-testing/src/main/java/com/google/android/horologist/compose/testing/WearPreviewFontSizes.kt @@ -0,0 +1,70 @@ +/* + * Copyright 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.android.horologist.compose.testing + +import androidx.compose.ui.tooling.preview.Devices +import androidx.compose.ui.tooling.preview.Preview + +@Preview( + device = Devices.WEAR_OS_SMALL_ROUND, + showSystemUi = true, + backgroundColor = 0xff000000, + showBackground = true, + group = "Fonts - Small", + fontScale = 0.94f +) +@Preview( + device = Devices.WEAR_OS_SMALL_ROUND, + showSystemUi = true, + backgroundColor = 0xff000000, + showBackground = true, + group = "Fonts - Normal", + fontScale = 1f +) +@Preview( + device = Devices.WEAR_OS_SMALL_ROUND, + showSystemUi = true, + backgroundColor = 0xff000000, + showBackground = true, + group = "Fonts - Medium", + fontScale = 1.06f +) +@Preview( + device = Devices.WEAR_OS_SMALL_ROUND, + showSystemUi = true, + backgroundColor = 0xff000000, + showBackground = true, + group = "Fonts - Large", + fontScale = 1.12f +) +@Preview( + device = Devices.WEAR_OS_SMALL_ROUND, + showSystemUi = true, + backgroundColor = 0xff000000, + showBackground = true, + group = "Fonts - Larger", + fontScale = 1.18f +) +@Preview( + device = Devices.WEAR_OS_SMALL_ROUND, + showSystemUi = true, + backgroundColor = 0xff000000, + showBackground = true, + group = "Fonts - Largest", + fontScale = 1.24f +) +public annotation class WearPreviewFontSizes diff --git a/media-ui/build.gradle b/media-ui/build.gradle index 74d9700101..c8db5a1819 100644 --- a/media-ui/build.gradle +++ b/media-ui/build.gradle @@ -91,8 +91,6 @@ dependencies { implementation libs.compose.material.iconsext implementation libs.androidx.media3.common - debugImplementation libs.androidx.customview - debugImplementation libs.androidx.customview.pooling debugImplementation libs.compose.ui.test.manifest debugImplementation libs.compose.ui.toolingpreview diff --git a/settings.gradle b/settings.gradle index 01994cba1c..28dcad128a 100644 --- a/settings.gradle +++ b/settings.gradle @@ -34,6 +34,7 @@ include ':tiles' include ':media-ui' include ':paparazzi' include ':media-data' +include ':compose-testing' // Enable Gradle's version catalog support // https://docs.gradle.org/current/userguide/platforms.html