Skip to content

Commit b632066

Browse files
committed
test(ui): cover expandable search and preserve map control geometry
1 parent 3ce9c14 commit b632066

2 files changed

Lines changed: 51 additions & 6 deletions

File tree

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.system.location.service
2+
3+
import androidx.compose.ui.test.*
4+
import androidx.compose.ui.test.junit4.v2.createEmptyComposeRule
5+
import androidx.test.core.app.ActivityScenario
6+
import androidx.test.ext.junit.runners.AndroidJUnit4
7+
import org.junit.Assert.assertEquals
8+
import org.junit.Rule
9+
import org.junit.Test
10+
import org.junit.runner.RunWith
11+
12+
@RunWith(AndroidJUnit4::class)
13+
class HomeSearchUiTest {
14+
@get:Rule val compose = createEmptyComposeRule()
15+
16+
@Test fun searchExpandsFromTheRightRestoresDraftAndCollapsesBeforeNavigation() {
17+
acceptSelectedMapForUiTest()
18+
grantUiPermissions()
19+
ActivityScenario.launch(MainActivity::class.java).use { scenario ->
20+
compose.onNodeWithTag("home-search-input").assertDoesNotExist()
21+
val menu = compose.onNodeWithContentDescription("打开菜单").assertIsDisplayed()
22+
.fetchSemanticsNode().boundsInRoot
23+
val search = compose.onNodeWithContentDescription("搜索地点").assertIsDisplayed()
24+
.fetchSemanticsNode().boundsInRoot
25+
org.junit.Assert.assertTrue(menu.right < search.left)
26+
compose.onNodeWithContentDescription("搜索地点").performClick()
27+
compose.onNodeWithTag("home-search-input").assertIsDisplayed().performTextInput("上海人民广场")
28+
assertEquals(menu, compose.onNodeWithContentDescription("打开菜单").fetchSemanticsNode().boundsInRoot)
29+
assertEquals(search, compose.onNodeWithContentDescription("搜索地点").fetchSemanticsNode().boundsInRoot)
30+
scenario.recreate()
31+
compose.onNodeWithTag("home-search-input").assertTextContains("上海人民广场")
32+
compose.onNodeWithContentDescription("收起搜索").performClick()
33+
compose.waitUntil(5_000) { compose.onAllNodesWithTag("home-search-input").fetchSemanticsNodes().isEmpty() }
34+
compose.onNodeWithContentDescription("搜索地点").performClick()
35+
compose.onNodeWithTag("home-search-input").assertTextContains("上海人民广场")
36+
scenario.onActivity { it.systemBackForUiTest() }
37+
compose.waitUntil(5_000) { compose.onAllNodesWithTag("home-search-input").fetchSemanticsNodes().isEmpty() }
38+
scenario.onActivity { assertEquals(R.id.nav_home, it.currentDestinationId) }
39+
compose.onNodeWithContentDescription("搜索地点").performClick()
40+
compose.onNodeWithContentDescription("打开菜单").performClick()
41+
compose.onNodeWithTag("home-search-input").assertDoesNotExist()
42+
compose.onNodeWithTag("portal_drawer").assertIsDisplayed()
43+
}
44+
}
45+
}

‎app/src/androidTest/java/com/system/location/service/UiDesignTest.kt‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ class UiDesignTest {
3535
permissions()
3636
ActivityScenario.launch(MainActivity::class.java).use { scenario ->
3737
fun homeGeometry(): List<Int> {
38-
compose.onNode(hasSetTextAction()).assertIsDisplayed()
38+
compose.onNodeWithTag("home-search-controls").assertIsDisplayed()
3939
compose.onNodeWithText("开始模拟").assertIsDisplayed()
40-
val search = compose.onNode(hasSetTextAction()).fetchSemanticsNode().boundsInRoot
40+
val search = compose.onNodeWithTag("home-search-controls").fetchSemanticsNode().boundsInRoot
4141
val bottom = compose.onNodeWithText("开始模拟").fetchSemanticsNode().boundsInRoot
4242
var geometry = emptyList<Int>()
4343
scenario.onActivity { activity ->
@@ -111,7 +111,7 @@ class UiDesignTest {
111111
@Test fun edgeToEdgeKeepsMapFullSizeAndControlsInsideSafeInsets() {
112112
permissions()
113113
ActivityScenario.launch(MainActivity::class.java).use { scenario ->
114-
compose.onNode(hasSetTextAction()).assertIsDisplayed()
114+
compose.onNodeWithTag("home-search-controls").assertIsDisplayed()
115115
val insets = androidx.core.view.WindowInsetsCompat.Builder()
116116
.setInsets(androidx.core.view.WindowInsetsCompat.Type.systemBars(), androidx.core.graphics.Insets.of(12, 48, 16, 32))
117117
.build()
@@ -120,7 +120,7 @@ class UiDesignTest {
120120
compose.waitForIdle()
121121
}
122122
applyInsets()
123-
val search = compose.onNode(hasSetTextAction()).fetchSemanticsNode().boundsInRoot
123+
val search = compose.onNodeWithTag("home-search-controls").fetchSemanticsNode().boundsInRoot
124124
val start = compose.onNodeWithText("开始模拟").fetchSemanticsNode().boundsInRoot
125125
var mapWidth = 0
126126
var mapHeight = 0
@@ -148,7 +148,7 @@ class UiDesignTest {
148148
assertTrue("$description must not overlap the start action", button.bottom <= start.top)
149149
}
150150
applyInsets()
151-
assertEquals(search, compose.onNode(hasSetTextAction()).fetchSemanticsNode().boundsInRoot)
151+
assertEquals(search, compose.onNodeWithTag("home-search-controls").fetchSemanticsNode().boundsInRoot)
152152
assertEquals(start, compose.onNodeWithText("开始模拟").fetchSemanticsNode().boundsInRoot)
153153
compose.openPage(scenario, R.id.nav_mock)
154154
applyInsets()
@@ -342,7 +342,7 @@ class UiDesignTest {
342342
}
343343
compose.onNodeWithText("开始模拟").assertIsDisplayed()
344344
compose.onNodeWithContentDescription("选择模拟目标").assertIsDisplayed()
345-
val search = compose.onNode(hasSetTextAction()).fetchSemanticsNode().boundsInRoot
345+
val search = compose.onNodeWithTag("home-search-controls").fetchSemanticsNode().boundsInRoot
346346
val panel = compose.onNodeWithTag("home-runtime-panel").fetchSemanticsNode().boundsInRoot
347347
val root = compose.onNode(isRoot() and hasAnyDescendant(hasTestTag("home-runtime-panel")))
348348
.fetchSemanticsNode().boundsInRoot

0 commit comments

Comments
 (0)