diff --git a/kakao/src/main/kotlin/io/github/kakaocup/kakao/common/matchers/SwitcherCurrentViewMatcher.kt b/kakao/src/main/kotlin/io/github/kakaocup/kakao/common/matchers/SwitcherCurrentViewMatcher.kt new file mode 100644 index 000000000..74d60fb89 --- /dev/null +++ b/kakao/src/main/kotlin/io/github/kakaocup/kakao/common/matchers/SwitcherCurrentViewMatcher.kt @@ -0,0 +1,21 @@ +@file:Suppress("unused") + +package io.github.kakaocup.kakao.common.matchers + +import android.view.View +import android.widget.ViewSwitcher +import androidx.test.espresso.matcher.BoundedMatcher +import org.hamcrest.Description + +/** + * Matches current view in View Switcher + */ +class SwitcherCurrentViewMatcher : BoundedMatcher(View::class.java) { + override fun matchesSafely(view: View?) = view?.let { + (it.parent as ViewSwitcher).currentView.equals(it) + } ?: false + + override fun describeTo(description: Description) { + description.appendText("Can't match current view for Switcher") + } +} diff --git a/kakao/src/main/kotlin/io/github/kakaocup/kakao/common/matchers/ViewGroupPositionMatcher.kt b/kakao/src/main/kotlin/io/github/kakaocup/kakao/common/matchers/ViewGroupPositionMatcher.kt index 741f7cf4f..79a067f06 100644 --- a/kakao/src/main/kotlin/io/github/kakaocup/kakao/common/matchers/ViewGroupPositionMatcher.kt +++ b/kakao/src/main/kotlin/io/github/kakaocup/kakao/common/matchers/ViewGroupPositionMatcher.kt @@ -21,4 +21,3 @@ class ViewGroupPositionMatcher(private val position: Int) : BoundedMatcher { + textSwitcher { + hasText("Counter: 1") + } + + nextButton.click() + + textSwitcher { + hasText("Counter: 2") + } + } + } +} diff --git a/sample/src/androidTest/kotlin/io/github/kakaocup/sample/screen/SwitchersScreen.kt b/sample/src/androidTest/kotlin/io/github/kakaocup/sample/screen/SwitchersScreen.kt new file mode 100644 index 000000000..d5d024778 --- /dev/null +++ b/sample/src/androidTest/kotlin/io/github/kakaocup/sample/screen/SwitchersScreen.kt @@ -0,0 +1,23 @@ +package io.github.kakaocup.sample.screen + +import io.github.kakaocup.kakao.common.matchers.SwitcherCurrentViewMatcher +import io.github.kakaocup.kakao.screen.Screen +import io.github.kakaocup.kakao.text.KButton +import io.github.kakaocup.kakao.text.KTextView +import io.github.kakaocup.sample.R + +class SwitchersScreen : Screen() { + val textSwitcher: KTextView + get() { + return KTextView { + withParent { + withId(R.id.text_switcher) + } + withMatcher(SwitcherCurrentViewMatcher()) + } + } + + val nextButton = KButton { + withId(R.id.next) + } +} diff --git a/sample/src/main/AndroidManifest.xml b/sample/src/main/AndroidManifest.xml index cc4d9969d..44cb7bfdb 100644 --- a/sample/src/main/AndroidManifest.xml +++ b/sample/src/main/AndroidManifest.xml @@ -87,7 +87,10 @@ android:name="io.github.kakaocup.sample.TabLayoutActivity" android:label="Tab Layout Activity" android:theme="@style/MaterialAppTheme" /> - + (R.id.snackbar_button).setOnClickListener { val snackbar = Snackbar.make( diff --git a/sample/src/main/res/layout/activity_test.xml b/sample/src/main/res/layout/activity_test.xml index 0aaf3e6aa..01e99f4b4 100644 --- a/sample/src/main/res/layout/activity_test.xml +++ b/sample/src/main/res/layout/activity_test.xml @@ -153,6 +153,12 @@ android:layout_height="wrap_content" android:text="TEXT VIEWS" /> +