The first public release of Fabled Minstrel #158
-10
@@ -103,14 +103,4 @@ class LibraryRepositoryTest {
|
|||||||
coVerify { artistDao.upsertAll(match { it.size == 1 && it[0].id == "a1" }) }
|
coVerify { artistDao.upsertAll(match { it.size == 1 && it[0].id == "a1" }) }
|
||||||
coVerify { albumDao.upsertAll(match { it.size == 2 && it[0].id == "al1" && it[1].id == "al2" }) }
|
coVerify { albumDao.upsertAll(match { it.size == 2 && it[0].id == "al1" && it[1].id == "al2" }) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `getArtist returns null when DAO is empty`() = runTest {
|
|
||||||
coEvery { artistDao.getById("missing") } returns null
|
|
||||||
val repo = LibraryRepository(artistDao, albumDao, trackDao, retrofit)
|
|
||||||
|
|
||||||
val result = repo.getArtist("missing")
|
|
||||||
|
|
||||||
assertEquals(null, result)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,26 +1,19 @@
|
|||||||
package com.fabledsword.minstrel.models
|
package com.fabledsword.minstrel.models
|
||||||
|
|
||||||
|
import com.fabledsword.minstrel.api.BaseUrlInterceptor
|
||||||
|
import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
class CoverUrlsTest {
|
class CoverUrlsTest {
|
||||||
|
// A cover is fetched through the placeholder host, which BaseUrlInterceptor
|
||||||
|
// rewrites to the live server and AuthCookieInterceptor signs; any other
|
||||||
|
// host would load without the session. A blank id has no picture.
|
||||||
@Test
|
@Test
|
||||||
fun `albumCoverPath builds the placeholder cover URL`() {
|
fun `covers and artist images go through the host the interceptors rewrite`() {
|
||||||
assertEquals("http://placeholder.invalid/api/albums/a1/cover", albumCoverPath("a1"))
|
assertEquals(BaseUrlInterceptor.PLACEHOLDER_HOST, albumCoverPath("a1").toHttpUrl().host)
|
||||||
}
|
assertEquals(BaseUrlInterceptor.PLACEHOLDER_HOST, artistImagePath("r1").toHttpUrl().host)
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `albumCoverPath is empty for a blank id`() {
|
|
||||||
assertEquals("", albumCoverPath(""))
|
assertEquals("", albumCoverPath(""))
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `artistImagePath builds the placeholder artist image URL`() {
|
|
||||||
assertEquals("http://placeholder.invalid/api/artists/r1/image", artistImagePath("r1"))
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `artistImagePath is empty for a blank id`() {
|
|
||||||
assertEquals("", artistImagePath(""))
|
assertEquals("", artistImagePath(""))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,47 +7,18 @@ import kotlin.test.assertTrue
|
|||||||
|
|
||||||
class RemotePlayerStateTest {
|
class RemotePlayerStateTest {
|
||||||
|
|
||||||
|
// A renderer error stops playback and is kept to report, but what the
|
||||||
|
// listener asked for survives it, so a failed play can resume locally.
|
||||||
@Test
|
@Test
|
||||||
fun `starts in idle state`() {
|
fun `an error stops playback and is recorded, and the play intent survives it`() {
|
||||||
val state = RemotePlayerState()
|
|
||||||
assertFalse(state.isPlaying)
|
|
||||||
assertEquals(0L, state.positionMs)
|
|
||||||
assertEquals(0L, state.durationMs)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `applyPositionInfo updates position, duration, and trackNumber`() {
|
|
||||||
val state = RemotePlayerState()
|
|
||||||
state.applyPositionInfo(
|
|
||||||
positionMs = 65_000L, durationMs = 210_000L, trackUri = "x", trackNumber = 3,
|
|
||||||
)
|
|
||||||
assertEquals(65_000L, state.positionMs)
|
|
||||||
assertEquals(210_000L, state.durationMs)
|
|
||||||
assertEquals("x", state.currentTrackUri)
|
|
||||||
assertEquals(3, state.trackNumber)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `applyTransportPlaying flips isPlaying true`() {
|
|
||||||
val state = RemotePlayerState()
|
val state = RemotePlayerState()
|
||||||
state.applyTransportPlaying()
|
state.applyTransportPlaying()
|
||||||
assertTrue(state.isPlaying)
|
state.setPlayIntent(true)
|
||||||
}
|
val ex = RuntimeException("connect timeout")
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `applyTransportPaused flips isPlaying false`() {
|
|
||||||
val state = RemotePlayerState().apply { applyTransportPlaying() }
|
|
||||||
state.applyTransportPaused()
|
|
||||||
assertFalse(state.isPlaying)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `applyError resets to idle and records error`() {
|
|
||||||
val state = RemotePlayerState().apply { applyTransportPlaying() }
|
|
||||||
val ex = RuntimeException("disconnected")
|
|
||||||
state.applyError(ex)
|
state.applyError(ex)
|
||||||
assertFalse(state.isPlaying)
|
assertFalse(state.isPlaying)
|
||||||
assertEquals(ex, state.lastError)
|
assertEquals(ex, state.lastError)
|
||||||
|
assertTrue(state.lastPlayIntent)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -69,24 +40,6 @@ class RemotePlayerStateTest {
|
|||||||
assertFalse(state.recordPollFailure())
|
assertFalse(state.recordPollFailure())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `play intent survives a SOAP error so a failed play can resume locally`() {
|
|
||||||
val state = RemotePlayerState()
|
|
||||||
state.setPlayIntent(true)
|
|
||||||
state.applyError(RuntimeException("connect timeout"))
|
|
||||||
// isPlaying is cleared by the error, but the user's intent persists.
|
|
||||||
assertFalse(state.isPlaying)
|
|
||||||
assertTrue(state.lastPlayIntent)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `pausing clears play intent`() {
|
|
||||||
val state = RemotePlayerState()
|
|
||||||
state.setPlayIntent(true)
|
|
||||||
state.setPlayIntent(false)
|
|
||||||
assertFalse(state.lastPlayIntent)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `reset clears play intent`() {
|
fun `reset clears play intent`() {
|
||||||
val state = RemotePlayerState()
|
val state = RemotePlayerState()
|
||||||
|
|||||||
+17
-47
@@ -1,55 +1,25 @@
|
|||||||
package com.fabledsword.minstrel.player.output
|
package com.fabledsword.minstrel.player.output
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.params.ParameterizedTest
|
||||||
|
import org.junit.jupiter.params.provider.CsvSource
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The idle timer arms when a speaker sits paused, and is cancelled by
|
||||||
|
* playing again or leaving the speaker; anything else leaves it as it is.
|
||||||
|
*/
|
||||||
class IdleRevertDecisionTest {
|
class IdleRevertDecisionTest {
|
||||||
|
|
||||||
@Test
|
@ParameterizedTest(name = "engaged={0} playing={1} armed={2} -> {3}")
|
||||||
fun `engaged and paused and not armed arms the timer`() {
|
@CsvSource(
|
||||||
assertEquals(
|
"true, false, false, ARM",
|
||||||
IdleRevertAction.ARM,
|
"true, false, true, IGNORE",
|
||||||
idleRevertAction(upnpEngaged = true, isPlaying = false, armed = false),
|
"true, true, true, CANCEL",
|
||||||
)
|
"true, true, false, IGNORE",
|
||||||
}
|
"false, false, true, CANCEL",
|
||||||
|
"false, true, false, IGNORE",
|
||||||
@Test
|
)
|
||||||
fun `engaged and paused and already armed is ignored`() {
|
fun `the idle timer`(engaged: Boolean, playing: Boolean, armed: Boolean, want: String) {
|
||||||
assertEquals(
|
assertEquals(want, idleRevertAction(upnpEngaged = engaged, isPlaying = playing, armed = armed).name)
|
||||||
IdleRevertAction.IGNORE,
|
|
||||||
idleRevertAction(upnpEngaged = true, isPlaying = false, armed = true),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `resuming playback cancels an armed timer`() {
|
|
||||||
assertEquals(
|
|
||||||
IdleRevertAction.CANCEL,
|
|
||||||
idleRevertAction(upnpEngaged = true, isPlaying = true, armed = true),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `playing with no timer armed is ignored`() {
|
|
||||||
assertEquals(
|
|
||||||
IdleRevertAction.IGNORE,
|
|
||||||
idleRevertAction(upnpEngaged = true, isPlaying = true, armed = false),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `disengaging UPnP cancels an armed timer`() {
|
|
||||||
assertEquals(
|
|
||||||
IdleRevertAction.CANCEL,
|
|
||||||
idleRevertAction(upnpEngaged = false, isPlaying = false, armed = true),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `disengaged with no timer armed is ignored`() {
|
|
||||||
assertEquals(
|
|
||||||
IdleRevertAction.IGNORE,
|
|
||||||
idleRevertAction(upnpEngaged = false, isPlaying = true, armed = false),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-25
@@ -6,38 +6,23 @@ import kotlin.test.assertEquals
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The Sonos queue plays straight through, so a track's album play is judged
|
* The Sonos queue plays straight through, so a track's album play is judged
|
||||||
* from its neighbours in the list sent.
|
* from its neighbours in the list sent. The rule itself is GainMath's and is
|
||||||
|
* tested there; this checks the queue hands it each track's neighbours, and
|
||||||
|
* that a track with no album counts as none.
|
||||||
*/
|
*/
|
||||||
class SonosAlbumPlayTest {
|
class SonosAlbumPlayTest {
|
||||||
|
|
||||||
private fun t(album: String, n: Int?, disc: Int? = null) =
|
private fun t(album: String, n: Int?) =
|
||||||
TrackRef(id = "$album-$disc-$n", title = "", albumId = album, artistId = "", trackNumber = n, discNumber = disc)
|
TrackRef(id = "$album-$n", title = "", albumId = album, artistId = "", trackNumber = n)
|
||||||
|
|
||||||
private fun asAlbum(queue: List<TrackRef>) = queue.indices.map { SonosQueueLoader.playingAsAlbum(queue, it) }
|
private fun asAlbum(queue: List<TrackRef>) = queue.indices.map { SonosQueueLoader.playingAsAlbum(queue, it) }
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `an album in order plays as an album throughout`() {
|
fun `each track is judged by its own neighbours in the queue`() {
|
||||||
assertEquals(listOf(true, true, true), asAlbum(listOf(t("a", 1), t("a", 2), t("a", 3))))
|
assertEquals(
|
||||||
}
|
listOf(true, true, false, false),
|
||||||
|
asAlbum(listOf(t("a", 1), t("a", 2), t("b", 7), t("c", 1))),
|
||||||
@Test
|
)
|
||||||
fun `a mix of albums plays as singles`() {
|
|
||||||
assertEquals(listOf(false, false, false), asAlbum(listOf(t("a", 1), t("b", 1), t("c", 4))))
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `album order runs across discs`() {
|
|
||||||
assertEquals(listOf(true, true), asAlbum(listOf(t("a", 12, disc = 1), t("a", 1, disc = 2))))
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `shuffled tracks of one album are not album play`() {
|
|
||||||
assertEquals(listOf(false, false), asAlbum(listOf(t("a", 3), t("a", 1))))
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `unnumbered tracks and missing albums are never album play`() {
|
|
||||||
assertEquals(listOf(false, false), asAlbum(listOf(t("a", null), t("a", null))))
|
|
||||||
assertEquals(listOf(false, false), asAlbum(listOf(t("", 1), t("", 2))))
|
assertEquals(listOf(false, false), asAlbum(listOf(t("", 1), t("", 2))))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-32
@@ -104,18 +104,6 @@ class AVTransportClientTest {
|
|||||||
assertEquals(TransportState.UNKNOWN, info.state)
|
assertEquals(TransportState.UNKNOWN, info.state)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `removeAllTracksFromQueue sends correct SOAP action`() = runTest {
|
|
||||||
server.enqueue(emptyResponse("RemoveAllTracksFromQueue"))
|
|
||||||
client.removeAllTracksFromQueue()
|
|
||||||
val request = server.takeRequest()
|
|
||||||
assertTrue(request.getHeader("SOAPACTION").orEmpty().contains("RemoveAllTracksFromQueue")) {
|
|
||||||
"SOAPACTION header missing action: ${request.getHeader("SOAPACTION")}"
|
|
||||||
}
|
|
||||||
val body = request.body.readUtf8()
|
|
||||||
assertTrue(body.contains("RemoveAllTracksFromQueue")) { "body: $body" }
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `addURIToQueue sends EnqueuedURI and DIDL-Lite metadata`() = runTest {
|
fun `addURIToQueue sends EnqueuedURI and DIDL-Lite metadata`() = runTest {
|
||||||
server.enqueue(emptyResponse("AddURIToQueue"))
|
server.enqueue(emptyResponse("AddURIToQueue"))
|
||||||
@@ -137,26 +125,6 @@ class AVTransportClientTest {
|
|||||||
assertTrue(body.contains("audio/mpeg")) { "mime missing: $body" }
|
assertTrue(body.contains("audio/mpeg")) { "mime missing: $body" }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `next sends Next SOAP action`() = runTest {
|
|
||||||
server.enqueue(emptyResponse("Next"))
|
|
||||||
client.next()
|
|
||||||
val request = server.takeRequest()
|
|
||||||
assertTrue(request.getHeader("SOAPACTION").orEmpty().endsWith("#Next\"")) {
|
|
||||||
"SOAPACTION: ${request.getHeader("SOAPACTION")}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `previous sends Previous SOAP action`() = runTest {
|
|
||||||
server.enqueue(emptyResponse("Previous"))
|
|
||||||
client.previous()
|
|
||||||
val request = server.takeRequest()
|
|
||||||
assertTrue(request.getHeader("SOAPACTION").orEmpty().endsWith("#Previous\"")) {
|
|
||||||
"SOAPACTION: ${request.getHeader("SOAPACTION")}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `seekToTrack sends TRACK_NR unit with 1-based target`() = runTest {
|
fun `seekToTrack sends TRACK_NR unit with 1-based target`() = runTest {
|
||||||
server.enqueue(emptyResponse("Seek"))
|
server.enqueue(emptyResponse("Seek"))
|
||||||
|
|||||||
+18
-36
@@ -1,44 +1,26 @@
|
|||||||
package com.fabledsword.minstrel.player.output.upnp
|
package com.fabledsword.minstrel.player.output.upnp
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.params.ParameterizedTest
|
||||||
|
import org.junit.jupiter.params.provider.CsvSource
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Sonos names one speaker several ways: the renderer's route id carries
|
||||||
|
* `uuid:` and an `_MR` suffix, a media server `_MS`, and the zone-group
|
||||||
|
* topology neither. Bare, they compare equal.
|
||||||
|
*/
|
||||||
class BareUdnTest {
|
class BareUdnTest {
|
||||||
|
|
||||||
@Test
|
@ParameterizedTest(name = "{0}")
|
||||||
fun `strips uuid prefix`() {
|
@CsvSource(
|
||||||
assertEquals("RINCON_ABC", "uuid:RINCON_ABC".bareUdn())
|
"uuid:RINCON_ABC",
|
||||||
}
|
"RINCON_ABC_MR",
|
||||||
|
"RINCON_ABC_MS",
|
||||||
@Test
|
"uuid:RINCON_ABC_MR",
|
||||||
fun `strips MR suffix`() {
|
"uuid:RINCON_ABC_MS",
|
||||||
assertEquals("RINCON_ABC", "RINCON_ABC_MR".bareUdn())
|
"RINCON_ABC",
|
||||||
}
|
)
|
||||||
|
fun `every form of a speaker's id is the same bare id`(udn: String) {
|
||||||
@Test
|
assertEquals("RINCON_ABC", udn.bareUdn())
|
||||||
fun `strips MS suffix`() {
|
|
||||||
assertEquals("RINCON_ABC", "RINCON_ABC_MS".bareUdn())
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `strips both uuid prefix and MR suffix`() {
|
|
||||||
assertEquals("RINCON_ABC", "uuid:RINCON_ABC_MR".bareUdn())
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `strips both uuid prefix and MS suffix`() {
|
|
||||||
assertEquals("RINCON_ABC", "uuid:RINCON_ABC_MS".bareUdn())
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `leaves already bare UDN unchanged`() {
|
|
||||||
assertEquals("RINCON_ABC", "RINCON_ABC".bareUdn())
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `MR suffix comparison crosses MediaRenderer vs ZGT response`() {
|
|
||||||
val routeId = "uuid:RINCON_5CAAFD794B6401400_MR"
|
|
||||||
val zgtMemberUdn = "RINCON_5CAAFD794B6401400"
|
|
||||||
assertEquals(routeId.bareUdn(), zgtMemberUdn.bareUdn())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-19
@@ -7,6 +7,8 @@ import okhttp3.mockwebserver.MockWebServer
|
|||||||
import org.junit.jupiter.api.AfterEach
|
import org.junit.jupiter.api.AfterEach
|
||||||
import org.junit.jupiter.api.BeforeEach
|
import org.junit.jupiter.api.BeforeEach
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
import org.junit.jupiter.params.ParameterizedTest
|
||||||
|
import org.junit.jupiter.params.provider.CsvSource
|
||||||
import org.junit.jupiter.api.Assertions.assertEquals
|
import org.junit.jupiter.api.Assertions.assertEquals
|
||||||
import org.junit.jupiter.api.Assertions.assertTrue
|
import org.junit.jupiter.api.Assertions.assertTrue
|
||||||
|
|
||||||
@@ -46,8 +48,9 @@ class RenderingControlClientTest {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@ParameterizedTest(name = "{0} -> {1}")
|
||||||
fun `setVolume clamps and sends DesiredVolume`() = runTest {
|
@CsvSource("150, 100", "-5, 0", "40, 40")
|
||||||
|
fun `setVolume clamps to the renderer's range and sends DesiredVolume`(asked: Int, sent: Int) = runTest {
|
||||||
server.enqueue(MockResponse().setBody(
|
server.enqueue(MockResponse().setBody(
|
||||||
"""<?xml version="1.0"?>
|
"""<?xml version="1.0"?>
|
||||||
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
|
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
|
||||||
@@ -56,23 +59,8 @@ class RenderingControlClientTest {
|
|||||||
xmlns:u="urn:schemas-upnp-org:service:RenderingControl:1"/>
|
xmlns:u="urn:schemas-upnp-org:service:RenderingControl:1"/>
|
||||||
</s:Body>
|
</s:Body>
|
||||||
</s:Envelope>""".trimIndent()))
|
</s:Envelope>""".trimIndent()))
|
||||||
client.setVolume(150)
|
client.setVolume(asked)
|
||||||
val body = server.takeRequest().body.readUtf8()
|
val body = server.takeRequest().body.readUtf8()
|
||||||
assertTrue(body.contains("<DesiredVolume>100</DesiredVolume>")) { body }
|
assertTrue(body.contains("<DesiredVolume>$sent</DesiredVolume>")) { body }
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `setVolume clamps below VOLUME_MIN to zero`() = runTest {
|
|
||||||
server.enqueue(MockResponse().setBody(
|
|
||||||
"""<?xml version="1.0"?>
|
|
||||||
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
|
|
||||||
<s:Body>
|
|
||||||
<u:SetVolumeResponse
|
|
||||||
xmlns:u="urn:schemas-upnp-org:service:RenderingControl:1"/>
|
|
||||||
</s:Body>
|
|
||||||
</s:Envelope>""".trimIndent()))
|
|
||||||
client.setVolume(-5)
|
|
||||||
val body = server.takeRequest().body.readUtf8()
|
|
||||||
assertTrue(body.contains("<DesiredVolume>0</DesiredVolume>")) { body }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+15
-34
@@ -3,49 +3,30 @@ package com.fabledsword.minstrel.playlists.data
|
|||||||
import com.fabledsword.minstrel.cache.db.dao.PlaylistCachedCount
|
import com.fabledsword.minstrel.cache.db.dao.PlaylistCachedCount
|
||||||
import com.fabledsword.minstrel.cache.db.entities.CachedPlaylistEntity
|
import com.fabledsword.minstrel.cache.db.entities.CachedPlaylistEntity
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
import org.junit.jupiter.params.ParameterizedTest
|
||||||
|
import org.junit.jupiter.params.provider.CsvSource
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
import kotlin.test.assertFalse
|
|
||||||
import kotlin.test.assertTrue
|
|
||||||
|
|
||||||
class PlaylistsRepositoryCacheMergeTest {
|
class PlaylistsRepositoryCacheMergeTest {
|
||||||
|
|
||||||
private fun playlist(id: String, trackCount: Int) =
|
private fun playlist(id: String, trackCount: Int) =
|
||||||
CachedPlaylistEntity(id = id, userId = "u", name = id, trackCount = trackCount)
|
CachedPlaylistEntity(id = id, userId = "u", name = id, trackCount = trackCount)
|
||||||
|
|
||||||
@Test
|
// Fully cached means every member track is resident; an empty playlist
|
||||||
fun `fully cached when every member track is resident`() {
|
// never is, and no count row means nothing is resident.
|
||||||
|
@ParameterizedTest(name = "{0} of {1} resident -> {2}")
|
||||||
|
@CsvSource(
|
||||||
|
"3, 3, true",
|
||||||
|
"2, 3, false",
|
||||||
|
", 3, false",
|
||||||
|
"0, 0, false",
|
||||||
|
)
|
||||||
|
fun `fully cached only when every track is resident`(cached: Int?, tracks: Int, want: Boolean) {
|
||||||
val out = mergePlaylistsWithCache(
|
val out = mergePlaylistsWithCache(
|
||||||
rows = listOf(playlist("p", trackCount = 3)),
|
rows = listOf(playlist("p", trackCount = tracks)),
|
||||||
counts = listOf(PlaylistCachedCount("p", cachedCount = 3)),
|
counts = listOfNotNull(cached?.let { PlaylistCachedCount("p", cachedCount = it) }),
|
||||||
)
|
)
|
||||||
assertTrue(out.single().fullyCached)
|
assertEquals(want, out.single().fullyCached)
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `not fully cached when only some tracks are resident`() {
|
|
||||||
val out = mergePlaylistsWithCache(
|
|
||||||
rows = listOf(playlist("p", trackCount = 3)),
|
|
||||||
counts = listOf(PlaylistCachedCount("p", cachedCount = 2)),
|
|
||||||
)
|
|
||||||
assertFalse(out.single().fullyCached)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `not fully cached when no tracks are resident (missing count row)`() {
|
|
||||||
val out = mergePlaylistsWithCache(
|
|
||||||
rows = listOf(playlist("p", trackCount = 3)),
|
|
||||||
counts = emptyList(),
|
|
||||||
)
|
|
||||||
assertFalse(out.single().fullyCached)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `empty playlist is never fully cached`() {
|
|
||||||
val out = mergePlaylistsWithCache(
|
|
||||||
rows = listOf(playlist("p", trackCount = 0)),
|
|
||||||
counts = listOf(PlaylistCachedCount("p", cachedCount = 0)),
|
|
||||||
)
|
|
||||||
assertFalse(out.single().fullyCached)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
+23
-42
@@ -1,6 +1,8 @@
|
|||||||
package com.fabledsword.minstrel.shared.widgets
|
package com.fabledsword.minstrel.shared.widgets
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
import org.junit.jupiter.params.ParameterizedTest
|
||||||
|
import org.junit.jupiter.params.provider.CsvSource
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -11,48 +13,27 @@ import kotlin.test.assertEquals
|
|||||||
*/
|
*/
|
||||||
class ReorderDragMathTest {
|
class ReorderDragMathTest {
|
||||||
|
|
||||||
@Test
|
@ParameterizedTest(name = "{0}px on {1}px rows -> {2}")
|
||||||
fun `zero offset moves nothing`() {
|
@CsvSource(
|
||||||
assertEquals(0, reorderDragDelta(0f, 64))
|
"0, 64, 0",
|
||||||
}
|
"64, 64, 1",
|
||||||
|
"31, 64, 0",
|
||||||
@Test
|
"32, 64, 1",
|
||||||
fun `a full row down moves one`() {
|
"56, 56, 1",
|
||||||
assertEquals(1, reorderDragDelta(64f, 64))
|
"28, 56, 1",
|
||||||
}
|
"192, 64, 3",
|
||||||
|
"-64, 64, -1",
|
||||||
@Test
|
"-32, 64, 0", // ties toward positive infinity, as in JS
|
||||||
fun `just under half a row rounds down`() {
|
"-128, 64, -2",
|
||||||
assertEquals(0, reorderDragDelta(31f, 64))
|
"100, 0, 0", // a row not yet measured moves nothing
|
||||||
}
|
"100, -1, 0",
|
||||||
|
)
|
||||||
@Test
|
fun `a drag moves by the whole rows it crosses, half a row counting as one`(
|
||||||
fun `half a row or more rounds up`() {
|
offset: Float,
|
||||||
assertEquals(1, reorderDragDelta(32f, 64))
|
rowHeight: Int,
|
||||||
}
|
want: Int,
|
||||||
|
) {
|
||||||
@Test
|
assertEquals(want, reorderDragDelta(offset, rowHeight))
|
||||||
fun `drag up is symmetric, with ties toward positive infinity as in JS`() {
|
|
||||||
assertEquals(-1, reorderDragDelta(-64f, 64))
|
|
||||||
assertEquals(0, reorderDragDelta(-32f, 64))
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `several rows`() {
|
|
||||||
assertEquals(3, reorderDragDelta(192f, 64))
|
|
||||||
assertEquals(-2, reorderDragDelta(-128f, 64))
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `a row not yet measured moves nothing`() {
|
|
||||||
assertEquals(0, reorderDragDelta(100f, 0))
|
|
||||||
assertEquals(0, reorderDragDelta(100f, -1))
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `the measured row height is what counts`() {
|
|
||||||
assertEquals(1, reorderDragDelta(56f, 56))
|
|
||||||
assertEquals(1, reorderDragDelta(28f, 56))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -60,11 +60,6 @@ class UpdateRepositoryTest {
|
|||||||
assertIs<Offer.Newer>(repo().check())
|
assertIs<Offer.Newer>(repo().check())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `the same app built again at a later minute is not offered`() = runTest {
|
|
||||||
assertEquals(Offer.Current, repo(version = { wire(version = "2026.10.20.0900") }).check())
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `a server with no app to offer is not a problem`() = runTest {
|
fun `a server with no app to offer is not a problem`() = runTest {
|
||||||
val none = repo(version = { throw HttpException(Response.error<Any>(404, "".toResponseBody())) })
|
val none = repo(version = { throw HttpException(Response.error<Any>(404, "".toResponseBody())) })
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ describe('offsetToDelta', () => {
|
|||||||
[64, 64, 1],
|
[64, 64, 1],
|
||||||
[31, 64, 0],
|
[31, 64, 0],
|
||||||
[32, 64, 1],
|
[32, 64, 1],
|
||||||
|
[56, 56, 1],
|
||||||
[28, 56, 1],
|
[28, 56, 1],
|
||||||
[192, 64, 3],
|
[192, 64, 3],
|
||||||
[-64, 64, -1],
|
[-64, 64, -1],
|
||||||
|
|||||||
Reference in New Issue
Block a user