Skip to content

Commit 079c9ca

Browse files
committed
Add ExposedDropDownMenuBoxItemTest
1 parent f07682b commit 079c9ca

File tree

2 files changed

+70
-3
lines changed

2 files changed

+70
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Copyright 2025 Google LLC
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+
* http://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.google.android.fhir.datacapture.test.views.compose
18+
19+
import android.content.Context
20+
import androidx.compose.ui.Modifier
21+
import androidx.compose.ui.test.assertIsDisplayed
22+
import androidx.compose.ui.test.junit4.createComposeRule
23+
import androidx.compose.ui.test.onNodeWithContentDescription
24+
import androidx.compose.ui.test.onNodeWithTag
25+
import androidx.compose.ui.test.performClick
26+
import androidx.core.content.ContextCompat
27+
import androidx.test.core.app.ApplicationProvider
28+
import androidx.test.ext.junit.runners.AndroidJUnit4
29+
import com.google.android.fhir.datacapture.R
30+
import com.google.android.fhir.datacapture.views.compose.DROP_DOWN_TEXT_FIELD_TAG
31+
import com.google.android.fhir.datacapture.views.compose.ExposedDropDownMenuBoxItem
32+
import com.google.android.fhir.datacapture.views.factories.DropDownAnswerOption
33+
import org.junit.Rule
34+
import org.junit.Test
35+
import org.junit.runner.RunWith
36+
37+
@RunWith(AndroidJUnit4::class)
38+
class ExposedDropDownMenuBoxItemTest {
39+
40+
@get:Rule val composeTestRule = createComposeRule()
41+
42+
val context: Context = ApplicationProvider.getApplicationContext()
43+
44+
@Test
45+
fun shouldShowLeadingIconForDropDownOptions() {
46+
val testDropDownAnswerOption =
47+
DropDownAnswerOption(
48+
answerId = "",
49+
answerOptionString = "Test Option",
50+
answerOptionImage = ContextCompat.getDrawable(context, R.drawable.ic_image_file),
51+
)
52+
53+
composeTestRule.setContent {
54+
ExposedDropDownMenuBoxItem(
55+
modifier = Modifier,
56+
enabled = true,
57+
options = listOf(testDropDownAnswerOption),
58+
onDropDownAnswerOptionSelected = {},
59+
)
60+
}
61+
62+
composeTestRule.onNodeWithTag(DROP_DOWN_TEXT_FIELD_TAG).performClick()
63+
composeTestRule
64+
.onNodeWithContentDescription(testDropDownAnswerOption.answerOptionString)
65+
.assertIsDisplayed()
66+
}
67+
}

datacapture/src/main/java/com/google/android/fhir/datacapture/extensions/MoreQuestionnaireItemAnswerOptionComponents.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2022-2025 Google LLC
2+
* Copyright 2022-2023 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,8 +18,8 @@ package com.google.android.fhir.datacapture.extensions
1818

1919
import android.content.Context
2020
import android.graphics.BitmapFactory
21+
import android.graphics.drawable.BitmapDrawable
2122
import android.graphics.drawable.Drawable
22-
import androidx.core.graphics.drawable.toDrawable
2323
import com.google.android.fhir.datacapture.R
2424
import org.hl7.fhir.r4.model.Attachment
2525
import org.hl7.fhir.r4.model.BooleanType
@@ -63,7 +63,7 @@ fun Questionnaire.QuestionnaireItemAnswerOptionComponent.itemAnswerOptionImage(
6363
val bitmap = BitmapFactory.decodeByteArray(it.data, 0, it.data.size)
6464
val imageSize =
6565
context.resources.getDimensionPixelOffset(R.dimen.item_answer_media_image_size)
66-
val drawable: Drawable = bitmap.toDrawable(context.resources)
66+
val drawable: Drawable = BitmapDrawable(context.resources, bitmap)
6767
drawable.setBounds(0, 0, imageSize, imageSize)
6868
drawable
6969
}

0 commit comments

Comments
 (0)