[go: nahoru, domu]

blob: 510382b066fa56df65e2fa93099fab7329452032 [file] [log] [blame]
Matvei Malkov2d37cbd2019-07-04 15:15:20 +01001/*
2 * Copyright 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package androidx.ui.material
18
Jelle Fresen11fc7062020-01-13 16:53:55 +000019import android.os.SystemClock.sleep
Louis Pullen-Freiliche46bcf02020-02-12 16:06:21 +000020import androidx.compose.emptyContent
Leland Richardsonfcf76b32020-05-13 16:58:59 -070021import androidx.compose.mutableStateOf
Matvei Malkov2d37cbd2019-07-04 15:15:20 +010022import androidx.test.filters.MediumTest
Adam Powell999a89b2020-03-11 09:08:07 -070023import androidx.ui.core.LayoutCoordinates
24import androidx.ui.core.Modifier
George Mountd02af602020-03-06 16:41:40 -080025import androidx.ui.core.onPositioned
Filip Pavlis1d4d1b832020-05-27 14:45:15 +010026import androidx.ui.core.testTag
Matvei Malkov201726d2020-03-13 14:03:54 +000027import androidx.ui.foundation.Box
Matvei Malkov323b7452020-05-01 16:57:52 +010028import androidx.ui.foundation.clickable
Matvei Malkov11fcc1332020-06-25 18:03:03 +010029import androidx.ui.foundation.drawBackground
George Mount8f237572020-04-30 12:08:30 -070030import androidx.ui.geometry.Offset
Matvei Malkov11fcc1332020-06-25 18:03:03 +010031import androidx.ui.graphics.Color
Adam Powell999a89b2020-03-11 09:08:07 -070032import androidx.ui.layout.fillMaxSize
Matvei Malkov11fcc1332020-06-25 18:03:03 +010033import androidx.ui.layout.rtl
Filip Pavlis028c0d52020-06-29 15:07:53 +010034import androidx.ui.test.assertIsEqualTo
35import androidx.ui.test.assertLeftPositionInRootIsEqualTo
36import androidx.ui.test.assertTopPositionInRootIsEqualTo
37import androidx.ui.test.assertWidthIsEqualTo
Matvei Malkov2d37cbd2019-07-04 15:15:20 +010038import androidx.ui.test.createComposeRule
Jelle Fresen11fc7062020-01-13 16:53:55 +000039import androidx.ui.test.doGesture
Matvei Malkov7aa7fd22019-08-16 16:52:59 +010040import androidx.ui.test.findByTag
Jelle Fresen11fc7062020-01-13 16:53:55 +000041import androidx.ui.test.globalBounds
Filip Pavlis6fdb2502020-04-02 14:41:32 +010042import androidx.ui.test.runOnIdleCompose
43import androidx.ui.test.runOnUiThread
Jelle Fresen11fc7062020-01-13 16:53:55 +000044import androidx.ui.test.sendClick
Matvei Malkov11fcc1332020-06-25 18:03:03 +010045import androidx.ui.test.sendSwipeDown
46import androidx.ui.test.sendSwipeLeft
47import androidx.ui.test.sendSwipeRight
48import androidx.ui.test.sendSwipeUp
George Mount842c8c12020-01-08 16:03:42 -080049import androidx.ui.unit.dp
Ryan Mentley7865a632019-08-20 20:10:29 -070050import androidx.ui.unit.height
Ryan Mentley7865a632019-08-20 20:10:29 -070051import androidx.ui.unit.width
Filip Pavlise63b30c2020-01-09 16:21:07 +000052import com.google.common.truth.Truth.assertThat
Matvei Malkov886ec6a2020-02-03 01:45:29 +000053import org.junit.Ignore
Matvei Malkov2d37cbd2019-07-04 15:15:20 +010054import org.junit.Rule
55import org.junit.Test
56import org.junit.runner.RunWith
57import org.junit.runners.JUnit4
Jelle Fresen4c566312020-01-16 10:32:40 +000058import java.util.concurrent.CountDownLatch
59import java.util.concurrent.TimeUnit
Matvei Malkov2d37cbd2019-07-04 15:15:20 +010060import kotlin.math.roundToInt
61
62@MediumTest
63@RunWith(JUnit4::class)
64class DrawerTest {
65
66 @get:Rule
Matvei Malkov7aa7fd22019-08-16 16:52:59 +010067 val composeTestRule = createComposeRule(disableTransitions = true)
Matvei Malkov2d37cbd2019-07-04 15:15:20 +010068
69 @Test
70 fun modalDrawer_testOffset_whenOpened() {
Matvei Malkov2d37cbd2019-07-04 15:15:20 +010071 composeTestRule.setMaterialContent {
Matvei Malkov7aa7fd22019-08-16 16:52:59 +010072 ModalDrawerLayout(DrawerState.Opened, {}, drawerContent = {
Filip Pavlis028c0d52020-06-29 15:07:53 +010073 Box(Modifier.fillMaxSize().testTag("content"))
Louis Pullen-Freiliche46bcf02020-02-12 16:06:21 +000074 }, bodyContent = emptyContent())
Matvei Malkov2d37cbd2019-07-04 15:15:20 +010075 }
Filip Pavlis028c0d52020-06-29 15:07:53 +010076
77 findByTag("content")
78 .assertLeftPositionInRootIsEqualTo(0.dp)
Matvei Malkov2d37cbd2019-07-04 15:15:20 +010079 }
80
81 @Test
82 fun modalDrawer_testOffset_whenClosed() {
Nader Jawad6df06122020-06-03 15:27:08 -070083 var position: Offset? = null
Matvei Malkov2d37cbd2019-07-04 15:15:20 +010084 composeTestRule.setMaterialContent {
Matvei Malkov7aa7fd22019-08-16 16:52:59 +010085 ModalDrawerLayout(DrawerState.Closed, {}, drawerContent = {
Adam Powell999a89b2020-03-11 09:08:07 -070086 Box(Modifier.fillMaxSize().onPositioned { coords: LayoutCoordinates ->
Filip Pavlis028c0d52020-06-29 15:07:53 +010087 position = coords.localToRoot(Offset.Zero)
Matvei Malkov201726d2020-03-13 14:03:54 +000088 })
Louis Pullen-Freiliche46bcf02020-02-12 16:06:21 +000089 }, bodyContent = emptyContent())
Matvei Malkov2d37cbd2019-07-04 15:15:20 +010090 }
Filip Pavlis028c0d52020-06-29 15:07:53 +010091
92 val width = rootWidth()
93 composeTestRule.runOnIdleComposeWithDensity {
94 position!!.x.toDp().assertIsEqualTo(-width)
Filip Pavlise63b30c2020-01-09 16:21:07 +000095 }
Matvei Malkov2d37cbd2019-07-04 15:15:20 +010096 }
97
98 @Test
99 fun modalDrawer_testEndPadding_whenOpened() {
Matvei Malkov2d37cbd2019-07-04 15:15:20 +0100100 composeTestRule.setMaterialContent {
Matvei Malkov7aa7fd22019-08-16 16:52:59 +0100101 ModalDrawerLayout(DrawerState.Opened, {}, drawerContent = {
Filip Pavlis028c0d52020-06-29 15:07:53 +0100102 Box(Modifier.fillMaxSize().testTag("content"))
Louis Pullen-Freiliche46bcf02020-02-12 16:06:21 +0000103 }, bodyContent = emptyContent())
Matvei Malkov2d37cbd2019-07-04 15:15:20 +0100104 }
105
Filip Pavlis028c0d52020-06-29 15:07:53 +0100106 findByTag("content")
107 .assertWidthIsEqualTo(rootWidth() - 56.dp)
Matvei Malkov2d37cbd2019-07-04 15:15:20 +0100108 }
109
110 @Test
111 fun bottomDrawer_testOffset_whenOpened() {
Matvei Malkov2d37cbd2019-07-04 15:15:20 +0100112 composeTestRule.setMaterialContent {
Matvei Malkov7aa7fd22019-08-16 16:52:59 +0100113 BottomDrawerLayout(DrawerState.Opened, {}, drawerContent = {
Filip Pavlis028c0d52020-06-29 15:07:53 +0100114 Box(Modifier.fillMaxSize().testTag("content"))
Louis Pullen-Freiliche46bcf02020-02-12 16:06:21 +0000115 }, bodyContent = emptyContent())
Matvei Malkov2d37cbd2019-07-04 15:15:20 +0100116 }
Filip Pavlise63b30c2020-01-09 16:21:07 +0000117
Filip Pavlis028c0d52020-06-29 15:07:53 +0100118 val width = rootWidth()
119 val height = rootHeight()
120 val expectedHeight = if (width > height) 0.dp else (height / 2)
121 findByTag("content")
122 .assertTopPositionInRootIsEqualTo(expectedHeight)
Matvei Malkov2d37cbd2019-07-04 15:15:20 +0100123 }
124
125 @Test
126 fun bottomDrawer_testOffset_whenClosed() {
Nader Jawad6df06122020-06-03 15:27:08 -0700127 var position: Offset? = null
Matvei Malkov2d37cbd2019-07-04 15:15:20 +0100128 composeTestRule.setMaterialContent {
Matvei Malkov7aa7fd22019-08-16 16:52:59 +0100129 BottomDrawerLayout(DrawerState.Closed, {}, drawerContent = {
Adam Powell999a89b2020-03-11 09:08:07 -0700130 Box(Modifier.fillMaxSize().onPositioned { coords: LayoutCoordinates ->
Filip Pavlis028c0d52020-06-29 15:07:53 +0100131 position = coords.localToRoot(Offset.Zero)
Matvei Malkov201726d2020-03-13 14:03:54 +0000132 })
Louis Pullen-Freiliche46bcf02020-02-12 16:06:21 +0000133 }, bodyContent = emptyContent())
Matvei Malkov2d37cbd2019-07-04 15:15:20 +0100134 }
Filip Pavlis028c0d52020-06-29 15:07:53 +0100135
136 val height = rootHeight()
137 composeTestRule.runOnIdleComposeWithDensity {
138 position!!.y.toDp().assertIsEqualTo(height)
Filip Pavlise63b30c2020-01-09 16:21:07 +0000139 }
Matvei Malkov2d37cbd2019-07-04 15:15:20 +0100140 }
141
142 @Test
Matvei Malkov886ec6a2020-02-03 01:45:29 +0000143 @Ignore("failing in postsubmit, fix in b/148751721")
Jelle Fresen4c566312020-01-16 10:32:40 +0000144 fun modalDrawer_openAndClose() {
George Mount8f237572020-04-30 12:08:30 -0700145 var contentWidth: Int? = null
Jelle Fresen4c566312020-01-16 10:32:40 +0000146 var openedLatch: CountDownLatch? = null
147 var closedLatch: CountDownLatch? = CountDownLatch(1)
Leland Richardsonfcf76b32020-05-13 16:58:59 -0700148 val drawerState = mutableStateOf(DrawerState.Closed)
Jelle Fresen4c566312020-01-16 10:32:40 +0000149 composeTestRule.setMaterialContent {
Filip Pavlis1d4d1b832020-05-27 14:45:15 +0100150 ModalDrawerLayout(drawerState.value, { drawerState.value = it },
151 drawerContent = {
152 Box(
153 Modifier.fillMaxSize().onPositioned { info: LayoutCoordinates ->
Nader Jawad6df06122020-06-03 15:27:08 -0700154 val pos = info.localToGlobal(Offset.Zero)
Nader Jawade6a9b332020-05-21 13:49:20 -0700155 if (pos.x == 0.0f) {
Filip Pavlis1d4d1b832020-05-27 14:45:15 +0100156 // If fully opened, mark the openedLatch if present
157 openedLatch?.countDown()
George Mount8f237572020-04-30 12:08:30 -0700158 } else if (-pos.x.roundToInt() == contentWidth) {
Filip Pavlis1d4d1b832020-05-27 14:45:15 +0100159 // If fully closed, mark the closedLatch if present
160 closedLatch?.countDown()
Matvei Malkov9f27abf2020-05-19 15:15:56 +0100161 }
Filip Pavlis1d4d1b832020-05-27 14:45:15 +0100162 }
163 )
164 },
165 bodyContent = {
166 Box(Modifier.fillMaxSize()
167 .onPositioned { contentWidth = it.size.width })
168 })
Jelle Fresen4c566312020-01-16 10:32:40 +0000169 }
170 // Drawer should start in closed state
171 assertThat(closedLatch!!.await(5, TimeUnit.SECONDS)).isTrue()
172
173 // When the drawer state is set to Opened
174 openedLatch = CountDownLatch(1)
Filip Pavlis6fdb2502020-04-02 14:41:32 +0100175 runOnIdleCompose {
Leland Richardsonfcf76b32020-05-13 16:58:59 -0700176 drawerState.value = DrawerState.Opened
Jelle Fresen4c566312020-01-16 10:32:40 +0000177 }
178 // Then the drawer should be opened
179 assertThat(openedLatch.await(5, TimeUnit.SECONDS)).isTrue()
180
181 // When the drawer state is set to Closed
182 closedLatch = CountDownLatch(1)
Filip Pavlis6fdb2502020-04-02 14:41:32 +0100183 runOnIdleCompose {
Leland Richardsonfcf76b32020-05-13 16:58:59 -0700184 drawerState.value = DrawerState.Closed
Jelle Fresen4c566312020-01-16 10:32:40 +0000185 }
186 // Then the drawer should be closed
187 assertThat(closedLatch.await(5, TimeUnit.SECONDS)).isTrue()
188 }
189
190 @Test
Matvei Malkov7aa7fd22019-08-16 16:52:59 +0100191 fun modalDrawer_bodyContent_clickable() {
192 var drawerClicks = 0
193 var bodyClicks = 0
Leland Richardsonfcf76b32020-05-13 16:58:59 -0700194 val drawerState = mutableStateOf(DrawerState.Closed)
Matvei Malkov7aa7fd22019-08-16 16:52:59 +0100195 composeTestRule.setMaterialContent {
Aurimas Liutikas7a828d32019-10-07 17:16:05 -0700196 // emulate click on the screen
Filip Pavlis1d4d1b832020-05-27 14:45:15 +0100197 ModalDrawerLayout(drawerState.value, { drawerState.value = it },
198 drawerContent = {
199 Box(
200 Modifier.fillMaxSize().clickable { drawerClicks += 1 },
201 children = emptyContent()
202 )
203 },
204 bodyContent = {
205 Box(
206 Modifier.testTag("Drawer").fillMaxSize().clickable { bodyClicks += 1 },
207 children = emptyContent()
208 )
209 })
Matvei Malkov7aa7fd22019-08-16 16:52:59 +0100210 }
211
Jelle Fresen11fc7062020-01-13 16:53:55 +0000212 // Click in the middle of the drawer (which is the middle of the body)
213 findByTag("Drawer").doGesture { sendClick() }
Matvei Malkov7aa7fd22019-08-16 16:52:59 +0100214
Filip Pavlis6fdb2502020-04-02 14:41:32 +0100215 runOnIdleCompose {
Filip Pavlise63b30c2020-01-09 16:21:07 +0000216 assertThat(drawerClicks).isEqualTo(0)
217 assertThat(bodyClicks).isEqualTo(1)
Matvei Malkov7aa7fd22019-08-16 16:52:59 +0100218
Leland Richardsonfcf76b32020-05-13 16:58:59 -0700219 drawerState.value = DrawerState.Opened
Matvei Malkov7aa7fd22019-08-16 16:52:59 +0100220 }
Jelle Fresen11fc7062020-01-13 16:53:55 +0000221 sleep(100) // TODO(147586311): remove this sleep when opening the drawer triggers a wait
Matvei Malkov7aa7fd22019-08-16 16:52:59 +0100222
Jelle Fresen11fc7062020-01-13 16:53:55 +0000223 // Click on the left-center pixel of the drawer
224 findByTag("Drawer").doGesture {
Nader Jawade6a9b332020-05-21 13:49:20 -0700225 val left = 1.0f
Nader Jawad63153c12020-05-21 14:17:08 -0700226 val centerY = (globalBounds.height / 2)
Nader Jawad6df06122020-06-03 15:27:08 -0700227 sendClick(Offset(left, centerY))
Jelle Fresen11fc7062020-01-13 16:53:55 +0000228 }
Matvei Malkov7aa7fd22019-08-16 16:52:59 +0100229
Filip Pavlis6fdb2502020-04-02 14:41:32 +0100230 runOnIdleCompose {
Filip Pavlise63b30c2020-01-09 16:21:07 +0000231 assertThat(drawerClicks).isEqualTo(1)
232 assertThat(bodyClicks).isEqualTo(1)
Filip Pavlis2b161e42019-11-22 17:40:08 +0000233 }
Matvei Malkov7aa7fd22019-08-16 16:52:59 +0100234 }
235
236 @Test
Matvei Malkov886ec6a2020-02-03 01:45:29 +0000237 @Ignore("failing in postsubmit, fix in b/148751721")
Jelle Fresen4c566312020-01-16 10:32:40 +0000238 fun bottomDrawer_openAndClose() {
George Mount8f237572020-04-30 12:08:30 -0700239 var contentHeight: Int? = null
240 var openedHeight: Int? = null
Jelle Fresen4c566312020-01-16 10:32:40 +0000241 var openedLatch: CountDownLatch? = null
242 var closedLatch: CountDownLatch? = CountDownLatch(1)
Leland Richardsonfcf76b32020-05-13 16:58:59 -0700243 val drawerState = mutableStateOf(DrawerState.Closed)
Jelle Fresen4c566312020-01-16 10:32:40 +0000244 composeTestRule.setMaterialContent {
Filip Pavlis1d4d1b832020-05-27 14:45:15 +0100245 BottomDrawerLayout(drawerState.value, { drawerState.value = it },
246 drawerContent = {
247 Box(Modifier.fillMaxSize().onPositioned { info: LayoutCoordinates ->
Nader Jawad6df06122020-06-03 15:27:08 -0700248 val pos = info.localToGlobal(Offset.Zero)
George Mount8f237572020-04-30 12:08:30 -0700249 if (pos.y.roundToInt() == openedHeight) {
Filip Pavlis1d4d1b832020-05-27 14:45:15 +0100250 // If fully opened, mark the openedLatch if present
251 openedLatch?.countDown()
George Mount8f237572020-04-30 12:08:30 -0700252 } else if (pos.y.roundToInt() == contentHeight) {
Filip Pavlis1d4d1b832020-05-27 14:45:15 +0100253 // If fully closed, mark the closedLatch if present
254 closedLatch?.countDown()
255 }
256 })
257 },
258 bodyContent = {
259 Box(Modifier.fillMaxSize().onPositioned {
260 contentHeight = it.size.height
George Mount8f237572020-04-30 12:08:30 -0700261 openedHeight = (it.size.height * BottomDrawerOpenFraction).roundToInt()
Filip Pavlis1d4d1b832020-05-27 14:45:15 +0100262 })
263 }
264 )
Jelle Fresen4c566312020-01-16 10:32:40 +0000265 }
266 // Drawer should start in closed state
267 assertThat(closedLatch!!.await(5, TimeUnit.SECONDS)).isTrue()
268
269 // When the drawer state is set to Opened
270 openedLatch = CountDownLatch(1)
Filip Pavlis6fdb2502020-04-02 14:41:32 +0100271 runOnIdleCompose {
Leland Richardsonfcf76b32020-05-13 16:58:59 -0700272 drawerState.value = DrawerState.Opened
Jelle Fresen4c566312020-01-16 10:32:40 +0000273 }
274 // Then the drawer should be opened
275 assertThat(openedLatch.await(5, TimeUnit.SECONDS)).isTrue()
276
277 // When the drawer state is set to Closed
278 closedLatch = CountDownLatch(1)
Filip Pavlis6fdb2502020-04-02 14:41:32 +0100279 runOnIdleCompose {
Leland Richardsonfcf76b32020-05-13 16:58:59 -0700280 drawerState.value = DrawerState.Closed
Jelle Fresen4c566312020-01-16 10:32:40 +0000281 }
282 // Then the drawer should be closed
283 assertThat(closedLatch.await(5, TimeUnit.SECONDS)).isTrue()
284 }
285
286 @Test
Matvei Malkov7aa7fd22019-08-16 16:52:59 +0100287 fun bottomDrawer_bodyContent_clickable() {
288 var drawerClicks = 0
289 var bodyClicks = 0
Leland Richardsonfcf76b32020-05-13 16:58:59 -0700290 val drawerState = mutableStateOf(DrawerState.Closed)
Matvei Malkov7aa7fd22019-08-16 16:52:59 +0100291 composeTestRule.setMaterialContent {
Aurimas Liutikas7a828d32019-10-07 17:16:05 -0700292 // emulate click on the screen
Filip Pavlis1d4d1b832020-05-27 14:45:15 +0100293 BottomDrawerLayout(drawerState.value, { drawerState.value = it },
294 drawerContent = {
295 Box(
296 Modifier.fillMaxSize().clickable { drawerClicks += 1 },
297 children = emptyContent()
298 )
299 },
300 bodyContent = {
301 Box(
302 Modifier.testTag("Drawer").fillMaxSize().clickable { bodyClicks += 1 },
303 children = emptyContent()
304 )
305 })
Matvei Malkov7aa7fd22019-08-16 16:52:59 +0100306 }
307
Jelle Fresen11fc7062020-01-13 16:53:55 +0000308 // Click in the middle of the drawer (which is the middle of the body)
309 findByTag("Drawer").doGesture { sendClick() }
Matvei Malkov7aa7fd22019-08-16 16:52:59 +0100310
Filip Pavlis6fdb2502020-04-02 14:41:32 +0100311 runOnIdleCompose {
Filip Pavlise63b30c2020-01-09 16:21:07 +0000312 assertThat(drawerClicks).isEqualTo(0)
313 assertThat(bodyClicks).isEqualTo(1)
314 }
Matvei Malkov7aa7fd22019-08-16 16:52:59 +0100315
Filip Pavlis6fdb2502020-04-02 14:41:32 +0100316 runOnUiThread {
Leland Richardsonfcf76b32020-05-13 16:58:59 -0700317 drawerState.value = DrawerState.Opened
Jelle Fresen11fc7062020-01-13 16:53:55 +0000318 }
319 sleep(100) // TODO(147586311): remove this sleep when opening the drawer triggers a wait
320
321 // Click on the bottom-center pixel of the drawer
322 findByTag("Drawer").doGesture {
323 val bounds = globalBounds
Nader Jawad63153c12020-05-21 14:17:08 -0700324 val centerX = bounds.width / 2
325 val bottom = bounds.height - 1.0f
Nader Jawad6df06122020-06-03 15:27:08 -0700326 sendClick(Offset(centerX, bottom))
Jelle Fresen11fc7062020-01-13 16:53:55 +0000327 }
328
329 assertThat(drawerClicks).isEqualTo(1)
330 assertThat(bodyClicks).isEqualTo(1)
Matvei Malkov7aa7fd22019-08-16 16:52:59 +0100331 }
Matvei Malkov11fcc1332020-06-25 18:03:03 +0100332
333 @Test
334 fun modalDrawer_openBySwipe() {
335 val drawerState = mutableStateOf(DrawerState.Closed)
336 composeTestRule.setMaterialContent {
337 // emulate click on the screen
338 Box(Modifier.testTag("Drawer")) {
339 ModalDrawerLayout(drawerState.value, { drawerState.value = it },
340 drawerContent = {
341 Box(Modifier.fillMaxSize().drawBackground(Color.Magenta))
342 },
343 bodyContent = {
344 Box(Modifier.fillMaxSize().drawBackground(Color.Red))
345 })
346 }
347 }
348
349 findByTag("Drawer")
350 .doGesture { sendSwipeRight() }
351
352 runOnIdleCompose {
353 assertThat(drawerState.value).isEqualTo(DrawerState.Opened)
354 }
355
356 findByTag("Drawer")
357 .doGesture { sendSwipeLeft() }
358
359 runOnIdleCompose {
360 assertThat(drawerState.value).isEqualTo(DrawerState.Closed)
361 }
362 }
363
364 @Test
365 fun modalDrawer_openBySwipe_rtl() {
366 val drawerState = mutableStateOf(DrawerState.Closed)
367 composeTestRule.setMaterialContent {
368 // emulate click on the screen
369 Box(Modifier.testTag("Drawer").rtl) {
370 ModalDrawerLayout(drawerState.value, { drawerState.value = it },
371 drawerContent = {
372 Box(Modifier.fillMaxSize().drawBackground(Color.Magenta))
373 },
374 bodyContent = {
375 Box(Modifier.fillMaxSize().drawBackground(Color.Red))
376 })
377 }
378 }
379
380 findByTag("Drawer")
381 .doGesture { sendSwipeLeft() }
382
383 runOnIdleCompose {
384 assertThat(drawerState.value).isEqualTo(DrawerState.Opened)
385 }
386
387 findByTag("Drawer")
388 .doGesture { sendSwipeRight() }
389
390 runOnIdleCompose {
391 assertThat(drawerState.value).isEqualTo(DrawerState.Closed)
392 }
393 }
394
395 @Test
396 fun bottomDrawer_openBySwipe() {
397 val drawerState = mutableStateOf(DrawerState.Closed)
398 composeTestRule.setMaterialContent {
399 // emulate click on the screen
400 Box(Modifier.testTag("Drawer")) {
401 BottomDrawerLayout(drawerState.value, { drawerState.value = it },
402 drawerContent = {
403 Box(Modifier.fillMaxSize().drawBackground(Color.Magenta))
404 },
405 bodyContent = {
406 Box(Modifier.fillMaxSize().drawBackground(Color.Red))
407 })
408 }
409 }
410
411 findByTag("Drawer")
412 .doGesture { sendSwipeUp() }
413
414 runOnIdleCompose {
415 assertThat(drawerState.value).isEqualTo(DrawerState.Opened)
416 }
417
418 findByTag("Drawer")
419 .doGesture { sendSwipeDown() }
420
421 runOnIdleCompose {
422 assertThat(drawerState.value).isEqualTo(DrawerState.Closed)
423 }
424 }
Matvei Malkov2d37cbd2019-07-04 15:15:20 +0100425}