mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-19 04:46:08 +00:00
Fix FEX dropdown scaling and Discover search focus (#681)
This commit is contained in:
1 parent
1c1a96cb19
commit
623fb3fb62
5 files changed
+217
-3
No files matched your search
@@ -0,0 +1,107 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.EditText
|
||||
import androidx.compose.runtime.SideEffect
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalView
|
||||
import androidx.compose.ui.semantics.SemanticsActions
|
||||
import androidx.compose.ui.test.onNodeWithContentDescription
|
||||
import androidx.compose.ui.test.onNodeWithText
|
||||
import androidx.compose.ui.test.hasText
|
||||
import androidx.compose.ui.test.hasClickAction
|
||||
import androidx.compose.ui.test.assertIsNotFocused
|
||||
import androidx.compose.ui.test.performClick
|
||||
import androidx.compose.ui.test.performSemanticsAction
|
||||
import com.droiddeck.launcher.R
|
||||
import com.droiddeck.launcher.store.FlathubApi
|
||||
import com.droiddeck.launcher.store.StoreState
|
||||
import org.junit.After
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [28], qualifiers = "w960dp-h540dp-land", application = android.app.Application::class)
|
||||
class FlathubFocusTest {
|
||||
@get:Rule val compose = createRobolectricComposeRule()
|
||||
|
||||
@After fun clearStore() {
|
||||
StoreState.sections.clear()
|
||||
StoreState.details.clear()
|
||||
StoreState.openRequest = null
|
||||
}
|
||||
|
||||
@Test fun openingAnAppReleasesTheCoveredNativeSearchField() {
|
||||
val id = "io.github.test.Datcord"
|
||||
StoreState.sections["popular"] = listOf(
|
||||
FlathubApi.AppSummary(id, "Datcord", "Discord client", "", null, false, 0),
|
||||
)
|
||||
StoreState.details[id] = FlathubApi.AppDetails(
|
||||
id, "Datcord", "Discord client", "", null, "", null, null, null,
|
||||
emptyList(), emptyList(), null, 0, 0, listOf("aarch64"),
|
||||
)
|
||||
lateinit var root: View
|
||||
val focus = FrontFocus()
|
||||
compose.setContent {
|
||||
DroidDeckTheme {
|
||||
val view = LocalView.current
|
||||
SideEffect { root = view.rootView }
|
||||
CompositionLocalProvider(LocalFrontFocus provides focus) {
|
||||
FocusGlideHost {
|
||||
Storefront(FrontEndState(
|
||||
installed = "r9", ready = true, available = null, busy = false, stage = "", percent = -1,
|
||||
desktopInstalled = true, offlineAccount = null, offline = false, frameGenLabel = "",
|
||||
romsDir = null, logsEnabled = false, steamGames = emptyList(), emulators = emptyList(), running = null,
|
||||
), FrontEndActions(
|
||||
onPlay = {}, onPlayDesktopUi = {}, onSteamGame = {}, onDesktop = {}, onEmulator = {},
|
||||
onRom = {}, onResume = {}, onSteamSettings = {}, onDesktopSettings = {},
|
||||
onInstallPackage = {}, onRemovePackage = {}, onRuntime = {}, onFrameGenPick = {},
|
||||
onImportLossless = {}, onProtons = {}, onComponents = {}, onPerformance = {},
|
||||
onRoms = {}, onFiles = {}, onLogs = {}, onOffline = {},
|
||||
onWirelessAdbPair = { _, _, _, _ -> }, onWirelessAdbApply = { _, _, _, _ -> },
|
||||
onSetPhantomProcessLimit = { _, _ -> },
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
val context = RuntimeEnvironment.getApplication()
|
||||
compose.onNodeWithContentDescription(context.getString(R.string.stores_search_open)).performClick()
|
||||
compose.waitForIdle()
|
||||
val field = editText(root)!!
|
||||
compose.runOnIdle {
|
||||
// Keep a nonempty query, so clearing focus cannot simply dispose the search field.
|
||||
// Whitespace skips the network search while retaining the field just like typed text.
|
||||
field.setText(" ")
|
||||
field.requestFocus()
|
||||
assertTrue(field.isFocused)
|
||||
}
|
||||
compose.waitForIdle()
|
||||
// Touching a card does not implicitly focus a Compose control or release an AndroidView.
|
||||
compose.onNodeWithText("Datcord").performSemanticsAction(SemanticsActions.OnClick) { it() }
|
||||
compose.onNodeWithText(context.getString(R.string.store_install)).assertExists()
|
||||
compose.runOnIdle {
|
||||
assertFalse("Covered search field must release focus", field.isFocused)
|
||||
assertEquals(" ", field.text.toString())
|
||||
focus.items.getValue("tile:store:$id").requestFocus()
|
||||
}
|
||||
compose.onNode(hasText("Datcord") and hasClickAction()).assertIsNotFocused()
|
||||
}
|
||||
|
||||
private fun editText(view: View): EditText? {
|
||||
if (view is EditText) return view
|
||||
if (view is ViewGroup) for (i in 0 until view.childCount) {
|
||||
editText(view.getChildAt(i))?.let { return it }
|
||||
}
|
||||
return null
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.runtime.SideEffect
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.snapshots.Snapshot
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.testTag
|
||||
import androidx.compose.ui.platform.LocalDensity
|
||||
import androidx.compose.ui.test.onNodeWithTag
|
||||
import androidx.compose.ui.test.onNodeWithText
|
||||
import androidx.compose.ui.test.performClick
|
||||
import androidx.compose.ui.unit.dp
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
// Render the component without starting runtime services or installing the app crash handler.
|
||||
@Config(sdk = [28], application = android.app.Application::class)
|
||||
class PresetScaleTest {
|
||||
@get:Rule val compose = createRobolectricComposeRule()
|
||||
|
||||
@Test fun presetPopupAndPageKeepTheScaleChosenInSetup() {
|
||||
val scale = mutableIntStateOf(100)
|
||||
val preset = mutableStateOf("PERFORMANCE")
|
||||
val open = mutableStateOf(false)
|
||||
compose.setContent {
|
||||
DroidDeckTheme(appScale = scale.intValue) {
|
||||
Box(Modifier.size(100.dp).testTag("page-size"))
|
||||
FexPresetChip(preset.value, false, open.value, true,
|
||||
onToggle = { open.value = true }, onDismiss = { open.value = false },
|
||||
onPick = { preset.value = it!! })
|
||||
}
|
||||
}
|
||||
val originalWidth = compose.onNodeWithTag("page-size").fetchSemanticsNode().boundsInRoot.width
|
||||
// Notify changes driven by the test before asking Compose to become idle again.
|
||||
compose.runOnIdle {
|
||||
scale.intValue = 75
|
||||
Snapshot.sendApplyNotifications()
|
||||
}
|
||||
compose.onNodeWithText("Performance").performClick()
|
||||
compose.onNodeWithText("Intermediate").performClick()
|
||||
compose.waitForIdle()
|
||||
assertEquals(originalWidth * 0.75f,
|
||||
compose.onNodeWithTag("page-size").fetchSemanticsNode().boundsInRoot.width, 1f)
|
||||
compose.runOnIdle {
|
||||
open.value = true
|
||||
Snapshot.sendApplyNotifications()
|
||||
}
|
||||
compose.onNodeWithText("Compatibility").performClick()
|
||||
compose.waitForIdle()
|
||||
assertEquals(originalWidth * 0.75f,
|
||||
compose.onNodeWithTag("page-size").fetchSemanticsNode().boundsInRoot.width, 1f)
|
||||
}
|
||||
|
||||
@Test fun menuUsesItsAnchorsDensity() {
|
||||
var pageDensity = 0f
|
||||
var menuDensity = 0f
|
||||
compose.setContent {
|
||||
DroidDeckTheme(appScale = 75) {
|
||||
val density = LocalDensity.current.density
|
||||
SideEffect { pageDensity = density }
|
||||
AnchoredMenu(true, onDismiss = {}) {
|
||||
val popupDensity = LocalDensity.current.density
|
||||
SideEffect { menuDensity = popupDensity }
|
||||
MenuItem("Preset", false) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
compose.waitForIdle()
|
||||
assertEquals(pageDensity, menuDensity, 0f)
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package com.droiddeck.launcher.ui
|
||||
import android.content.ComponentName
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.compose.ui.test.junit4.createComposeRule
|
||||
import androidx.compose.runtime.snapshots.Snapshot
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.Shadows.shadowOf
|
||||
|
||||
@@ -12,4 +13,7 @@ fun createRobolectricComposeRule() = createComposeRule().also {
|
||||
shadowOf(context.packageManager).addActivityIfNotPresent(
|
||||
ComponentName(context, ComponentActivity::class.java),
|
||||
)
|
||||
// Pure state tests can leave unapplied snapshots before a Compose host starts its snapshot
|
||||
// manager. Apply them before the rule's initial idle check, which runs before the test body.
|
||||
Snapshot.sendApplyNotifications()
|
||||
}
|
||||
Reference in new issue
Block a user