-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Fixed clicking on the min value when there is no value yet #6524
base: master
Are you sure you want to change the base?
Conversation
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 don't think I understand the implementation. I can remove the enable
/disable
calls and no tests fail, so maybe I'm missing some edge cases that need tests?
import android.view.MotionEvent | ||
import com.google.android.material.slider.Slider | ||
|
||
fun Slider.clickOnStep(step: Float) { |
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 this should probably live in testshared
instead as it's not the kind of thing that I feel should be androidx.test:core
(which is what androidtest
is really there for).
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 | ||
public void changingSliderValueToTheMinOneWhenSliderHasNoValue_setsTheValue() { | ||
RangeDecimalWidget widget = createWidget(promptWithQuestionDefAndAnswer(rangeQuestion, null)); | ||
widget.slider.measure(100, 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.
We could add a helper for the measure
/layout
boilerplate to SliderExt
as well.
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.
It turns out widget.slider.measure(100, 10);
is not needed so I removed it.
Let me explain:
This is because I initially added tests only to cover the bug. However, the state is also used to prevent updating the value twice. As mentioned above, if the slider is already enabled, there’s no need to call the listener. I added new tests to cover that. |
Closes #6504
Why is this the best possible solution? Were any other approaches considered?
The issue arises because all our question types support a "no answer" state, whereas sliders lack this concept. To address this, we adjusted the slider's appearance but couldn't set its value outside the specified range (or provide no answer at all). For example, if the range was 1–10, the value defaulted to 1 (the minimum) when no answer was provided. As a result, clicking the minimum value didn't trigger a click event since consecutive clicks on the same value don't generate multiple value-changed events.
To resolve this, I implemented a separate interface to listen for touch events and trigger the missing event when no answer has been provided yet.
How does this change affect users? Describe intentional changes to behavior and behavior that could have accidentally been affected by code changes. In other words, what are the regression risks?
As mentioned above, the issue occurred when clicking on the minimum value with no answer provided. Please test this scenario as well as clicking on other values to ensure everything works correctly.
Do we need any specific form for testing your changes? If so, please attach one.
No.
Does this change require updates to documentation? If so, please file an issue here and include the link below.
No.
Before submitting this PR, please make sure you have:
./gradlew connectedAndroidTest
(or./gradlew testLab
) and confirmed all checks still passDateFormatsTest