mirror of
https://github.com/JustinZeus/Wholphin.git
synced 2026-07-09 08:01:20 +02:00
Add some tests to ensure samples
This commit is contained in:
parent
d809cc2be4
commit
2da34a8f56
3 changed files with 115 additions and 4 deletions
|
|
@ -83,6 +83,7 @@ sealed class HomeRowConfig {
|
|||
}
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class HomeRowConfigDisplay(
|
||||
val title: String,
|
||||
val config: HomeRowConfig,
|
||||
|
|
|
|||
|
|
@ -52,7 +52,6 @@ import dagger.hilt.android.qualifiers.ApplicationContext
|
|||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.serialization.json.Json
|
||||
import org.jellyfin.sdk.api.client.ApiClient
|
||||
import org.jellyfin.sdk.api.client.extensions.userLibraryApi
|
||||
import org.jellyfin.sdk.model.api.CollectionType
|
||||
|
|
@ -61,7 +60,6 @@ import org.jellyfin.sdk.model.api.SortOrder
|
|||
import org.jellyfin.sdk.model.api.request.GetGenresRequest
|
||||
import org.jellyfin.sdk.model.api.request.GetItemsRequest
|
||||
import org.jellyfin.sdk.model.api.request.GetLatestMediaRequest
|
||||
import timber.log.Timber
|
||||
import java.util.UUID
|
||||
import javax.inject.Inject
|
||||
|
||||
|
|
@ -151,8 +149,8 @@ class HomePageSettingsViewModel
|
|||
_state.update {
|
||||
it.copy(rows = rowConfig)
|
||||
}
|
||||
val json = Json.encodeToString(rowConfig.map { it.config })
|
||||
Timber.v("json=$json")
|
||||
// val json = Json.encodeToString(rowConfig)
|
||||
// Timber.v("json=$json")
|
||||
|
||||
fetchRowData()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,112 @@
|
|||
package com.github.damontecres.wholphin.test
|
||||
|
||||
import com.github.damontecres.wholphin.data.model.HomeRowConfig
|
||||
import com.github.damontecres.wholphin.data.model.HomeRowConfigDisplay
|
||||
import com.github.damontecres.wholphin.data.model.HomeRowViewOptions
|
||||
import com.github.damontecres.wholphin.preferences.PrefContentScale
|
||||
import com.github.damontecres.wholphin.ui.AspectRatio
|
||||
import com.github.damontecres.wholphin.ui.components.ViewOptionImageType
|
||||
import kotlinx.serialization.json.Json
|
||||
import org.jellyfin.sdk.model.UUID
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
class TestHomeRowSamples {
|
||||
companion object {
|
||||
val SAMPLES =
|
||||
listOf(
|
||||
HomeRowConfigDisplay(
|
||||
title = "Recently added",
|
||||
config =
|
||||
HomeRowConfig.RecentlyAdded(
|
||||
id = 0,
|
||||
parentId = UUID.randomUUID(),
|
||||
viewOptions =
|
||||
HomeRowViewOptions(
|
||||
heightDp = 100,
|
||||
spacing = 8,
|
||||
contentScale = PrefContentScale.CROP,
|
||||
aspectRatio = AspectRatio.FOUR_THREE,
|
||||
imageType = ViewOptionImageType.THUMB,
|
||||
showTitles = false,
|
||||
useSeries = false,
|
||||
),
|
||||
),
|
||||
),
|
||||
HomeRowConfigDisplay(
|
||||
title = "Recently released",
|
||||
config =
|
||||
HomeRowConfig.RecentlyReleased(
|
||||
id = 0,
|
||||
parentId = UUID.randomUUID(),
|
||||
viewOptions = HomeRowViewOptions(),
|
||||
),
|
||||
),
|
||||
HomeRowConfigDisplay(
|
||||
title = "Genres",
|
||||
config =
|
||||
HomeRowConfig.Genres(
|
||||
id = 0,
|
||||
parentId = UUID.randomUUID(),
|
||||
viewOptions = HomeRowViewOptions(),
|
||||
),
|
||||
),
|
||||
HomeRowConfigDisplay(
|
||||
title = "Continue watching",
|
||||
config =
|
||||
HomeRowConfig.ContinueWatching(
|
||||
id = 0,
|
||||
viewOptions = HomeRowViewOptions(),
|
||||
),
|
||||
),
|
||||
HomeRowConfigDisplay(
|
||||
title = "Next up",
|
||||
config =
|
||||
HomeRowConfig.NextUp(
|
||||
id = 0,
|
||||
viewOptions = HomeRowViewOptions(),
|
||||
),
|
||||
),
|
||||
HomeRowConfigDisplay(
|
||||
title = "Combined",
|
||||
config =
|
||||
HomeRowConfig.ContinueWatchingCombined(
|
||||
id = 0,
|
||||
viewOptions = HomeRowViewOptions(),
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Check all types have a sample`() {
|
||||
// This ensures there is a sample for each possible HomeRowConfig type
|
||||
val foundTypes = mutableSetOf<KClass<out HomeRowConfig>>()
|
||||
SAMPLES.forEach {
|
||||
when (it.config) {
|
||||
is HomeRowConfig.ContinueWatching -> foundTypes.add(HomeRowConfig.ContinueWatching::class)
|
||||
is HomeRowConfig.ContinueWatchingCombined -> foundTypes.add(HomeRowConfig.ContinueWatchingCombined::class)
|
||||
is HomeRowConfig.Genres -> foundTypes.add(HomeRowConfig.Genres::class)
|
||||
is HomeRowConfig.NextUp -> foundTypes.add(HomeRowConfig.NextUp::class)
|
||||
is HomeRowConfig.RecentlyAdded -> foundTypes.add(HomeRowConfig.RecentlyAdded::class)
|
||||
is HomeRowConfig.RecentlyReleased -> foundTypes.add(HomeRowConfig.RecentlyReleased::class)
|
||||
}
|
||||
}
|
||||
Assert.assertEquals(HomeRowConfig::class.sealedSubclasses.size, foundTypes.size)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Print sample JSON`() {
|
||||
// This just prints out the JSON of the samples so developers can review
|
||||
val json =
|
||||
Json {
|
||||
ignoreUnknownKeys = true
|
||||
isLenient = true
|
||||
prettyPrint = true
|
||||
}
|
||||
val string = json.encodeToString(SAMPLES)
|
||||
println(string)
|
||||
json.decodeFromString<List<HomeRowConfigDisplay>>(string)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue