|
| 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 | +} |
0 commit comments