diff --git a/compose/snippets/src/androidTest/java/com/example/compose/snippets/deviceconfigurationoverride/DeviceConfigurationOverrideSnippets.kt b/compose/snippets/src/androidTest/java/com/example/compose/snippets/deviceconfigurationoverride/DeviceConfigurationOverrideSnippets.kt new file mode 100644 index 000000000..36db665a1 --- /dev/null +++ b/compose/snippets/src/androidTest/java/com/example/compose/snippets/deviceconfigurationoverride/DeviceConfigurationOverrideSnippets.kt @@ -0,0 +1,65 @@ +/* + * Copyright 2024 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.example.compose.snippets.deviceconfigurationoverride + +import androidx.compose.material3.Text +import androidx.compose.ui.test.DeviceConfigurationOverride +import androidx.compose.ui.test.FontScale +import androidx.compose.ui.test.FontWeightAdjustment +import androidx.compose.ui.test.ForcedSize +import androidx.compose.ui.test.junit4.createComposeRule +import androidx.compose.ui.test.then +import androidx.compose.ui.unit.DpSize +import androidx.compose.ui.unit.dp +import com.example.compose.snippets.interop.MyScreen +import org.junit.Ignore +import org.junit.Rule +import org.junit.Test + +class DeviceConfigurationOverrideSnippetsTest { + @get:Rule + val composeTestRule = createComposeRule() + + @Ignore("Snippet test") + @Test + fun forcedSize() { + // [START android_compose_deviceconfigurationoverride_forcedsize] + composeTestRule.setContent { + DeviceConfigurationOverride( + DeviceConfigurationOverride.ForcedSize(DpSize(1280.dp, 800.dp)) + ) { + MyScreen() // will be rendered in the space for 1280dp by 800dp without clipping + } + } + // [END android_compose_deviceconfigurationoverride_forcedsize] + } + + @Ignore("Snippet test") + @Test + fun then() { + // [START android_compose_deviceconfigurationoverride_then] + composeTestRule.setContent { + DeviceConfigurationOverride( + DeviceConfigurationOverride.FontScale(1.5f) then + DeviceConfigurationOverride.FontWeightAdjustment(200) + ) { + Text(text = "text with increased scale and weight") + } + } + // [END android_compose_deviceconfigurationoverride_then] + } +} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 035b5f151..068d1cb8a 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -4,6 +4,7 @@ androidGradlePlugin = "8.2.2" androidx-activity-compose = "1.9.0-alpha03" androidx-appcompat = "1.6.1" androidx-compose-bom = "2024.02.01" +androidx-compose-ui-test = "1.7.0-alpha03" # TODO: Remove once 1.7 is stable androidx-constraintlayout = "2.1.4" androidx-constraintlayout-compose = "1.0.1" androidx-coordinator-layout = "1.2.0" @@ -68,7 +69,7 @@ androidx-compose-runtime-livedata = { module = "androidx.compose.runtime:runtime androidx-compose-ui = { module = "androidx.compose.ui:ui" } androidx-compose-ui-googlefonts = { module = "androidx.compose.ui:ui-text-google-fonts" } androidx-compose-ui-graphics = { module = "androidx.compose.ui:ui-graphics" } -androidx-compose-ui-test = { module = "androidx.compose.ui:ui-test" } +androidx-compose-ui-test = { module = "androidx.compose.ui:ui-test", version.ref = "androidx-compose-ui-test" } androidx-compose-ui-test-junit4 = { module = "androidx.compose.ui:ui-test-junit4" } androidx-compose-ui-test-manifest = { module = "androidx.compose.ui:ui-test-manifest" } androidx-compose-ui-tooling = { module = "androidx.compose.ui:ui-tooling" }