-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Empty Option added to DropDown and test cases added (#1298)
* Empty Option added to DropDown and test cases added * merged dropdown change with PR 995 * Review points addressed
- Loading branch information
1 parent
ae4c26a
commit ac93433
Showing
6 changed files
with
181 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...roidTest/java/com/google/android/fhir/datacapture/utilities/AutoCompleteTextViewAction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright 2021 Google LLC | ||
* | ||
* 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 | ||
* | ||
* http://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.google.android.fhir.datacapture.utilities | ||
|
||
import android.view.View | ||
import android.widget.AutoCompleteTextView | ||
import androidx.test.espresso.UiController | ||
import androidx.test.espresso.ViewAction | ||
import androidx.test.espresso.matcher.ViewMatchers.isAssignableFrom | ||
import androidx.test.espresso.matcher.ViewMatchers.isEnabled | ||
import org.hamcrest.Matcher | ||
import org.hamcrest.Matchers.allOf | ||
|
||
/** Show Drop Down view for AutoCompleteTextView widget. */ | ||
fun showDropDown(): ViewAction { | ||
return object : ViewAction { | ||
override fun getConstraints(): Matcher<View> = | ||
allOf(isEnabled(), isAssignableFrom(AutoCompleteTextView::class.java)) | ||
|
||
override fun getDescription(): String { | ||
return "show DropDown" | ||
} | ||
|
||
override fun perform(uiController: UiController, view: View?) { | ||
val autoCompleteTextView = view as AutoCompleteTextView | ||
autoCompleteTextView.showDropDown() | ||
uiController.loopMainThreadUntilIdle() | ||
} | ||
} | ||
} |
135 changes: 135 additions & 0 deletions
135
.../android/fhir/datacapture/views/QuestionnaireItemDropDownViewHolderFactoryEspressoTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
/* | ||
* Copyright 2021 Google LLC | ||
* | ||
* 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 | ||
* | ||
* http://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.google.android.fhir.datacapture.views | ||
|
||
import android.view.View | ||
import android.widget.FrameLayout | ||
import android.widget.TextView | ||
import androidx.test.espresso.Espresso.onView | ||
import androidx.test.espresso.action.ViewActions | ||
import androidx.test.espresso.assertion.ViewAssertions.matches | ||
import androidx.test.espresso.matcher.RootMatchers | ||
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed | ||
import androidx.test.espresso.matcher.ViewMatchers.withId | ||
import androidx.test.espresso.matcher.ViewMatchers.withText | ||
import androidx.test.ext.junit.rules.ActivityScenarioRule | ||
import androidx.test.platform.app.InstrumentationRegistry | ||
import com.google.android.fhir.datacapture.R | ||
import com.google.android.fhir.datacapture.TestActivity | ||
import com.google.android.fhir.datacapture.utilities.showDropDown | ||
import com.google.common.truth.Truth.assertThat | ||
import org.hl7.fhir.r4.model.Coding | ||
import org.hl7.fhir.r4.model.Questionnaire | ||
import org.hl7.fhir.r4.model.QuestionnaireResponse | ||
import org.junit.Before | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
class QuestionnaireItemDropDownViewHolderFactoryEspressoTest { | ||
@Rule | ||
@JvmField | ||
var activityScenarioRule: ActivityScenarioRule<TestActivity> = | ||
ActivityScenarioRule<TestActivity>(TestActivity::class.java) | ||
|
||
private lateinit var parent: FrameLayout | ||
private lateinit var viewHolder: QuestionnaireItemViewHolder | ||
|
||
@Before | ||
fun setup() { | ||
activityScenarioRule.getScenario().onActivity { activity -> parent = FrameLayout(activity) } | ||
viewHolder = QuestionnaireItemDropDownViewHolderFactory.create(parent) | ||
setTestLayout(viewHolder.itemView) | ||
} | ||
|
||
@Test | ||
fun shouldClearAutoCompleteTextView() { | ||
val questionnaireItemViewItem = | ||
QuestionnaireItemViewItem( | ||
answerOptions("Coding 1", "Coding 2", "Coding 3", "Coding 4", "Coding 5"), | ||
responseOptions() | ||
) {} | ||
runOnUI { viewHolder.bind(questionnaireItemViewItem) } | ||
|
||
onView(withId(R.id.auto_complete)).perform(showDropDown()) | ||
onView(withText("-")) | ||
.inRoot(RootMatchers.isPlatformPopup()) | ||
.check(matches(isDisplayed())) | ||
.perform(ViewActions.click()) | ||
assertThat(viewHolder.itemView.findViewById<TextView>(R.id.auto_complete).text.toString()) | ||
.isEqualTo("-") | ||
assertThat(questionnaireItemViewItem.questionnaireResponseItem.answer).isEmpty() | ||
} | ||
|
||
@Test | ||
fun shouldSetDropDownValueToAutoCompleteTextView() { | ||
val questionnaireItemViewItem = | ||
QuestionnaireItemViewItem( | ||
answerOptions("Coding 1", "Coding 2", "Coding 3", "Coding 4", "Coding 5"), | ||
responseOptions() | ||
) {} | ||
runOnUI { viewHolder.bind(questionnaireItemViewItem) } | ||
|
||
onView(withId(R.id.auto_complete)).perform(showDropDown()) | ||
onView(withText("Coding 3")) | ||
.inRoot(RootMatchers.isPlatformPopup()) | ||
.check(matches(isDisplayed())) | ||
.perform(ViewActions.click()) | ||
assertThat(viewHolder.itemView.findViewById<TextView>(R.id.auto_complete).text.toString()) | ||
.isEqualTo("Coding 3") | ||
assertThat( | ||
(questionnaireItemViewItem.questionnaireResponseItem.answer[0].value as Coding).display | ||
) | ||
.isEqualTo("Coding 3") | ||
} | ||
|
||
/** Method to run code snippet on UI/main thread */ | ||
private fun runOnUI(action: () -> Unit) { | ||
activityScenarioRule.getScenario().onActivity { activity -> action() } | ||
} | ||
|
||
/** Method to set content view for test activity */ | ||
private fun setTestLayout(view: View) { | ||
activityScenarioRule.getScenario().onActivity { activity -> activity.setContentView(view) } | ||
InstrumentationRegistry.getInstrumentation().waitForIdleSync() | ||
} | ||
|
||
private fun answerOptions(vararg options: String) = | ||
Questionnaire.QuestionnaireItemComponent().apply { | ||
options.forEach { option -> | ||
addAnswerOption( | ||
Questionnaire.QuestionnaireItemAnswerOptionComponent().apply { | ||
value = | ||
Coding().apply { | ||
code = option.replace(" ", "_") | ||
display = option | ||
} | ||
} | ||
) | ||
} | ||
} | ||
|
||
private fun responseOptions(vararg responses: String) = | ||
QuestionnaireResponse.QuestionnaireResponseItemComponent().apply { | ||
responses.forEach { response -> | ||
addAnswer( | ||
QuestionnaireResponse.QuestionnaireResponseItemAnswerComponent().apply { | ||
value = Coding().apply { display = response } | ||
} | ||
) | ||
} | ||
} | ||
} |
89 changes: 0 additions & 89 deletions
89
...m/google/android/fhir/datacapture/views/QuestionnaireItemDropDownViewHolderFactoryTest.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters