Modern-Apps.git
Publicgit clone https://git.maproj.org/Modern-Apps.gitModern-Apps.git / launcher / src / test / java / com / vayunmathur / launcher / ui / LauncherHomePopupsTest.kt
LauncherHomePopupsTest.kt97 lines · 3.6 KiBRaw
| 1 | package com.vayunmathur.launcher.ui |
| 2 | |
| 3 | import androidx.compose.animation.core.Animatable |
| 4 | import androidx.compose.runtime.CompositionLocalProvider |
| 5 | import androidx.compose.ui.geometry.Rect |
| 6 | import androidx.compose.ui.test.assertIsDisplayed |
| 7 | import androidx.compose.ui.test.junit4.createComposeRule |
| 8 | import androidx.compose.ui.test.onAllNodesWithText |
| 9 | import androidx.compose.ui.test.onNodeWithText |
| 10 | import androidx.test.ext.junit.runners.AndroidJUnit4 |
| 11 | import com.vayunmathur.launcher.domain.ContainerRef |
| 12 | import com.vayunmathur.launcher.domain.LauncherItemType |
| 13 | import com.vayunmathur.launcher.platform.ItemMenuActions |
| 14 | import com.vayunmathur.launcher.platform.ItemMenuUiState |
| 15 | import com.vayunmathur.launcher.platform.ShortcutEntry |
| 16 | import com.vayunmathur.launcher.platform.WidgetPickerActions |
| 17 | import com.vayunmathur.launcher.platform.WidgetPickerUiState |
| 18 | import com.vayunmathur.launcher.platform.WorkspaceItem |
| 19 | import com.vayunmathur.launcher.ui.components.LauncherDragController |
| 20 | import com.vayunmathur.launcher.ui.components.LocalLauncherDrag |
| 21 | import org.junit.Rule |
| 22 | import org.junit.Test |
| 23 | import org.junit.runner.RunWith |
| 24 | import 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) |
| 32 | class 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 | } |