mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 20:36:04 +00:00
feat(ui): add game resource links (#1630)
This commit is contained in:
1 parent
830c753312
commit
c8f650e167
5 files changed
+207
No files matched your search
@@ -0,0 +1,63 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import android.content.Intent
|
||||
import androidx.compose.ui.input.InputMode
|
||||
import androidx.compose.ui.input.InputModeManager
|
||||
import androidx.compose.ui.input.key.Key
|
||||
import androidx.compose.ui.platform.LocalInputModeManager
|
||||
import androidx.compose.ui.test.assertIsDisplayed
|
||||
import androidx.compose.ui.test.assertIsFocused
|
||||
import androidx.compose.ui.test.onNodeWithText
|
||||
import androidx.compose.ui.test.performClick
|
||||
import androidx.compose.ui.test.performKeyInput
|
||||
import androidx.compose.ui.test.pressKey
|
||||
import androidx.compose.ui.test.requestFocus
|
||||
import com.droiddeck.launcher.R
|
||||
import com.droiddeck.launcher.frontend.Library
|
||||
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.RuntimeEnvironment
|
||||
import org.robolectric.Shadows.shadowOf
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
@OptIn(androidx.compose.ui.test.ExperimentalTestApi::class, androidx.compose.ui.ExperimentalComposeUiApi::class)
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [34], qualifiers = "w360dp-h640dp-port", application = android.app.Application::class)
|
||||
class GameResourcesRowTest {
|
||||
@get:Rule val compose = createRobolectricComposeRule()
|
||||
private val ctx get() = RuntimeEnvironment.getApplication()
|
||||
private val game = Library.SteamGame(292030, "The Witcher 3", null, "/steam")
|
||||
|
||||
@Test fun everyResourceIsReachableOnANarrowPageAndOpensTheExpectedBrowserUrl() {
|
||||
compose.setContent { DroidDeckTheme { GameResourcesRow(game.name, game) } }
|
||||
for (link in gameResources(game.name, game)) {
|
||||
compose.onNodeWithText(ctx.getString(link.label)).assertIsDisplayed().performClick()
|
||||
val intent = shadowOf(ctx).nextStartedActivity
|
||||
assertEquals(Intent.ACTION_VIEW, intent.action)
|
||||
assertEquals(link.url, intent.dataString)
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun controllerCanMoveBetweenLinksAndOpenAResource() {
|
||||
lateinit var inputMode: InputModeManager
|
||||
compose.setContent { DroidDeckTheme {
|
||||
inputMode = LocalInputModeManager.current
|
||||
GameResourcesRow(game.name, game)
|
||||
} }
|
||||
compose.runOnIdle { inputMode.requestInputMode(InputMode.Keyboard) }
|
||||
compose.onNodeWithText(ctx.getString(R.string.game_resource_pcgw)).requestFocus().assertIsFocused().performKeyInput { pressKey(Key.DirectionRight) }
|
||||
compose.onNodeWithText(ctx.getString(R.string.game_resource_guides)).assertIsFocused().performKeyInput { pressKey(Key.ButtonA) }
|
||||
assertEquals(gameResources(game.name, game)[1].url, shadowOf(ctx).nextStartedActivity.dataString)
|
||||
}
|
||||
|
||||
@Test @Config(qualifiers = "w640dp-h360dp-land")
|
||||
fun shortLandscapeWindowsKeepEveryResourceVisible() {
|
||||
compose.setContent { DroidDeckTheme { GameResourcesRow(game.name, game) } }
|
||||
for (link in gameResources(game.name, game)) {
|
||||
compose.onNodeWithText(ctx.getString(link.label)).assertIsDisplayed()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import com.droiddeck.launcher.R
|
||||
import com.droiddeck.launcher.frontend.Library
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import java.net.URI
|
||||
import java.net.URLDecoder
|
||||
|
||||
class GameResourcesTest {
|
||||
@Test fun searchesPreserveUnicodeAndEscapeQueryDelimiters() {
|
||||
val title = "Ōkami HD & friends + 100% #1?"
|
||||
val links = gameResources(" $title ", null)
|
||||
assertEquals(3, links.size)
|
||||
links.forEach { link ->
|
||||
val uri = URI(link.url)
|
||||
assertEquals("https", uri.scheme)
|
||||
assertEquals(null, uri.fragment)
|
||||
assertEquals(title, URLDecoder.decode(uri.rawQuery.substringAfter('='), "UTF-8"))
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun onlySteamClientGamesGetAppSpecificSteamResources() {
|
||||
val steam = Library.SteamGame(292030, "The Witcher 3", null, "/steam")
|
||||
val links = gameResources(steam.name, steam)
|
||||
assertEquals("https://www.protondb.com/app/292030", links.single { it.label == R.string.game_resource_protondb }.url)
|
||||
assertEquals("https://store.steampowered.com/account/remotestorageapp/?appid=292030", links.single { it.label == R.string.game_resource_steam_cloud }.url)
|
||||
val others = listOf(
|
||||
Library.SteamGame(292030, steam.name, null, Library.ADDED),
|
||||
Library.SteamGame(292030, steam.name, null, Library.ADDED, source = "gog", storeId = "292030"),
|
||||
Library.SteamGame(292030, steam.name, null, Library.XBOX_CLOUD, source = "xbox"),
|
||||
Library.SteamGame(-1, steam.name, null, "/steam"),
|
||||
)
|
||||
others.forEach { game ->
|
||||
assertEquals(3, gameResources(game.name, game).size)
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun loadingPagesHaveNoResourcesUntilTheyHaveATitle() {
|
||||
assertTrue(gameResources(" ", null).isEmpty())
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user