Skip to content

Commit 4cbc2d3

Browse files
committed
Expand test
1 parent 852101a commit 4cbc2d3

File tree

2 files changed

+100
-3
lines changed

2 files changed

+100
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package info.hannes.slidingup.demo
2+
3+
import android.util.Log
4+
import android.view.View
5+
import androidx.test.espresso.UiController
6+
import androidx.test.espresso.ViewAction
7+
import androidx.test.espresso.matcher.BoundedMatcher
8+
import androidx.test.espresso.matcher.ViewMatchers
9+
import com.sothree.slidinguppanel.PanelState
10+
import com.sothree.slidinguppanel.SlidingUpPanelLayout
11+
import org.hamcrest.Description
12+
import org.hamcrest.Matcher
13+
14+
fun withValue(expectedValue: PanelState): Matcher<View?> {
15+
return object : BoundedMatcher<View?, SlidingUpPanelLayout>(SlidingUpPanelLayout::class.java) {
16+
override fun describeTo(description: Description) {
17+
description.appendText("expected: $expectedValue")
18+
}
19+
20+
override fun matchesSafely(slider: SlidingUpPanelLayout): Boolean {
21+
Log.d("slider", slider.panelState.toString())
22+
return slider.panelState == expectedValue
23+
}
24+
}
25+
}
26+
27+
fun setValue(value: PanelState): ViewAction {
28+
return object : ViewAction {
29+
override fun getDescription(): String {
30+
return "Set Slider value to $value"
31+
}
32+
33+
override fun getConstraints(): Matcher<View> {
34+
return ViewMatchers.isAssignableFrom(SlidingUpPanelLayout::class.java)
35+
}
36+
37+
override fun perform(uiController: UiController?, view: View) {
38+
val seekBar = view as SlidingUpPanelLayout
39+
seekBar.panelState = value
40+
}
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
11
package info.hannes.slidingup.demo
22

3+
import android.util.Log
4+
import android.view.View
5+
import androidx.test.espresso.assertion.ViewAssertions.matches
6+
import com.sothree.slidinguppanel.demo.R
37
import androidx.test.core.graphics.writeToTestStorage
4-
import androidx.test.espresso.Espresso
8+
import androidx.test.espresso.Espresso.onView
9+
import androidx.test.espresso.UiController
10+
import androidx.test.espresso.ViewAction
11+
import androidx.test.espresso.matcher.BoundedMatcher
512
import androidx.test.espresso.matcher.ViewMatchers
13+
import androidx.test.espresso.matcher.ViewMatchers.withId
614
import androidx.test.espresso.screenshot.captureToBitmap
715
import androidx.test.ext.junit.rules.activityScenarioRule
816
import androidx.test.ext.junit.runners.AndroidJUnit4
17+
import com.sothree.slidinguppanel.PanelState
18+
import com.sothree.slidinguppanel.SlidingUpPanelLayout
919
import com.sothree.slidinguppanel.demo.DemoActivity
20+
import org.hamcrest.Description
21+
import org.hamcrest.Matcher
1022
import org.junit.Rule
1123
import org.junit.Test
1224
import org.junit.rules.TestName
@@ -15,6 +27,8 @@ import org.junit.runner.RunWith
1527
@RunWith(AndroidJUnit4::class)
1628
class StartTest {
1729

30+
private val WAIT_SLIDER = 600L
31+
1832
@get:Rule
1933
val activityScenarioRule = activityScenarioRule<DemoActivity>()
2034

@@ -23,9 +37,50 @@ class StartTest {
2337

2438
@Test
2539
fun smokeTestSimplyStart() {
26-
Thread.sleep(1000)
27-
Espresso.onView(ViewMatchers.isRoot())
40+
onView(ViewMatchers.isRoot())
2841
.captureToBitmap()
2942
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}")
3043
}
44+
45+
@Test
46+
fun testExpand() {
47+
onView(ViewMatchers.isRoot())
48+
.captureToBitmap()
49+
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-1")
50+
onView(withId(R.id.sliding_layout)).check(matches(withValue(PanelState.COLLAPSED)))
51+
52+
onView(withId(R.id.sliding_layout)).perform(setValue(PanelState.EXPANDED))
53+
54+
Thread.sleep(WAIT_SLIDER)
55+
onView(withId(R.id.sliding_layout)).check(matches(withValue(PanelState.EXPANDED)))
56+
onView(ViewMatchers.isRoot())
57+
.captureToBitmap()
58+
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-2")
59+
60+
onView(withId(R.id.sliding_layout)).perform(setValue(PanelState.COLLAPSED))
61+
Thread.sleep(WAIT_SLIDER)
62+
onView(withId(R.id.sliding_layout)).check(matches(withValue(PanelState.COLLAPSED)))
63+
onView(ViewMatchers.isRoot())
64+
.captureToBitmap()
65+
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-3")
66+
}
67+
68+
@Test
69+
fun testAnchorWithoutSetAnchored() {
70+
onView(withId(R.id.sliding_layout)).check(matches(withValue(PanelState.COLLAPSED)))
71+
72+
onView(withId(R.id.sliding_layout)).perform(setValue(PanelState.EXPANDED))
73+
74+
Thread.sleep(WAIT_SLIDER)
75+
onView(withId(R.id.sliding_layout)).check(matches(withValue(PanelState.EXPANDED)))
76+
77+
// without state anchored, a state ANCHORED should be ignored
78+
onView(withId(R.id.sliding_layout)).perform(setValue(PanelState.ANCHORED))
79+
Thread.sleep(WAIT_SLIDER)
80+
// should be still EXPANDED
81+
onView(withId(R.id.sliding_layout)).check(matches(withValue(PanelState.EXPANDED)))
82+
onView(ViewMatchers.isRoot())
83+
.captureToBitmap()
84+
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-2")
85+
}
3186
}

0 commit comments

Comments
 (0)