Skip to content

Commit d60bf2d

Browse files
authored
Merge branch 'main' into askandroid/snippet-migration
2 parents f564001 + 0ce9349 commit d60bf2d

File tree

6 files changed

+70
-0
lines changed

6 files changed

+70
-0
lines changed

compose/snippets/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,6 @@ dependencies {
163163
androidTestImplementation(libs.androidx.compose.ui.test.junit4.accessibility)
164164
debugImplementation(libs.androidx.compose.ui.test.manifest)
165165

166+
androidTestImplementation(libs.androidx.glance.testing)
167+
androidTestImplementation(libs.androidx.glance.appwidget.testing)
166168
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright 2025 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.compose.snippets.glance
18+
19+
import androidx.compose.runtime.Composable
20+
import androidx.glance.GlanceModifier
21+
import androidx.glance.appwidget.testing.unit.runGlanceAppWidgetUnitTest
22+
import androidx.glance.layout.Row
23+
import androidx.glance.semantics.semantics
24+
import androidx.glance.semantics.testTag
25+
import androidx.glance.testing.unit.assertHasText
26+
import androidx.glance.testing.unit.hasTestTag
27+
import androidx.glance.text.Text
28+
import org.junit.Test
29+
30+
// [START android_compose_glance_unit_test]
31+
private const val FAKE_HEADLINE = "EXTRA! EXTRA! READ ALL ABOUT IT!"
32+
33+
class MyGlanceComposableTest {
34+
@Test
35+
fun myNewsItemComposable_largeSize_hasHeadline() = runGlanceAppWidgetUnitTest {
36+
// Set the composable to test
37+
provideComposable {
38+
MyNewsItemComposable(FAKE_HEADLINE)
39+
}
40+
41+
// Perform assertions
42+
onNode(hasTestTag("headline"))
43+
.assertHasText(FAKE_HEADLINE)
44+
}
45+
46+
47+
@Composable
48+
fun MyNewsItemComposable(headline: String) {
49+
Row {
50+
Text(
51+
text = headline,
52+
modifier = GlanceModifier.semantics { testTag = "headline" },
53+
)
54+
}
55+
}
56+
}
57+
// [END android_compose_glance_unit_test]

gradle/libs.versions.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ androidx-emoji2-views = { module = "androidx.emoji2:emoji2-views", version.ref =
126126
androidx-fragment-ktx = { module = "androidx.fragment:fragment-ktx", version.ref = "androidx-fragment-ktx" }
127127
androidx-glance-appwidget = { module = "androidx.glance:glance-appwidget", version.ref = "androidx-glance-appwidget" }
128128
androidx-glance-material3 = { module = "androidx.glance:glance-material3", version.ref = "androidx-glance-appwidget" }
129+
androidx-glance-testing = { group = "androidx.glance", name = "glance-testing", version.ref = "androidx-glance-appwidget" }
130+
androidx-glance-appwidget-testing = { group = "androidx.glance", name = "glance-appwidget-testing", version.ref = "androidx-glance-appwidget" }
129131
androidx-graphics-shapes = "androidx.graphics:graphics-shapes:1.0.1"
130132
androidx-hilt-navigation-compose = { module = "androidx.hilt:hilt-navigation-compose", version.ref = "androidxHiltNavigationCompose" }
131133
androidx-lifecycle-runtime = { module = "androidx.lifecycle:lifecycle-runtime-ktx", version.ref = "androidx-lifecycle-runtime-compose" }

xr/src/main/java/com/example/xr/arcore/Anchors.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import androidx.xr.arcore.AnchorCreateSuccess
2121
import androidx.xr.arcore.Trackable
2222
import androidx.xr.runtime.Config
2323
import androidx.xr.runtime.Session
24+
import androidx.xr.runtime.SessionConfigureConfigurationNotSupported
2425
import androidx.xr.runtime.SessionConfigureSuccess
2526
import androidx.xr.runtime.math.Pose
2627
import androidx.xr.scenecore.AnchorEntity
@@ -34,6 +35,8 @@ fun configureAnchoring(session: Session) {
3435
)
3536
when (val result = session.configure(newConfig)) {
3637
is SessionConfigureSuccess -> TODO(/* Success! */)
38+
is SessionConfigureConfigurationNotSupported ->
39+
TODO(/* Some combinations of configurations are not valid. Handle this failure case. */)
3740
else ->
3841
TODO(/* The session could not be configured. See SessionConfigureResult for possible causes. */)
3942
}

xr/src/main/java/com/example/xr/arcore/Hands.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import androidx.xr.arcore.Hand
2323
import androidx.xr.arcore.HandJointType
2424
import androidx.xr.runtime.Config
2525
import androidx.xr.runtime.Session
26+
import androidx.xr.runtime.SessionConfigureConfigurationNotSupported
2627
import androidx.xr.runtime.SessionConfigureSuccess
2728
import androidx.xr.runtime.math.Pose
2829
import androidx.xr.runtime.math.Quaternion
@@ -40,6 +41,8 @@ fun ComponentActivity.configureSession(session: Session) {
4041
)
4142
when (val result = session.configure(newConfig)) {
4243
is SessionConfigureSuccess -> TODO(/* Success! */)
44+
is SessionConfigureConfigurationNotSupported ->
45+
TODO(/* Some combinations of configurations are not valid. Handle this failure case. */)
4346
else ->
4447
TODO(/* The session could not be configured. See SessionConfigureResult for possible causes. */)
4548
}

xr/src/main/java/com/example/xr/arcore/Planes.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package com.example.xr.arcore
1919
import androidx.xr.arcore.Plane
2020
import androidx.xr.runtime.Config
2121
import androidx.xr.runtime.Session
22+
import androidx.xr.runtime.SessionConfigureConfigurationNotSupported
2223
import androidx.xr.runtime.SessionConfigureSuccess
2324
import androidx.xr.runtime.math.Pose
2425
import androidx.xr.runtime.math.Ray
@@ -31,6 +32,8 @@ fun configurePlaneTracking(session: Session) {
3132
)
3233
when (val result = session.configure(newConfig)) {
3334
is SessionConfigureSuccess -> TODO(/* Success! */)
35+
is SessionConfigureConfigurationNotSupported ->
36+
TODO(/* Some combinations of configurations are not valid. Handle this failure case. */)
3437
else ->
3538
TODO(/* The session could not be configured. See SessionConfigureResult for possible causes. */)
3639
}

0 commit comments

Comments
 (0)