diff --git a/kakao/src/main/kotlin/io/github/kakaocup/kakao/scroll/ScrollViewActions.kt b/kakao/src/main/kotlin/io/github/kakaocup/kakao/scroll/ScrollViewActions.kt index 354bae743..deeb0dd98 100644 --- a/kakao/src/main/kotlin/io/github/kakaocup/kakao/scroll/ScrollViewActions.kt +++ b/kakao/src/main/kotlin/io/github/kakaocup/kakao/scroll/ScrollViewActions.kt @@ -3,13 +3,17 @@ package io.github.kakaocup.kakao.scroll import android.view.View +import android.widget.HorizontalScrollView import android.widget.ScrollView +import androidx.core.widget.NestedScrollView import androidx.test.espresso.UiController import androidx.test.espresso.ViewAction import androidx.test.espresso.matcher.ViewMatchers +import androidx.test.espresso.matcher.ViewMatchers.isAssignableFrom import io.github.kakaocup.kakao.common.actions.ScrollableActions import io.github.kakaocup.kakao.common.actions.SwipeableActions import org.hamcrest.Matchers +import org.hamcrest.Matchers.anyOf /** * Provides ScrollableActions implementation for ScrollView @@ -24,11 +28,20 @@ interface ScrollViewActions : ScrollableActions, SwipeableActions { override fun getDescription() = "Scroll ScrollView to start" override fun getConstraints() = - Matchers.allOf(ViewMatchers.isAssignableFrom(ScrollView::class.java), ViewMatchers.isDisplayed()) + Matchers.allOf( + anyOf( + isAssignableFrom(ScrollView::class.java), + isAssignableFrom(NestedScrollView::class.java), + isAssignableFrom(HorizontalScrollView::class.java), + ), + ViewMatchers.isDisplayed() + ) override fun perform(uiController: UiController?, view: View?) { - if (view is ScrollView) { - view.fullScroll(View.FOCUS_UP) + when (view) { + is ScrollView -> view.fullScroll(View.FOCUS_UP) + is NestedScrollView -> view.fullScroll(View.FOCUS_UP) + is HorizontalScrollView -> view.fullScroll(View.FOCUS_LEFT) } } }) @@ -39,11 +52,20 @@ interface ScrollViewActions : ScrollableActions, SwipeableActions { override fun getDescription() = "Scroll ScrollView to end" override fun getConstraints() = - Matchers.allOf(ViewMatchers.isAssignableFrom(ScrollView::class.java), ViewMatchers.isDisplayed()) + Matchers.allOf( + anyOf( + isAssignableFrom(ScrollView::class.java), + isAssignableFrom(NestedScrollView::class.java), + isAssignableFrom(HorizontalScrollView::class.java), + ), + ViewMatchers.isDisplayed() + ) override fun perform(uiController: UiController?, view: View?) { - if (view is ScrollView) { - view.fullScroll(View.FOCUS_DOWN) + when (view) { + is ScrollView -> view.fullScroll(View.FOCUS_DOWN) + is NestedScrollView -> view.fullScroll(View.FOCUS_DOWN) + is HorizontalScrollView -> view.fullScroll(View.FOCUS_RIGHT) } } }) @@ -54,11 +76,20 @@ interface ScrollViewActions : ScrollableActions, SwipeableActions { override fun getDescription() = "Scroll ScrollView to $position Y position" override fun getConstraints() = - Matchers.allOf(ViewMatchers.isAssignableFrom(ScrollView::class.java), ViewMatchers.isDisplayed()) + Matchers.allOf( + anyOf( + isAssignableFrom(ScrollView::class.java), + isAssignableFrom(NestedScrollView::class.java), + isAssignableFrom(HorizontalScrollView::class.java), + ), + ViewMatchers.isDisplayed() + ) override fun perform(uiController: UiController?, view: View?) { - if (view is ScrollView) { - view.scrollTo(0, position) + when (view) { + is ScrollView -> view.scrollTo(0, position) + is NestedScrollView -> view.scrollTo(0, position) + is HorizontalScrollView -> view.scrollTo(position, 0) } } }) diff --git a/sample/src/androidTest/kotlin/io/github/kakaocup/sample/HorizontalScrollTest.kt b/sample/src/androidTest/kotlin/io/github/kakaocup/sample/HorizontalScrollTest.kt new file mode 100644 index 000000000..a31ea17f4 --- /dev/null +++ b/sample/src/androidTest/kotlin/io/github/kakaocup/sample/HorizontalScrollTest.kt @@ -0,0 +1,33 @@ +package io.github.kakaocup.sample + +import androidx.test.ext.junit.rules.ActivityScenarioRule +import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner +import io.github.kakaocup.kakao.screen.Screen.Companion.onScreen +import io.github.kakaocup.sample.screen.ScrollScreen +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith + + +@RunWith(AndroidJUnit4ClassRunner::class) +class HorizontalScrollTest { + @Rule + @JvmField + val rule = ActivityScenarioRule(HorizontalScrollActivity::class.java) + + @Test + fun test() { + onScreen { + checkStart() + scroll { scrollToEnd() } + checkEnd() + + scroll { scrollToStart() } + checkStart() + + scroll { scrollTo(5000) } + checkEnd() + } + } +} + diff --git a/sample/src/androidTest/kotlin/io/github/kakaocup/sample/NestedScrollTest.kt b/sample/src/androidTest/kotlin/io/github/kakaocup/sample/NestedScrollTest.kt new file mode 100644 index 000000000..07b7b90e5 --- /dev/null +++ b/sample/src/androidTest/kotlin/io/github/kakaocup/sample/NestedScrollTest.kt @@ -0,0 +1,33 @@ +package io.github.kakaocup.sample + +import androidx.test.ext.junit.rules.ActivityScenarioRule +import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner +import io.github.kakaocup.kakao.screen.Screen.Companion.onScreen +import io.github.kakaocup.sample.screen.ScrollScreen +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith + + +@RunWith(AndroidJUnit4ClassRunner::class) +class NestedScrollTest { + @Rule + @JvmField + val rule = ActivityScenarioRule(NestedScrollActivity::class.java) + + @Test + fun test() { + onScreen { + checkStart() + scroll { scrollToEnd() } + checkEnd() + + scroll { scrollToStart() } + checkStart() + + scroll { scrollTo(5000) } + checkEnd() + } + } +} + diff --git a/sample/src/androidTest/kotlin/io/github/kakaocup/sample/ScrollTest.kt b/sample/src/androidTest/kotlin/io/github/kakaocup/sample/ScrollTest.kt new file mode 100644 index 000000000..549ea6cbb --- /dev/null +++ b/sample/src/androidTest/kotlin/io/github/kakaocup/sample/ScrollTest.kt @@ -0,0 +1,33 @@ +package io.github.kakaocup.sample + +import androidx.test.ext.junit.rules.ActivityScenarioRule +import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner +import io.github.kakaocup.kakao.screen.Screen.Companion.onScreen +import io.github.kakaocup.sample.screen.ScrollScreen +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith + + +@RunWith(AndroidJUnit4ClassRunner::class) +class ScrollTest { + @Rule + @JvmField + val rule = ActivityScenarioRule(ScrollActivity::class.java) + + @Test + fun test() { + onScreen { + checkStart() + scroll { scrollToEnd() } + checkEnd() + + scroll { scrollToStart() } + checkStart() + + scroll { scrollTo(5000) } + checkEnd() + } + } +} + diff --git a/sample/src/androidTest/kotlin/io/github/kakaocup/sample/screen/ScrollScreen.kt b/sample/src/androidTest/kotlin/io/github/kakaocup/sample/screen/ScrollScreen.kt new file mode 100644 index 000000000..d105ca786 --- /dev/null +++ b/sample/src/androidTest/kotlin/io/github/kakaocup/sample/screen/ScrollScreen.kt @@ -0,0 +1,33 @@ +package io.github.kakaocup.sample.screen + +import io.github.kakaocup.kakao.screen.Screen +import io.github.kakaocup.kakao.scroll.KScrollView +import io.github.kakaocup.kakao.text.KTextView +import io.github.kakaocup.sample.R + + +class ScrollScreen : Screen() { + val firstElement = KTextView { withId(R.id.first_element) } + val secondElement = KTextView { withId(R.id.second_element) } + val scroll = KScrollView { withId(R.id.scroll) } + + fun checkStart() { + idle(1000) + firstElement { + isDisplayed() + } + secondElement { + isNotDisplayed() + } + } + + fun checkEnd() { + idle(1000) + firstElement { + isNotDisplayed() + } + secondElement { + isDisplayed() + } + } +} diff --git a/sample/src/main/AndroidManifest.xml b/sample/src/main/AndroidManifest.xml index fb965d86a..afb8c0a35 100644 --- a/sample/src/main/AndroidManifest.xml +++ b/sample/src/main/AndroidManifest.xml @@ -39,6 +39,18 @@ android:name="io.github.kakaocup.sample.NestedRecyclerActivity" android:label="Nested Recycler Activity" android:theme="@style/AppTheme" /> + + + + + + + + + + + + + + + + + diff --git a/sample/src/main/res/layout/activity_nested_scroll.xml b/sample/src/main/res/layout/activity_nested_scroll.xml new file mode 100644 index 000000000..b9fe22237 --- /dev/null +++ b/sample/src/main/res/layout/activity_nested_scroll.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + diff --git a/sample/src/main/res/layout/activity_scroll.xml b/sample/src/main/res/layout/activity_scroll.xml new file mode 100644 index 000000000..9615b6724 --- /dev/null +++ b/sample/src/main/res/layout/activity_scroll.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + +