-
-
Notifications
You must be signed in to change notification settings - Fork 90
/
HorizontalSwipeTests.kt
50 lines (45 loc) · 1.55 KB
/
HorizontalSwipeTests.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package co.joebirch.composeplayground.action
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Slider
import androidx.compose.material.Surface
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.test.*
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.unit.Duration
import androidx.compose.ui.unit.inMilliseconds
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class HorizontalSwipeTests {
@get:Rule
val composeTestRule = createComposeRule()
private fun launchContent() {
composeTestRule.setContent {
MaterialTheme {
Surface {
val selectedValue = remember { mutableStateOf(0f) }
Slider(value = selectedValue.value, onValueChange = {
selectedValue.value = it
}, modifier = Modifier.testTag("MyTag"))
}
}
}
}
@Test
fun testSwipeHorizontal() {
launchContent()
composeTestRule.onNodeWithTag("MyTag")
.performGesture {
swipe(Offset(0f, 0f), Offset(200f, 0f),
Duration(5000).apply { inMilliseconds() })
swipeRight()
swipeLeft()
}
}
}