mirror of
https://github.com/austinried/subtracks.git
synced 2026-11-11 07:29:14 +01:00
artwork: cover the non-square and thumbnail reload paths
The fix keyed the request remembers in all three CoverArt branches; assert each of them survives a re-salted URL for the same cacheKey, not just the square grid path.
This commit is contained in:
@@ -5,6 +5,7 @@ import android.graphics.Bitmap
|
|||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import androidx.activity.ComponentActivity
|
import androidx.activity.ComponentActivity
|
||||||
import androidx.compose.foundation.layout.size
|
import androidx.compose.foundation.layout.size
|
||||||
|
import androidx.compose.runtime.MutableState
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.test.junit4.v2.createAndroidComposeRule
|
import androidx.compose.ui.test.junit4.v2.createAndroidComposeRule
|
||||||
@@ -61,18 +62,45 @@ class CoverArtReloadTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun aNewSaltedUrlForTheSameArtworkDoesNotRestartTheLoad() {
|
fun aNewSaltedUrlForTheSameArtworkDoesNotRestartTheSquareLoad() {
|
||||||
val refState = mutableStateOf(CoverArtRef(url = "http://host/art?id=1&s=one", cacheKey = "1:art:true"))
|
assertANewSaltedUrlDoesNotReload(square = true, thumbnail = false)
|
||||||
composeRule.setContent {
|
}
|
||||||
CoverArt(ref = refState.value, name = "Kid A", modifier = Modifier.size(64.dp))
|
|
||||||
}
|
|
||||||
composeRule.waitUntil(timeoutMillis = 5_000) { requests.get() == 1 }
|
|
||||||
|
|
||||||
refState.value = CoverArtRef(url = "http://host/art?id=1&s=two", cacheKey = "1:art:true")
|
@Test
|
||||||
|
fun aNewSaltedUrlForTheSameArtworkDoesNotRestartTheNonSquareLoad() {
|
||||||
|
assertANewSaltedUrlDoesNotReload(square = false, thumbnail = false)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun aNewSaltedUrlForTheSameArtworkDoesNotRestartTheThumbnailLoad() {
|
||||||
|
assertANewSaltedUrlDoesNotReload(square = true, thumbnail = true)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun assertANewSaltedUrlDoesNotReload(
|
||||||
|
square: Boolean,
|
||||||
|
thumbnail: Boolean,
|
||||||
|
) {
|
||||||
|
val refState = mutableStateOf(CoverArtRef(url = "http://host/art?id=1&s=one", cacheKey = "1:art:false"))
|
||||||
|
val thumbnailState: MutableState<CoverArtRef>? =
|
||||||
|
if (thumbnail) mutableStateOf(CoverArtRef(url = "http://host/art?id=1&t=one", cacheKey = "1:art:true")) else null
|
||||||
|
val expected = if (thumbnail) 2 else 1
|
||||||
|
composeRule.setContent {
|
||||||
|
CoverArt(
|
||||||
|
ref = refState.value,
|
||||||
|
name = "Kid A",
|
||||||
|
thumbnailRef = thumbnailState?.value,
|
||||||
|
square = square,
|
||||||
|
modifier = Modifier.size(64.dp),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
composeRule.waitUntil(timeoutMillis = 5_000) { requests.get() == expected }
|
||||||
|
|
||||||
|
refState.value = CoverArtRef(url = "http://host/art?id=1&s=two", cacheKey = "1:art:false")
|
||||||
|
thumbnailState?.value = CoverArtRef(url = "http://host/art?id=1&t=two", cacheKey = "1:art:true")
|
||||||
composeRule.waitForIdle()
|
composeRule.waitForIdle()
|
||||||
composeRule.mainClock.advanceTimeBy(500)
|
composeRule.mainClock.advanceTimeBy(500)
|
||||||
composeRule.waitForIdle()
|
composeRule.waitForIdle()
|
||||||
|
|
||||||
assertEquals(1, requests.get())
|
assertEquals("a fresh salt for the same artwork must not rebuild the image request", expected, requests.get())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user