mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 20:36:04 +00:00
fix: open game Components on the game's profile (#1146)
This commit is contained in:
1 parent
aa5e9c3e91
commit
8ccd771059
7 files changed
+145
-16
No files matched your search
@@ -1,5 +1,6 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.ui.test.onNodeWithText
|
||||
import androidx.compose.ui.test.performClick
|
||||
import com.droiddeck.launcher.R
|
||||
@@ -15,9 +16,59 @@ import org.robolectric.annotation.Config
|
||||
@Config(sdk = [28])
|
||||
class ComponentsPageProfileTest {
|
||||
@get:Rule val compose = createRobolectricComposeRule()
|
||||
private val gameA = Library.SteamGame(42, "Game A", null, "internal")
|
||||
private val gameB = Library.SteamGame(43, "Game B", null, "internal")
|
||||
|
||||
@Test fun gameProfilesCoexistWithTheDefaultComponentStack() {
|
||||
val context = RuntimeEnvironment.getApplication()
|
||||
show()
|
||||
val stackHeading = context.getString(R.string.comp_this_proton).uppercase()
|
||||
compose.onNodeWithText(stackHeading).assertExists()
|
||||
compose.onNodeWithText(context.getString(R.string.comp_scope_general)).performClick()
|
||||
compose.onNodeWithText("Game A").performClick()
|
||||
compose.onNodeWithText(context.getString(R.string.comp_game_hint)).assertExists()
|
||||
compose.onNodeWithText(stackHeading).assertDoesNotExist()
|
||||
|
||||
compose.onNodeWithText("Game A").performClick()
|
||||
compose.onNodeWithText(context.getString(R.string.comp_scope_general)).performClick()
|
||||
compose.onNodeWithText(stackHeading).assertExists()
|
||||
}
|
||||
|
||||
@Test fun opensTheRequestedGameProfileAndAllowsSwitchingToDefault() {
|
||||
val context = RuntimeEnvironment.getApplication()
|
||||
show { gameB.profileKey }
|
||||
compose.onNodeWithText("Game B").assertExists()
|
||||
compose.onNodeWithText(context.getString(R.string.comp_game_hint)).assertExists()
|
||||
compose.onNodeWithText(context.getString(R.string.comp_this_proton).uppercase()).assertDoesNotExist()
|
||||
|
||||
compose.onNodeWithText("Game B").performClick()
|
||||
compose.onNodeWithText(context.getString(R.string.comp_scope_general)).performClick()
|
||||
compose.onNodeWithText(context.getString(R.string.comp_this_proton).uppercase()).assertExists()
|
||||
}
|
||||
|
||||
@Test fun aNewNavigationTargetReplacesThePreviousProfile() {
|
||||
val context = RuntimeEnvironment.getApplication()
|
||||
val target = mutableStateOf<String?>(gameA.profileKey)
|
||||
show { target.value }
|
||||
compose.onNodeWithText("Game A").assertExists()
|
||||
|
||||
compose.runOnIdle { target.value = gameB.profileKey }
|
||||
compose.onNodeWithText("Game B").assertExists()
|
||||
compose.onNodeWithText("Game A").assertDoesNotExist()
|
||||
|
||||
compose.runOnIdle { target.value = null }
|
||||
compose.onNodeWithText(context.getString(R.string.comp_scope_general)).assertExists()
|
||||
compose.onNodeWithText(context.getString(R.string.comp_this_proton).uppercase()).assertExists()
|
||||
}
|
||||
|
||||
@Test fun anUnavailableGameFallsBackToTheDefaultProfile() {
|
||||
val context = RuntimeEnvironment.getApplication()
|
||||
show { "missing-game" }
|
||||
compose.onNodeWithText(context.getString(R.string.comp_scope_general)).assertExists()
|
||||
compose.onNodeWithText(context.getString(R.string.comp_this_proton).uppercase()).assertExists()
|
||||
}
|
||||
|
||||
private fun show(initialGameKey: () -> String? = { null }) {
|
||||
compose.setContent {
|
||||
DroidDeckTheme {
|
||||
ComponentsPage(
|
||||
@@ -40,20 +91,11 @@ class ComponentsPageProfileTest {
|
||||
onRefresh = {},
|
||||
onImport = {},
|
||||
onBack = {},
|
||||
games = listOf(Library.SteamGame(42, "Game A", null, "internal")),
|
||||
games = listOf(gameA, gameB),
|
||||
initialGameKey = initialGameKey(),
|
||||
requestInitialFocus = false,
|
||||
)
|
||||
}
|
||||
}
|
||||
val stackHeading = context.getString(R.string.comp_this_proton).uppercase()
|
||||
compose.onNodeWithText(stackHeading).assertExists()
|
||||
compose.onNodeWithText(context.getString(R.string.comp_scope_general)).performClick()
|
||||
compose.onNodeWithText("Game A").performClick()
|
||||
compose.onNodeWithText(context.getString(R.string.comp_game_hint)).assertExists()
|
||||
compose.onNodeWithText(stackHeading).assertDoesNotExist()
|
||||
|
||||
compose.onNodeWithText("Game A").performClick()
|
||||
compose.onNodeWithText(context.getString(R.string.comp_scope_general)).performClick()
|
||||
compose.onNodeWithText(stackHeading).assertExists()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import androidx.compose.ui.test.onNodeWithText
|
||||
import androidx.compose.ui.test.performClick
|
||||
import com.droiddeck.launcher.R
|
||||
import com.droiddeck.launcher.frontend.Library
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNull
|
||||
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])
|
||||
class LaunchSettingsComponentsTest {
|
||||
@get:Rule val compose = createRobolectricComposeRule()
|
||||
private var openedGame: Library.SteamGame? = null
|
||||
private var defaultOpens = 0
|
||||
|
||||
@Test fun gameComponentsCardPassesItsGameInsteadOfOpeningDefault() {
|
||||
val game = Library.SteamGame(42, "Game A", null, "internal")
|
||||
show(game)
|
||||
clickComponents()
|
||||
assertEquals(game, openedGame)
|
||||
assertEquals(0, defaultOpens)
|
||||
}
|
||||
|
||||
@Test fun addedGameComponentsCardPreservesItsUnsignedProfileKey() {
|
||||
val game = Library.SteamGame(-42, "Added game", null, Library.ADDED)
|
||||
show(game)
|
||||
clickComponents()
|
||||
assertEquals(game.profileKey, openedGame?.profileKey)
|
||||
assertEquals("4294967254", openedGame?.profileKey)
|
||||
assertEquals(0, defaultOpens)
|
||||
}
|
||||
|
||||
@Test fun generalComponentsCardStillOpensDefault() {
|
||||
show(null)
|
||||
clickComponents()
|
||||
assertNull(openedGame)
|
||||
assertEquals(1, defaultOpens)
|
||||
}
|
||||
|
||||
private fun clickComponents() {
|
||||
compose.onNodeWithText(RuntimeEnvironment.getApplication().getString(R.string.setup_card_components)).performClick()
|
||||
compose.waitForIdle()
|
||||
}
|
||||
|
||||
private fun show(game: Library.SteamGame?) {
|
||||
compose.setContent {
|
||||
DroidDeckTheme {
|
||||
LaunchSettings(
|
||||
FrontEndState(
|
||||
installed = null, ready = false, available = null, busy = false, stage = "", percent = -1,
|
||||
desktopInstalled = false, offlineAccount = null, offline = false, frameGenLabel = "",
|
||||
romsDir = null, logsEnabled = false, steamGames = listOfNotNull(game),
|
||||
emulators = emptyList(), running = null,
|
||||
),
|
||||
FrontEndActions(
|
||||
onPlay = {}, onPlayDesktopUi = {}, onSteamGame = {}, onDesktop = {}, onEmulator = {},
|
||||
onRom = {}, onResume = {}, onSteamSettings = {}, onDesktopSettings = {},
|
||||
onInstallPackage = {}, onRemovePackage = {}, onRuntime = {}, onFrameGenPick = {},
|
||||
onImportLossless = {}, onProtons = {}, onComponents = { defaultOpens++ },
|
||||
onGameComponents = { openedGame = it }, onPerformance = {},
|
||||
onRoms = {}, onFiles = {}, onLogs = {}, onOffline = {},
|
||||
onWirelessAdbPair = { _, _, _, _ -> }, onWirelessAdbApply = { _, _, _, _ -> },
|
||||
onSetPhantomProcessLimit = { _, _ -> },
|
||||
),
|
||||
rememberMenuHost(),
|
||||
game,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user