3
3
package io.github.kakaocup.kakao.scroll
4
4
5
5
import android.view.View
6
+ import android.widget.HorizontalScrollView
6
7
import android.widget.ScrollView
8
+ import androidx.core.widget.NestedScrollView
7
9
import androidx.test.espresso.UiController
8
10
import androidx.test.espresso.ViewAction
9
11
import androidx.test.espresso.matcher.ViewMatchers
12
+ import androidx.test.espresso.matcher.ViewMatchers.isAssignableFrom
10
13
import io.github.kakaocup.kakao.common.actions.ScrollableActions
11
14
import io.github.kakaocup.kakao.common.actions.SwipeableActions
12
15
import org.hamcrest.Matchers
16
+ import org.hamcrest.Matchers.anyOf
13
17
14
18
/* *
15
19
* Provides ScrollableActions implementation for ScrollView
@@ -24,11 +28,20 @@ interface ScrollViewActions : ScrollableActions, SwipeableActions {
24
28
override fun getDescription () = " Scroll ScrollView to start"
25
29
26
30
override fun getConstraints () =
27
- Matchers .allOf(ViewMatchers .isAssignableFrom(ScrollView ::class .java), ViewMatchers .isDisplayed())
31
+ Matchers .allOf(
32
+ anyOf(
33
+ isAssignableFrom(ScrollView ::class .java),
34
+ isAssignableFrom(NestedScrollView ::class .java),
35
+ isAssignableFrom(HorizontalScrollView ::class .java),
36
+ ),
37
+ ViewMatchers .isDisplayed()
38
+ )
28
39
29
40
override fun perform (uiController : UiController ? , view : View ? ) {
30
- if (view is ScrollView ) {
31
- view.fullScroll(View .FOCUS_UP )
41
+ when (view) {
42
+ is ScrollView -> view.fullScroll(View .FOCUS_UP )
43
+ is NestedScrollView -> view.fullScroll(View .FOCUS_UP )
44
+ is HorizontalScrollView -> view.fullScroll(View .FOCUS_LEFT )
32
45
}
33
46
}
34
47
})
@@ -39,11 +52,20 @@ interface ScrollViewActions : ScrollableActions, SwipeableActions {
39
52
override fun getDescription () = " Scroll ScrollView to end"
40
53
41
54
override fun getConstraints () =
42
- Matchers .allOf(ViewMatchers .isAssignableFrom(ScrollView ::class .java), ViewMatchers .isDisplayed())
55
+ Matchers .allOf(
56
+ anyOf(
57
+ isAssignableFrom(ScrollView ::class .java),
58
+ isAssignableFrom(NestedScrollView ::class .java),
59
+ isAssignableFrom(HorizontalScrollView ::class .java),
60
+ ),
61
+ ViewMatchers .isDisplayed()
62
+ )
43
63
44
64
override fun perform (uiController : UiController ? , view : View ? ) {
45
- if (view is ScrollView ) {
46
- view.fullScroll(View .FOCUS_DOWN )
65
+ when (view) {
66
+ is ScrollView -> view.fullScroll(View .FOCUS_DOWN )
67
+ is NestedScrollView -> view.fullScroll(View .FOCUS_DOWN )
68
+ is HorizontalScrollView -> view.fullScroll(View .FOCUS_RIGHT )
47
69
}
48
70
}
49
71
})
@@ -54,11 +76,20 @@ interface ScrollViewActions : ScrollableActions, SwipeableActions {
54
76
override fun getDescription () = " Scroll ScrollView to $position Y position"
55
77
56
78
override fun getConstraints () =
57
- Matchers .allOf(ViewMatchers .isAssignableFrom(ScrollView ::class .java), ViewMatchers .isDisplayed())
79
+ Matchers .allOf(
80
+ anyOf(
81
+ isAssignableFrom(ScrollView ::class .java),
82
+ isAssignableFrom(NestedScrollView ::class .java),
83
+ isAssignableFrom(HorizontalScrollView ::class .java),
84
+ ),
85
+ ViewMatchers .isDisplayed()
86
+ )
58
87
59
88
override fun perform (uiController : UiController ? , view : View ? ) {
60
- if (view is ScrollView ) {
61
- view.scrollTo(0 , position)
89
+ when (view) {
90
+ is ScrollView -> view.scrollTo(0 , position)
91
+ is NestedScrollView -> view.scrollTo(0 , position)
92
+ is HorizontalScrollView -> view.scrollTo(position, 0 )
62
93
}
63
94
}
64
95
})
0 commit comments