mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 20:36:04 +00:00
itch.io: browse the Store tab by sort and price, with paging and a disk cache
The Store tab only had four fixed shelves and a title search. A row of sort (Popular, New, Top rated, Top sellers) and price (Any, Free, On sale) chips now sets a BrowseQuery; anything but the defaults swaps the shelves for that query's games, loaded page by page as the grid scrolls. ItchBrowse builds itch's listing-feed URL (platform and tag segments are in the builder for the next change), tries each spelling of a price filter until one answers, spaces requests 1.2 s apart, backs off once on a 429, and keeps pages in the app cache for three hours. Every request is logged with its status and game count so a wrong URL guess can be fixed from a device. Owned games replace their browse copy so Install and the owned markers are right, and the detail page finds browse results. Strings for all 33 locales; URL-builder tests; docs/development/itch-browse.md.
This commit is contained in:
40 files changed
+708
-8
No files matched your search
@@ -0,0 +1,54 @@
|
||||
package com.droiddeck.launcher.stores.itch
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
class ItchBrowseTest {
|
||||
@Test fun theDefaultQueryIsTheFrontPage() {
|
||||
assertTrue(BrowseQuery().isDefault)
|
||||
assertFalse(BrowseQuery(sort = ItchBrowse.SORT_NEW).isDefault)
|
||||
assertFalse(BrowseQuery(price = ItchBrowse.PRICE_FREE).isDefault)
|
||||
}
|
||||
|
||||
@Test fun sortsMapToTheirFeedPaths() {
|
||||
assertEquals(listOf("https://itch.io/games.xml"), ItchBrowse.urls(BrowseQuery(), 1))
|
||||
assertEquals(listOf("https://itch.io/games/newest.xml"), ItchBrowse.urls(BrowseQuery(sort = ItchBrowse.SORT_NEW), 1))
|
||||
assertEquals(listOf("https://itch.io/games/top-rated.xml"), ItchBrowse.urls(BrowseQuery(sort = ItchBrowse.SORT_TOP_RATED), 1))
|
||||
assertEquals(listOf("https://itch.io/games/top-sellers.xml"), ItchBrowse.urls(BrowseQuery(sort = ItchBrowse.SORT_TOP_SELLERS), 1))
|
||||
}
|
||||
|
||||
@Test fun pagesAfterTheFirstCarryThePageNumber() {
|
||||
assertEquals(listOf("https://itch.io/games/newest.xml?page=3"), ItchBrowse.urls(BrowseQuery(sort = ItchBrowse.SORT_NEW), 3))
|
||||
}
|
||||
|
||||
@Test fun aPriceFilterOffersEverySpellingInOrder() {
|
||||
val free = ItchBrowse.urls(BrowseQuery(sort = ItchBrowse.SORT_TOP_RATED, price = ItchBrowse.PRICE_FREE), 1)
|
||||
assertEquals(listOf("https://itch.io/games/top-rated/free.xml", "https://itch.io/games/top-rated/price-free.xml"), free)
|
||||
assertEquals(listOf("https://itch.io/games/on-sale.xml"), ItchBrowse.urls(BrowseQuery(price = ItchBrowse.PRICE_SALE), 1))
|
||||
}
|
||||
|
||||
@Test fun platformsAndTagsFollowTheSortAndPriceInAFixedOrder() {
|
||||
val query = BrowseQuery(
|
||||
sort = ItchBrowse.SORT_NEW, price = ItchBrowse.PRICE_SALE,
|
||||
platforms = setOf("web", "linux"), tags = listOf("Pixel Art", "Horror"),
|
||||
)
|
||||
assertEquals(
|
||||
listOf("https://itch.io/games/newest/on-sale/platform-linux/platform-web/tag-pixel-art/tag-horror.xml"),
|
||||
ItchBrowse.urls(query, 1),
|
||||
)
|
||||
}
|
||||
|
||||
@Test fun tagsBecomeSlugs() {
|
||||
assertEquals("pixel-art", ItchBrowse.tagSlug(" Pixel Art "))
|
||||
assertEquals("2d", ItchBrowse.tagSlug("2D"))
|
||||
assertEquals("sci-fi", ItchBrowse.tagSlug("Sci-Fi!"))
|
||||
}
|
||||
|
||||
@Test fun theSamePlatformsInAnyOrderGiveTheSameUrl() {
|
||||
val a = ItchBrowse.urls(BrowseQuery(platforms = setOf("web", "linux")), 1)
|
||||
val b = ItchBrowse.urls(BrowseQuery(platforms = setOf("linux", "web")), 1)
|
||||
assertEquals(a, b)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user