mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-22 06:15:58 +00:00
feat(library): add a Favorites tab and a heart button on the game page (#2613)
* Add a Favorites tab to the Library with a heart on the game page * Fix favorites test helper call
This commit is contained in:
1 parent
76c4de5b5d
commit
50fbcf8b2a
5 files changed
+134
-8
No files matched your search
@@ -0,0 +1,53 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import com.droiddeck.launcher.frontend.Library
|
||||
import com.droiddeck.launcher.stores.CatalogItem
|
||||
import com.droiddeck.launcher.stores.Store
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
class LibraryFavoritesTest {
|
||||
private fun steam(id: Int, name: String) = LibraryEntry("app:$id", Library.SOURCE_STEAM, name, Library.SteamGame(id, name, null, "Steam library"), null, true)
|
||||
|
||||
private fun owned(id: String, name: String): LibraryEntry {
|
||||
val item = CatalogItem(Store.GOG, id, name, imageUrl = null, owned = true)
|
||||
return LibraryEntry("app:gog:$id", Store.GOG.id, name, null, item, false)
|
||||
}
|
||||
|
||||
@Test fun togglingAddsThenRemovesAKey() {
|
||||
val on = toggled(emptySet(), "app:440")
|
||||
assertEquals(setOf("app:440"), on)
|
||||
assertEquals(emptySet<String>(), toggled(on, "app:440"))
|
||||
}
|
||||
|
||||
@Test fun aStoreGameIsKeyedByItsStoreProductSoInstallingItKeepsTheHeart() {
|
||||
val entry = owned("123", "Witcher")
|
||||
assertEquals("gog:123", entry.favoriteKey)
|
||||
val installed = LibraryEntry("app:-5", "gog", "Game", Library.SteamGame(-5, "Game", null, Library.ADDED, source = "gog", storeId = "123"), null, true)
|
||||
assertEquals(entry.favoriteKey, installed.favoriteKey)
|
||||
}
|
||||
|
||||
@Test fun aGameWithoutAStoreIsKeyedByItsLibraryKey() {
|
||||
assertEquals("app:440", steam(440, "Team Fortress 2").favoriteKey)
|
||||
}
|
||||
|
||||
@Test fun theFavoritesSourceKeepsOnlyHeartedGamesFromEveryStore() {
|
||||
val tf2 = steam(440, "Team Fortress 2")
|
||||
val witcher = owned("123", "Witcher")
|
||||
val other = steam(10, "Counter-Strike")
|
||||
val hearts = setOf(tf2.favoriteKey, witcher.favoriteKey)
|
||||
val shown = listOf(tf2, witcher, other).filter { inLibrarySource(LIBRARY_FAVORITES, it, hearts) }
|
||||
assertEquals(listOf(tf2, witcher), shown)
|
||||
assertTrue(inLibrarySource(LIBRARY_ALL, other, hearts))
|
||||
assertFalse(inLibrarySource(Store.GOG.id, tf2, hearts))
|
||||
}
|
||||
|
||||
@Test fun theFavoritesTabComesFirstAndOnlyAppearsOnceSomethingIsHearted() {
|
||||
val entries = listOf(steam(440, "Team Fortress 2"), owned("123", "Witcher"))
|
||||
assertEquals(listOf("steam", "gog"), librarySources(entries, listOf("gog")))
|
||||
assertEquals(listOf(LIBRARY_FAVORITES, "steam", "gog"), librarySources(entries, listOf("gog"), favorites = setOf("gog:123")))
|
||||
assertEquals(listOf("steam", "gog"), librarySources(entries, listOf("gog"), favorites = setOf("gog:999")))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user