From cf7e58356808370d12884657a1451543eaca2915 Mon Sep 17 00:00:00 2001 From: Simon Marquis Date: Wed, 21 Feb 2024 14:39:48 +0100 Subject: [PATCH] chore: replace deprecated Accompanist Test Harness with official `DeviceConfigurationOverride` Docs: https://google.github.io/accompanist/testharness/ --- catalog/build.gradle.kts | 2 +- .../com/adevinta/spark/catalog/CatalogApp.kt | 23 ++++++++++--------- gradle/libs.versions.toml | 4 ++-- spark/build.gradle.kts | 4 ++-- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/catalog/build.gradle.kts b/catalog/build.gradle.kts index 40084c2a2..e458dafd6 100644 --- a/catalog/build.gradle.kts +++ b/catalog/build.gradle.kts @@ -71,11 +71,11 @@ dependencies { implementation(libs.kotlin.reflect) implementation(libs.kotlinx.collections.immutable) - implementation(libs.accompanist.testharness) implementation(libs.accompanist.drawablepainter) implementation(libs.androidx.compose.foundation) implementation(libs.androidx.compose.ui) + implementation(libs.androidx.compose.ui.test) implementation(libs.androidx.compose.ui.tooling.preview) implementation(libs.androidx.compose.material.iconsExtended) implementation(libs.androidx.compose.material3) diff --git a/catalog/src/main/kotlin/com/adevinta/spark/catalog/CatalogApp.kt b/catalog/src/main/kotlin/com/adevinta/spark/catalog/CatalogApp.kt index 4db450fd6..4953df356 100644 --- a/catalog/src/main/kotlin/com/adevinta/spark/catalog/CatalogApp.kt +++ b/catalog/src/main/kotlin/com/adevinta/spark/catalog/CatalogApp.kt @@ -62,6 +62,11 @@ import androidx.compose.ui.graphics.graphicsLayer import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.platform.LocalLayoutDirection +import androidx.compose.ui.test.DarkMode +import androidx.compose.ui.test.DeviceConfigurationOverride +import androidx.compose.ui.test.FontScale +import androidx.compose.ui.test.LayoutDirection +import androidx.compose.ui.test.then import androidx.compose.ui.unit.LayoutDirection import androidx.compose.ui.unit.dp import com.adevinta.spark.SparkFeatureFlag @@ -74,7 +79,7 @@ import com.adevinta.spark.catalog.tabbar.CatalogTabBar import com.adevinta.spark.catalog.tabbar.CatalogTabs import com.adevinta.spark.catalog.themes.BrandMode import com.adevinta.spark.catalog.themes.ColorMode -import com.adevinta.spark.catalog.themes.FontScaleMode +import com.adevinta.spark.catalog.themes.FontScaleMode.System import com.adevinta.spark.catalog.themes.TextDirection import com.adevinta.spark.catalog.themes.Theme import com.adevinta.spark.catalog.themes.ThemeMode @@ -92,7 +97,6 @@ import com.adevinta.spark.catalog.ui.rememberBackdropScaffoldState import com.adevinta.spark.catalog.ui.shaders.colorblindness.ColorBlindNessType import com.adevinta.spark.catalog.ui.shaders.colorblindness.shader import com.adevinta.spark.tokens.asSparkColors -import com.google.accompanist.testharness.TestHarness import kotlinx.coroutines.launch @Composable @@ -171,15 +175,12 @@ internal fun ComponentActivity.CatalogApp( ) } - @Suppress("DEPRECATION") - TestHarness( - darkMode = useDark, - layoutDirection = layoutDirection, - fontScale = if (theme.fontScaleMode == FontScaleMode.System) { - LocalDensity.current.fontScale - } else { - theme.fontScale - }, + DeviceConfigurationOverride( + override = DeviceConfigurationOverride.DarkMode(useDark) + then DeviceConfigurationOverride.LayoutDirection(layoutDirection) + then DeviceConfigurationOverride.FontScale( + theme.takeUnless { it.fontScaleMode == System }?.fontScale ?: LocalDensity.current.fontScale, + ), ) { Box( modifier = Modifier diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index a1602b1ef..f108fd7d9 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -38,7 +38,6 @@ accompanist-flowlayout = { module = "com.google.accompanist:accompanist-flowlayo accompanist-pager = { module = "com.google.accompanist:accompanist-pager", version.ref = "accompanist" } accompanist-permissions = { module = "com.google.accompanist:accompanist-permissions", version.ref = "accompanist" } accompanist-swiperefresh = { module = "com.google.accompanist:accompanist-swiperefresh", version.ref = "accompanist" } -accompanist-testharness = { module = "com.google.accompanist:accompanist-testharness", version.ref = "accompanist" } androidx-activity = { module = "androidx.activity:activity-ktx", version.ref = "androidx-activity" } androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activity" } @@ -59,7 +58,8 @@ androidx-compose-ui = { module = "androidx.compose.ui:ui" } androidx-constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "constraintlayout" } androidx-constraintlayoutCompose = { group = "androidx.constraintlayout", name = "constraintlayout-compose", version.ref = "constraintlayoutCompose" } androidx-compose-ui-text = { module = "androidx.compose.ui:ui-text-google-fonts" } -androidx-compose-ui-test = { module = "androidx.compose.ui:ui-test-junit4" } +androidx-compose-ui-test = { module = "androidx.compose.ui:ui-test" } +androidx-compose-ui-testJUnit = { module = "androidx.compose.ui:ui-test-junit4" } androidx-compose-ui-testManifest = { module = "androidx.compose.ui:ui-test-manifest" } androidx-compose-ui-tooling = { module = "androidx.compose.ui:ui-tooling" } androidx-compose-ui-tooling-preview = { module = "androidx.compose.ui:ui-tooling-preview" } diff --git a/spark/build.gradle.kts b/spark/build.gradle.kts index bbc536d4f..a8bdcb74b 100644 --- a/spark/build.gradle.kts +++ b/spark/build.gradle.kts @@ -83,13 +83,13 @@ dependencies { testImplementation(libs.androidx.test.runner) testImplementation(libs.testParameterInjector) testImplementation(libs.robolectric) - testImplementation(libs.androidx.compose.ui.test) + testImplementation(libs.androidx.compose.ui.testJUnit) testImplementation(libs.androidx.compose.ui.testManifest) androidTestImplementation(libs.junit) androidTestImplementation(libs.kotlin.test) androidTestImplementation(libs.androidx.test.truth) androidTestImplementation(libs.androidx.test.runner) - androidTestImplementation(libs.androidx.compose.ui.test) + androidTestImplementation(libs.androidx.compose.ui.testJUnit) androidTestImplementation(libs.androidx.compose.ui.testManifest) }