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

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

LauncherTvEditMenuTest.kt166 lines · 5.5 KiBRaw
1package com.vayunmathur.launcher.ui
2
3import androidx.compose.ui.test.assertIsDisplayed
4import androidx.compose.ui.test.junit4.createComposeRule
5import androidx.compose.ui.test.onAllNodesWithText
6import androidx.compose.ui.test.onNodeWithText
7import androidx.compose.ui.test.performClick
8import androidx.test.ext.junit.runners.AndroidJUnit4
9import com.vayunmathur.launcher.platform.TvAppEntry
10import com.vayunmathur.launcher.platform.TvHomeState
11import com.vayunmathur.launcher.platform.TvTile
12import org.junit.Rule
13import org.junit.Test
14import org.junit.runner.RunWith
15import kotlin.test.assertEquals
16
17/**
18 * Compose tests (Robolectric + createComposeRule) for [TvEditMenu]: the
19 * edit dialog names the tile and offers Move/Replace/Remove plus
20 * Uninstall (user apps) or App info (system apps); the add menu lists
21 * candidates.
22 */
23@RunWith(AndroidJUnit4::class)
24class LauncherTvEditMenuTest {
25
26 @get:Rule val rule = createComposeRule()
27
28 private fun tile(pkg: String, label: String, user: Boolean = true) = TvTile(
29 packageName = pkg,
30 label = label,
31 banner = null,
32 appIcon = null,
33 userInstalled = user,
34 )
35
36 private fun show(
37 state: TvHomeState,
38 onStartMove: (String) -> Unit = {},
39 onRemove: () -> Unit = {},
40 onUninstallOrInfo: () -> Unit = {},
41 onDismiss: () -> Unit = {},
42 ) {
43 rule.setContent {
44 TvEditMenu(
45 state = state,
46 onDismiss = onDismiss,
47 onStartMove = onStartMove,
48 onReplace = {},
49 onRemove = onRemove,
50 onUninstallOrInfo = onUninstallOrInfo,
51 onPickAddCandidate = {},
52 onCloseAddMenu = {},
53 )
54 }
55 }
56
57 @Test fun userAppMenuOffersUninstall() {
58 show(TvHomeState(rowApps = listOf(tile("com.example.a", "Alpha")), editingKey = "com.example.a"))
59 rule.onNodeWithText("Alpha").assertIsDisplayed()
60 rule.onNodeWithText("Move").assertIsDisplayed()
61 rule.onNodeWithText("Replace").assertIsDisplayed()
62 rule.onNodeWithText("Remove from home").assertIsDisplayed()
63 rule.onNodeWithText("Uninstall").assertIsDisplayed()
64 }
65
66 @Test fun systemAppMenuOffersAppInfo() {
67 show(
68 TvHomeState(
69 rowApps = listOf(tile("com.android.sys", "System", user = false)),
70 editingKey = "com.android.sys",
71 ),
72 )
73 rule.onNodeWithText("App info").assertIsDisplayed()
74 }
75
76 @Test fun moveRowStartsMove() {
77 var moved: String? = null
78 show(
79 TvHomeState(rowApps = listOf(tile("com.example.a", "Alpha")), editingKey = "com.example.a"),
80 onStartMove = { moved = it },
81 )
82 rule.onNodeWithText("Move").performClick()
83 assertEquals("com.example.a", moved)
84 }
85
86 @Test fun removeRowRemoves() {
87 var removed = false
88 show(
89 TvHomeState(rowApps = listOf(tile("com.example.a", "Alpha")), editingKey = "com.example.a"),
90 onRemove = { removed = true },
91 )
92 rule.onNodeWithText("Remove from home").performClick()
93 assertEquals(true, removed)
94 }
95
96 @Test fun addMenuListsCandidates() {
97 var picked: String? = null
98 rule.setContent {
99 TvEditMenu(
100 state = TvHomeState(
101 showAddMenu = true,
102 addCandidates = listOf(
103 TvAppEntry("com.example.a", "Alpha", true),
104 TvAppEntry("com.example.b", "Beta", true),
105 ),
106 ),
107 onDismiss = {},
108 onStartMove = {},
109 onReplace = {},
110 onRemove = {},
111 onUninstallOrInfo = {},
112 onPickAddCandidate = { picked = it },
113 onCloseAddMenu = {},
114 )
115 }
116 rule.onNodeWithText("Add an app").assertIsDisplayed()
117 rule.onNodeWithText("Beta").performClick()
118 assertEquals("com.example.b", picked)
119 }
120
121 @Test fun addMenuEmptyReadsEveryAppHere() {
122 rule.setContent {
123 TvEditMenu(
124 state = TvHomeState(showAddMenu = true),
125 onDismiss = {},
126 onStartMove = {},
127 onReplace = {},
128 onRemove = {},
129 onUninstallOrInfo = {},
130 onPickAddCandidate = {},
131 onCloseAddMenu = {},
132 )
133 }
134 rule.onNodeWithText("Every app is already here").assertIsDisplayed()
135 }
136
137 @Test fun replaceMenuNamesCurrent() {
138 rule.setContent {
139 TvEditMenu(
140 state = TvHomeState(
141 rowApps = listOf(tile("com.example.a", "Alpha")),
142 showAddMenu = true,
143 addReplacesIndex = 0,
144 addCandidates = listOf(TvAppEntry("com.example.b", "Beta", true)),
145 ),
146 onDismiss = {},
147 onStartMove = {},
148 onReplace = {},
149 onRemove = {},
150 onUninstallOrInfo = {},
151 onPickAddCandidate = {},
152 onCloseAddMenu = {},
153 )
154 }
155 rule.onNodeWithText("Replace Alpha").assertIsDisplayed()
156 }
157
158 @Test fun noEditingKeyRendersNothing() {
159 show(TvHomeState(rowApps = listOf(tile("com.example.a", "Alpha"))))
160 // The tile grid is not this composable's business; only the dialog is.
161 assertEquals(
162 0,
163 rule.onAllNodesWithText("Move").fetchSemanticsNodes().size,
164 )
165 }
166}