diff --git a/demo/src/androidTest/java/info/hannes/slidingup/demo/Matcher.kt b/demo/src/androidTest/java/info/hannes/slidingup/demo/Matcher.kt new file mode 100644 index 0000000..9ef6ae9 --- /dev/null +++ b/demo/src/androidTest/java/info/hannes/slidingup/demo/Matcher.kt @@ -0,0 +1,42 @@ +package info.hannes.slidingup.demo + +import android.util.Log +import android.view.View +import androidx.test.espresso.UiController +import androidx.test.espresso.ViewAction +import androidx.test.espresso.matcher.BoundedMatcher +import androidx.test.espresso.matcher.ViewMatchers +import com.sothree.slidinguppanel.PanelState +import com.sothree.slidinguppanel.SlidingUpPanelLayout +import org.hamcrest.Description +import org.hamcrest.Matcher + +fun withValue(expectedValue: PanelState): Matcher { + return object : BoundedMatcher(SlidingUpPanelLayout::class.java) { + override fun describeTo(description: Description) { + description.appendText("expected: $expectedValue") + } + + override fun matchesSafely(slider: SlidingUpPanelLayout): Boolean { + Log.d("slider", slider.panelState.toString()) + return slider.panelState == expectedValue + } + } +} + +fun setValue(value: PanelState): ViewAction { + return object : ViewAction { + override fun getDescription(): String { + return "Set Slider value to $value" + } + + override fun getConstraints(): Matcher { + return ViewMatchers.isAssignableFrom(SlidingUpPanelLayout::class.java) + } + + override fun perform(uiController: UiController?, view: View) { + val seekBar = view as SlidingUpPanelLayout + seekBar.panelState = value + } + } +} \ No newline at end of file diff --git a/demo/src/androidTest/java/info/hannes/slidingup/demo/StartTest.kt b/demo/src/androidTest/java/info/hannes/slidingup/demo/StartTest.kt index be98c89..aa38d7b 100644 --- a/demo/src/androidTest/java/info/hannes/slidingup/demo/StartTest.kt +++ b/demo/src/androidTest/java/info/hannes/slidingup/demo/StartTest.kt @@ -1,12 +1,24 @@ package info.hannes.slidingup.demo +import android.util.Log +import android.view.View +import androidx.test.espresso.assertion.ViewAssertions.matches +import com.sothree.slidinguppanel.demo.R import androidx.test.core.graphics.writeToTestStorage -import androidx.test.espresso.Espresso +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.UiController +import androidx.test.espresso.ViewAction +import androidx.test.espresso.matcher.BoundedMatcher import androidx.test.espresso.matcher.ViewMatchers +import androidx.test.espresso.matcher.ViewMatchers.withId import androidx.test.espresso.screenshot.captureToBitmap import androidx.test.ext.junit.rules.activityScenarioRule import androidx.test.ext.junit.runners.AndroidJUnit4 +import com.sothree.slidinguppanel.PanelState +import com.sothree.slidinguppanel.SlidingUpPanelLayout import com.sothree.slidinguppanel.demo.DemoActivity +import org.hamcrest.Description +import org.hamcrest.Matcher import org.junit.Rule import org.junit.Test import org.junit.rules.TestName @@ -15,6 +27,8 @@ import org.junit.runner.RunWith @RunWith(AndroidJUnit4::class) class StartTest { + private val WAIT_SLIDER = 600L + @get:Rule val activityScenarioRule = activityScenarioRule() @@ -23,9 +37,50 @@ class StartTest { @Test fun smokeTestSimplyStart() { - Thread.sleep(1000) - Espresso.onView(ViewMatchers.isRoot()) + onView(ViewMatchers.isRoot()) .captureToBitmap() .writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}") } + + @Test + fun testExpand() { + onView(ViewMatchers.isRoot()) + .captureToBitmap() + .writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-1") + onView(withId(R.id.sliding_layout)).check(matches(withValue(PanelState.COLLAPSED))) + + onView(withId(R.id.sliding_layout)).perform(setValue(PanelState.EXPANDED)) + + Thread.sleep(WAIT_SLIDER) + onView(withId(R.id.sliding_layout)).check(matches(withValue(PanelState.EXPANDED))) + onView(ViewMatchers.isRoot()) + .captureToBitmap() + .writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-2") + + onView(withId(R.id.sliding_layout)).perform(setValue(PanelState.COLLAPSED)) + Thread.sleep(WAIT_SLIDER) + onView(withId(R.id.sliding_layout)).check(matches(withValue(PanelState.COLLAPSED))) + onView(ViewMatchers.isRoot()) + .captureToBitmap() + .writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-3") + } + + @Test + fun testAnchorWithoutSetAnchored() { + onView(withId(R.id.sliding_layout)).check(matches(withValue(PanelState.COLLAPSED))) + + onView(withId(R.id.sliding_layout)).perform(setValue(PanelState.EXPANDED)) + + Thread.sleep(WAIT_SLIDER) + onView(withId(R.id.sliding_layout)).check(matches(withValue(PanelState.EXPANDED))) + + // without state anchored, a state ANCHORED should be ignored + onView(withId(R.id.sliding_layout)).perform(setValue(PanelState.ANCHORED)) + Thread.sleep(WAIT_SLIDER) + // should be still EXPANDED + onView(withId(R.id.sliding_layout)).check(matches(withValue(PanelState.EXPANDED))) + onView(ViewMatchers.isRoot()) + .captureToBitmap() + .writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-2") + } }