-
Notifications
You must be signed in to change notification settings - Fork 302
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Populate initial value from dropdown list for questionnaire items with type reference #2065
Merged
Merged
Changes from 25 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
cc22d43
set the initial value using the initial expression extension for refe…
omarismail94 3870224
Allow developers to add custom search parameter to the engine. (#1778)
aditya-07 dfe0f8d
Show submit button in review mode. (#1826)
aditya-07 551209d
Fix for removing old indexes when resource is updated (#1840)
aditya-07 87d2f5a
Merge remote-tracking branch 'upstream/master' into answerExpression
omarismail94 a2e4cde
Merge remote-tracking branch 'upstream/master' into answerExpression
omarismail94 f137a90
Merge remote-tracking branch 'upstream/master' into answerExpression
omarismail94 4d2c62a
add datacapture config in demo app
omarismail94 75bc566
Merge remote-tracking branch 'upstream/master' into answerExpression
LZRS 4886ba2
Merge remote-tracking branch 'upstream/master' into answerExpression
LZRS 2a32685
Merge remote-tracking branch 'upstream/master' into answerExpression
LZRS b6283f8
Merge remote-tracking branch 'upstream/master' into answerExpression
LZRS 2f76ca3
Fix dropdown initial selection for answerOptions of type Reference
LZRS 8700742
Support expression evaluating to ResourceType for items of type Refer…
LZRS 08c0a0a
Merge branch 'master' into answerExpression
LZRS 1639a7d
Merge remote-tracking branch 'upstream/master' into answerExpression
LZRS bdd7363
Merge remote-tracking branch 'upstream/master' into answerExpression
LZRS 6de72b7
Update autocompleteTextView to check answerId
LZRS 4674086
Add AutoCompleteViewHolderFactory ui tests
LZRS 7f39ec3
Merge remote-tracking branch 'upstream/master' into answerExpression
LZRS f38e6f3
Fix failing tests for AutoCompleteViewHolderFactory
LZRS 4fed0f7
Merge branch 'master' into answerExpression
LZRS f214488
Refactor MoreTypes.kt to remove duplications
LZRS d4ab2a9
Refactor evaluation of questionnaireItem initial value
LZRS 6b576ec
Merge remote-tracking branch 'upstream/master' into answerExpression
LZRS 84537e2
Fix AutoCompleteTextViewFactory espresso test failing in api 24
LZRS 9d2d603
Merge branch 'master' into answerExpression
LZRS File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
160 changes: 160 additions & 0 deletions
160
...gle/android/fhir/datacapture/views/factories/AutoCompleteViewHolderFactoryEspressoTest.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,160 @@ | ||
/* | ||
* Copyright 2023 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.factories | ||
|
||
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 | ||
import androidx.test.espresso.matcher.RootMatchers | ||
import androidx.test.espresso.matcher.ViewMatchers | ||
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.test.TestActivity | ||
import com.google.android.fhir.datacapture.validation.NotValidated | ||
import com.google.android.fhir.datacapture.views.QuestionnaireViewItem | ||
import com.google.android.material.chip.ChipGroup | ||
import com.google.android.material.textfield.MaterialAutoCompleteTextView | ||
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 AutoCompleteViewHolderFactoryEspressoTest { | ||
@Rule | ||
@JvmField | ||
var activityScenarioRule: ActivityScenarioRule<TestActivity> = | ||
ActivityScenarioRule(TestActivity::class.java) | ||
|
||
private lateinit var parent: FrameLayout | ||
private lateinit var viewHolder: QuestionnaireItemViewHolder | ||
|
||
@Before | ||
fun setup() { | ||
activityScenarioRule.scenario.onActivity { activity -> parent = FrameLayout(activity) } | ||
viewHolder = AutoCompleteViewHolderFactory.create(parent) | ||
setTestLayout(viewHolder.itemView) | ||
} | ||
|
||
@Test | ||
fun shouldReturnFilteredDropDownMenuItems() { | ||
val questionnaireViewItem = | ||
QuestionnaireViewItem( | ||
answerOptions(false, "Coding 1", "Coding 2", "Coding 3", "Coding 4", "Coding 5"), | ||
responseOptions(), | ||
validationResult = NotValidated, | ||
answersChangedCallback = { _, _, _, _ -> }, | ||
) | ||
runOnUI { viewHolder.bind(questionnaireViewItem) } | ||
|
||
onView(ViewMatchers.withId(R.id.autoCompleteTextView)).perform(ViewActions.typeText("Coding 1")) | ||
assertThat( | ||
viewHolder.itemView | ||
.findViewById<MaterialAutoCompleteTextView>(R.id.autoCompleteTextView) | ||
.adapter.count | ||
) | ||
.isEqualTo(1) | ||
} | ||
|
||
@Test | ||
fun shouldAddDropDownValueSelectedForMultipleAnswersAutoCompleteTextView() { | ||
var answerHolder: List<QuestionnaireResponse.QuestionnaireResponseItemAnswerComponent>? = null | ||
val questionnaireViewItem = | ||
QuestionnaireViewItem( | ||
answerOptions(true, "Coding 1", "Coding 2", "Coding 3", "Coding 4", "Coding 5"), | ||
responseOptions("Coding 1", "Coding 5"), | ||
validationResult = NotValidated, | ||
answersChangedCallback = { _, _, answers, _ -> answerHolder = answers }, | ||
) | ||
runOnUI { viewHolder.bind(questionnaireViewItem) } | ||
|
||
onView(ViewMatchers.withId(R.id.autoCompleteTextView)).perform(ViewActions.typeText("Coding 3")) | ||
onView(ViewMatchers.withText("Coding 3")) | ||
.inRoot(RootMatchers.isPlatformPopup()) | ||
.check(ViewAssertions.matches(ViewMatchers.isDisplayed())) | ||
.perform(ViewActions.click()) | ||
assertThat( | ||
viewHolder.itemView.findViewById<TextView>(R.id.autoCompleteTextView).text.toString() | ||
) | ||
.isEmpty() | ||
assertThat(answerHolder!!.map { it.valueCoding.display }) | ||
.containsExactly("Coding 1", "Coding 5", "Coding 3") | ||
} | ||
|
||
@Test | ||
fun shouldSetCorrectNumberOfChipsForSelectedAnswers() { | ||
val questionnaireViewItem = | ||
QuestionnaireViewItem( | ||
answerOptions(true, "Coding 1", "Coding 2", "Coding 3", "Coding 4", "Coding 5"), | ||
responseOptions("Coding 1", "Coding 5"), | ||
validationResult = NotValidated, | ||
answersChangedCallback = { _, _, _, _ -> }, | ||
) | ||
runOnUI { viewHolder.bind(questionnaireViewItem) } | ||
|
||
assertThat(viewHolder.itemView.findViewById<ChipGroup>(R.id.chipContainer).childCount) | ||
.isEqualTo(2) | ||
} | ||
|
||
/** Method to run code snippet on UI/main thread */ | ||
private fun runOnUI(action: () -> Unit) { | ||
activityScenarioRule.scenario.onActivity { action() } | ||
} | ||
|
||
/** Method to set content view for test activity */ | ||
private fun setTestLayout(view: View) { | ||
activityScenarioRule.scenario.onActivity { activity -> activity.setContentView(view) } | ||
InstrumentationRegistry.getInstrumentation().waitForIdleSync() | ||
} | ||
|
||
private fun answerOptions(repeats: Boolean, vararg options: String) = | ||
Questionnaire.QuestionnaireItemComponent().apply { | ||
this.repeats = repeats | ||
options.forEach { option -> | ||
addAnswerOption( | ||
Questionnaire.QuestionnaireItemAnswerOptionComponent().apply { | ||
value = | ||
Coding().apply { | ||
code = option.replace(" ", "_") | ||
display = option | ||
} | ||
} | ||
) | ||
} | ||
} | ||
|
||
private fun responseOptions(vararg options: String) = | ||
QuestionnaireResponse.QuestionnaireResponseItemComponent().apply { | ||
options.forEach { option -> | ||
addAnswer( | ||
QuestionnaireResponse.QuestionnaireResponseItemAnswerComponent().apply { | ||
value = | ||
Coding().apply { | ||
code = option.replace(" ", "_") | ||
display = option | ||
} | ||
} | ||
) | ||
} | ||
} | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
slightly worried we're not dealing with identify of codes carefully enough. can we make this function much more rigorous please?
for example, comparing two coding just by code but not by system doesn't meet the brief of returning "unique identifier".