Skip to content

Commit

Permalink
chore: replace deprecated Accompanist Test Harness with official `Dev…
Browse files Browse the repository at this point in the history
…iceConfigurationOverride`

Docs: https://google.github.io/accompanist/testharness/
  • Loading branch information
SimonMarquis committed Feb 21, 2024
1 parent 6231630 commit 9af18c9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 21 deletions.
2 changes: 1 addition & 1 deletion catalog/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ dependencies {

implementation(libs.airbnb.showkase)

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)
Expand Down
25 changes: 9 additions & 16 deletions catalog/src/main/kotlin/com/adevinta/spark/catalog/CatalogApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import androidx.activity.SystemBarStyle
import androidx.activity.enableEdgeToEdge
import androidx.compose.animation.core.FastOutSlowInEasing
import androidx.compose.animation.core.tween
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.PaddingValues
Expand Down Expand Up @@ -58,13 +57,16 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
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 androidx.navigation.compose.NavHost
Expand Down Expand Up @@ -96,13 +98,8 @@ import com.adevinta.spark.catalog.themes.themeprovider.leboncoin.LeboncoinTheme
import com.adevinta.spark.catalog.themes.themeprovider.milanuncios.MilanunciosTheme
import com.adevinta.spark.catalog.themes.themeprovider.subito.SubitoTheme
import com.airbnb.android.showkase.models.ShowkaseBrowserComponent
import com.google.accompanist.testharness.TestHarness
import kotlinx.coroutines.launch

@OptIn(
ExperimentalFoundationApi::class,
ExperimentalComposeUiApi::class,
)
@Composable
internal fun ComponentActivity.CatalogApp(
theme: Theme,
Expand Down Expand Up @@ -157,14 +154,10 @@ internal fun ComponentActivity.CatalogApp(
onDispose {}
}

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.fontScale.takeUnless { theme.fontScaleMode == FontScaleMode.System } ?: LocalDensity.current.fontScale),
) {
Box(
modifier = Modifier.fillMaxSize(),
Expand Down
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,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" }

airbnb-showkase = { module = "com.airbnb.android:showkase", version.ref = "showkase" }
airbnb-showkase-processor = { module = "com.airbnb.android:showkase-processor", version.ref = "showkase" }
Expand All @@ -59,7 +58,8 @@ androidx-compose-runtime-livedata = { module = "androidx.compose.runtime:runtime
androidx-compose-ui = { module = "androidx.compose.ui:ui" }
# https://developer.android.com/reference/kotlin/androidx/compose/ui/text/googlefonts/package-summary
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", version = "1.7.0-alpha02" }
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" }
Expand Down
4 changes: 2 additions & 2 deletions spark/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,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)
}

0 comments on commit 9af18c9

Please sign in to comment.