Modern Apps git
git clone https://git.maproj.org/Modern-Apps.git
main ▾

Modern-Apps.git / launcher / src / test / java / com / vayunmathur / launcher / ui / LauncherHomePopupsTest.kt

LauncherHomePopupsTest.kt97 lines · 3.6 KiBRaw
1package com.vayunmathur.launcher.ui
2
3import androidx.compose.animation.core.Animatable
4import androidx.compose.runtime.CompositionLocalProvider
5import androidx.compose.ui.geometry.Rect
6import androidx.compose.ui.test.assertIsDisplayed
7import androidx.compose.ui.test.junit4.createComposeRule
8import androidx.compose.ui.test.onAllNodesWithText
9import androidx.compose.ui.test.onNodeWithText
10import androidx.test.ext.junit.runners.AndroidJUnit4
11import com.vayunmathur.launcher.domain.ContainerRef
12import com.vayunmathur.launcher.domain.LauncherItemType
13import com.vayunmathur.launcher.platform.ItemMenuActions
14import com.vayunmathur.launcher.platform.ItemMenuUiState
15import com.vayunmathur.launcher.platform.ShortcutEntry
16import com.vayunmathur.launcher.platform.WidgetPickerActions
17import com.vayunmathur.launcher.platform.WidgetPickerUiState
18import com.vayunmathur.launcher.platform.WorkspaceItem
19import com.vayunmathur.launcher.ui.components.LauncherDragController
20import com.vayunmathur.launcher.ui.components.LocalLauncherDrag
21import org.junit.Rule
22import org.junit.Test
23import org.junit.runner.RunWith
24import kotlin.test.assertEquals
25
26/**
27 * Compose tests (Robolectric + createComposeRule) for [HomePopups]: the
28 * item menu popup renders over its anchor, the wallpaper-options popup
29 * renders its rows, and the widget picker sheet opens when asked.
30 */
31@RunWith(AndroidJUnit4::class)
32class LauncherHomePopupsTest {
33
34 @get:Rule val rule = createComposeRule()
35
36 private val item = WorkspaceItem(
37 id = 7L,
38 type = LauncherItemType.APPLICATION,
39 label = "Mail",
40 container = ContainerRef.Desktop,
41 )
42
43 private fun show(
44 menuItemId: Long? = 7L,
45 optionsAnchor: Rect? = null,
46 widgetPickerOpen: Boolean = false,
47 ) {
48 val popup = Animatable(1f)
49 rule.setContent {
50 CompositionLocalProvider(LocalLauncherDrag provides LauncherDragController()) {
51 HomePopups(
52 menuItemId = menuItemId,
53 menuAnchor = Rect(0f, 0f, 100f, 100f),
54 itemMenuState = ItemMenuUiState(
55 item = item,
56 shortcuts = listOf(ShortcutEntry("compose", "Compose", "com.example.mail", 0L)),
57 canUninstall = true,
58 ),
59 itemMenuActions = ItemMenuActions.Noop,
60 popup = popup,
61 onClosePopup = {},
62 optionsAnchor = optionsAnchor,
63 onPickWallpaper = {},
64 widgetPickerActions = WidgetPickerActions.Noop,
65 onOpenSettings = {},
66 settleDrawer = {},
67 closePopup = {},
68 widgetPickerState = WidgetPickerUiState(open = widgetPickerOpen),
69 )
70 }
71 }
72 }
73
74 @Test fun itemMenuPopupRenders() {
75 show()
76 rule.onNodeWithText("Mail").assertIsDisplayed()
77 rule.onNodeWithText("App info").assertIsDisplayed()
78 }
79
80 @Test fun noPopupRendersNothing() {
81 show(menuItemId = null)
82 assertEquals(0, rule.onAllNodesWithText("App info").fetchSemanticsNodes().size)
83 }
84
85 @Test fun optionsPopupRendersRows() {
86 show(menuItemId = null, optionsAnchor = Rect(0f, 0f, 100f, 100f))
87 rule.onNodeWithText("Wallpaper & style").assertIsDisplayed()
88 rule.onNodeWithText("Home settings").assertIsDisplayed()
89 }
90
91 @Test fun widgetPickerSheetOpens() {
92 show(menuItemId = null, widgetPickerOpen = true)
93 rule.onNodeWithText("Search").assertIsDisplayed()
94 }
95
96
97}