-
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?
Changes from 4 commits
9464564
45667bc
9d660a5
fde45ee
f82c55b
51de075
2789971
7c79dc4
35af2a0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.odk.collect.androidtest | ||
|
||
import android.view.MotionEvent | ||
import com.google.android.material.slider.Slider | ||
|
||
fun Slider.clickOnStep(step: Float) { | ||
val xPosition: Float = step * (width / valueTo) | ||
val yPosition: Float = height / 2f | ||
|
||
val currentTime = System.currentTimeMillis() | ||
|
||
val downEvent = MotionEvent.obtain( | ||
currentTime, | ||
currentTime, | ||
MotionEvent.ACTION_DOWN, | ||
xPosition, | ||
yPosition, | ||
0 | ||
) | ||
dispatchTouchEvent(downEvent) | ||
|
||
val upEvent = MotionEvent.obtain( | ||
currentTime, | ||
currentTime, | ||
MotionEvent.ACTION_UP, | ||
xPosition, | ||
yPosition, | ||
0 | ||
) | ||
dispatchTouchEvent(upEvent) | ||
|
||
downEvent.recycle() | ||
upEvent.recycle() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
import org.odk.collect.android.formentry.questions.QuestionDetails; | ||
import org.odk.collect.android.listeners.WidgetValueChangedListener; | ||
import org.odk.collect.android.support.MockFormEntryPromptBuilder; | ||
import org.odk.collect.androidtest.SliderExtKt; | ||
|
||
import java.math.BigDecimal; | ||
|
||
|
@@ -202,6 +203,17 @@ public void everyTriggerWidgetShouldHaveCheckboxWithUniqueID() { | |
assertThat(widget1.slider.getId(), not(equalTo(widget2.slider.getId()))); | ||
} | ||
|
||
@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 commentThe reason will be displayed to describe this comment to others. Learn more. We could add a helper for the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It turns out |
||
widget.slider.layout(0, 0, 100, 10); | ||
|
||
SliderExtKt.clickOnStep(widget.slider, 1); | ||
|
||
assertThat(widget.currentValue.getText(), equalTo("1.5")); | ||
} | ||
|
||
private RangeDecimalWidget createWidget(FormEntryPrompt prompt) { | ||
return new RangeDecimalWidget(widgetTestActivity(), new QuestionDetails(prompt)); | ||
} | ||
|
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 beandroidx.test:core
(which is whatandroidtest
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.