-
Notifications
You must be signed in to change notification settings - Fork 299
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
Slider Question functionality added #287
Conversation
Thanks @MuhammadSalman-7214! Can you please always make sure to link to the issue this PR is addressing (and close the issue after this is merged). @joiskash do you have bandwidth to take a look at this? Thanks! |
Sure I'll have a look at this PR |
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.
Add tests in the QuestionnaireItemAdapterTest and address the comments below :)
android:id="@+id/slider" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:valueFrom="0.0" |
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.
I think these values should not be hardcoded. They must be obtained from the Questionnaire from sliderStepValue , maxValue & minValue. If not specified in the questionnaire then they must be in values.xml (?) @jingtang10 please comment
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.
currently these values should remain hard coded as discussed with @jingtang10, and for their values, I am not able to find values.xml currently in the code
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.
don't hardcode these in the xml file. hardcode these in the kotlin files.
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.
done @jingtang10
) {} | ||
) | ||
|
||
Truth.assertThat(viewHolder.itemView.findViewById<TextView>(R.id.slider_header).text) |
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.
Can we import com.google.common.truth.Truth.assertThat and just use assertThat? Just to keep it consistent with all the other Unit tests that have already been written
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.
sure
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.
please comment again once done.
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.
done @jingtang10
} | ||
|
||
@Test | ||
fun singleAnswerOrNull_singleAnswer_shouldReturnSingleAnswer() { |
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.
You have to write tests verifying that the slider is working as it is supposed to . Check the answerFalse_shouldSetCheckBoxUnchecked
unit test in QuestionnaireItemCheckBoxViewHolderFactoryInstrumentedTest to get a better understanding. The assert statement should use the value returned from the viewHolder.findViewById(R.id.slider)
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.
okay
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.
please comment again once done.
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.
done @jingtang10
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.
Please see https://github.com/google/android-fhir/blob/master/datacapture/src/androidTest/java/com/google/android/fhir/datacapture/views/QuestionnaireItemEditTextSingleLineViewHolderFactoryInstrumentedTest.kt. So there're two types of test cases, you have the ones that update the UI, and you have the ones that change the UI and update the questionnaire respoonse.
so you'll need to add at least another test case that tests the answer is set after you modify the slider.
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.
Done
val questionnaireItem = questionnaireItemViewItem.questionnaireItem | ||
val answer = questionnaireItemViewItem.singleAnswerOrNull | ||
sliderHeader.text = questionnaireItem.text.value | ||
val sliderValue = answer?.value?.integer?.value?.toString() ?: "0.0" |
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.
This cant be hardcoded.. imagine if the slider is from 5 to 10
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.
for now, this is hard coded, will create a new issue for this as discussed with @jingtang10 to read values from extensions
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.
yes i think we'll have to do this in a follow up and especially considering the ongoing work in #224
.setInteger(Integer.newBuilder().setValue(newValue.toInt()) | ||
.build()).build() | ||
|
||
questionnaireItemViewItem.singleAnswerOrNull = this |
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.
can you make this questionnaireItemViewItem.singleAnswerOrNull =
for better readability
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.
sorry, not understanding this. Can you explain this?
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.
instead of questionnaireItemViewItem.singleAnswerOrNull = this
inside the apply block can you refactor such that it is something like this
questionnaireItemViewItem.singleAnswerOrNull = QuestionnaireResponse.Item.Answer.newBuilder().apply { value = .... }
You can refer to the other factories to find this pattern
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.
@joiskash but this is already doing the same way as QuestionnaireResponse.Item.Answer.newBuilder().apply in the code
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.
Yes it is the same thing. Just suggesting to maintain uniformity in the code. Also why is the callback called inside apply?
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.
do not set questionnaireItemViewItem.singleAnswerOrNull
inside the apply
also keep questionnaireItemViewItem.questionnaireResponseItemChangedCallback()
outside of apply
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.
Done
@jingtang10 and @joiskash made the requested changes, please check, thanks. |
} | ||
|
||
@Test | ||
fun singleAnswerOrNull_singleAnswer_shouldReturnSingleAnswer() { |
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.
Please see https://github.com/google/android-fhir/blob/master/datacapture/src/androidTest/java/com/google/android/fhir/datacapture/views/QuestionnaireItemEditTextSingleLineViewHolderFactoryInstrumentedTest.kt. So there're two types of test cases, you have the ones that update the UI, and you have the ones that change the UI and update the questionnaire respoonse.
so you'll need to add at least another test case that tests the answer is set after you modify the slider.
} | ||
|
||
@Test | ||
fun singleAnswerOrNull_singleAnswer_shouldReturnSingleAnswer() { |
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.
fun singleAnswerOrNull_singleAnswer_shouldReturnSingleAnswer() { | |
fun shouldSetSliderValue() { |
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.
Done
} | ||
|
||
@Test | ||
fun singleAnswerOrNull_multipleAnswers_shouldReturnNull() { |
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.
fun singleAnswerOrNull_multipleAnswers_shouldReturnNull() { | |
fun shouldSetSliderValueToDefault() { |
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.
Done
.setInteger(Integer.newBuilder().setValue(newValue.toInt()) | ||
.build()).build() | ||
|
||
questionnaireItemViewItem.singleAnswerOrNull = this |
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.
do not set questionnaireItemViewItem.singleAnswerOrNull
inside the apply
also keep questionnaireItemViewItem.questionnaireResponseItemChangedCallback()
outside of apply
#287 (comment) |
thanks @MuhammadSalman-7214. I see you have moved the callback call outside of the Have you read this comment from @joiskash https://github.com/google/android-fhir/pull/287/files#r589390062 ? so maybe this is where the confusion comes from, have you read about scope functions https://kotlinlang.org/docs/scope-functions.html? you need to do the assignment outside of the apply function:
|
@jingtang10 yes I have already read about scope functions, just there was a bit confusion, but now everything is done. All other requested changes are done as well. Thanks. |
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.
thanks @MuhammadSalman-7214
your welcome @jingtang10 👍 |
#294 has been merged. So please rebase your branch onto |
# Conflicts: # datacapture/src/main/java/com/google/android/fhir/datacapture/MoreQuestionnaireItemExtensions.kt # datacapture/src/main/java/com/google/android/fhir/datacapture/QuestionnaireItemAdapter.kt # datacapture/src/main/java/com/google/android/fhir/datacapture/QuestionnaireItemViewHolderType.kt # datacapture/src/test/java/com/google/android/fhir/datacapture/QuestionnaireItemViewHolderTypeTest.kt
…ogle/android-fhir into ms/add-handle-slider-question
Because all the changes have been done already
No description provided.