Skip to content

Commit e88cd55

Browse files
committed
Fix Reader feed image display for VIDEO card types
- VIDEO cards now show featured images when available - Updated buildFeaturedImageVisibility() to support VIDEO cards with images - Updated buildFeaturedImageUrl() for consistent behavior across card types - Added comprehensive unit tests for VIDEO card image display - Fixes issue where VIDEO posts with thumbnails didn't show images Fixes #21332
1 parent fb78326 commit e88cd55

File tree

2 files changed

+39
-24
lines changed

2 files changed

+39
-24
lines changed

WordPress/src/main/java/org/wordpress/android/ui/reader/discover/ReaderPostUiStateBuilder.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,17 +282,21 @@ class ReaderPostUiStateBuilder @Inject constructor(
282282
// TODO malinjir show overlay when buildFullVideoUrl != null
283283
private fun buildVideoOverlayVisibility(post: ReaderPost) = post.cardType == VIDEO
284284

285-
private fun buildFeaturedImageVisibility(post: ReaderPost) =
286-
(post.cardType == PHOTO || post.cardType == DEFAULT) && post.hasFeaturedImage() ||
287-
post.cardType == VIDEO && post.hasFeaturedVideo()
285+
private fun buildFeaturedImageVisibility(post: ReaderPost): Boolean {
286+
return when (post.cardType) {
287+
GALLERY -> false
288+
VIDEO -> post.hasFeaturedVideo() || post.hasFeaturedImage()
289+
else -> post.hasFeaturedImage()
290+
}
291+
}
288292

289293
private fun buildThumbnailStripUrls(post: ReaderPost) =
290294
post.takeIf { it.cardType == GALLERY }
291295
?.let { retrieveGalleryThumbnailUrls(post) }
292296

293297
private fun buildFeaturedImageUrl(post: ReaderPost, photonWidth: Int, photonHeight: Int): String? {
294298
return post
295-
.takeIf { (it.cardType == PHOTO || it.cardType == DEFAULT) && it.hasFeaturedImage() }
299+
.takeIf { it.cardType != GALLERY && it.hasFeaturedImage() }
296300
?.getFeaturedImageForDisplay(photonWidth, photonHeight)
297301
}
298302

WordPress/src/test/java/org/wordpress/android/ui/reader/discover/ReaderPostUiStateBuilderTest.kt

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -312,10 +312,10 @@ class ReaderPostUiStateBuilderTest : BaseUnitTest() {
312312

313313
// region FEATURED IMAGE
314314
@Test
315-
fun `featured image is displayed for photo and default card types`() = test {
315+
fun `featured image is displayed for supported card types`() = test {
316316
// Arrange
317317
val dummyUrl = "12345"
318-
ReaderCardType.values().filter { it == PHOTO || it == DEFAULT }.forEach {
318+
ReaderCardType.values().filter { it != GALLERY }.forEach {
319319
val post = createPost(cardType = it, hasFeaturedImage = true, featuredImageUrlForDisplay = dummyUrl)
320320
// Act
321321
val uiState = mapPostToUiState(post)
@@ -325,10 +325,10 @@ class ReaderPostUiStateBuilderTest : BaseUnitTest() {
325325
}
326326

327327
@Test
328-
fun `featured image is displayed for photo and default card types for new UI`() = test {
328+
fun `featured image is displayed for supported card types for new UI`() = test {
329329
// Arrange
330330
val dummyUrl = "12345"
331-
ReaderCardType.values().filter { it == PHOTO || it == DEFAULT }.forEach {
331+
ReaderCardType.values().filter { it != GALLERY }.forEach {
332332
val post = createPost(cardType = it, hasFeaturedImage = true, featuredImageUrlForDisplay = dummyUrl)
333333
// Act
334334
val uiState = mapPostToUiState(post)
@@ -338,27 +338,23 @@ class ReaderPostUiStateBuilderTest : BaseUnitTest() {
338338
}
339339

340340
@Test
341-
fun `featured image is not displayed for other than photo and default card types`() = test {
341+
fun `featured image is not displayed for gallery card type`() = test {
342342
// Arrange
343-
ReaderCardType.values().filter { it != PHOTO && it != DEFAULT }.forEach {
344-
val post = createPost(cardType = it, hasFeaturedImage = true)
345-
// Act
346-
val uiState = mapPostToUiState(post)
347-
// Assert
348-
assertThat(uiState.featuredImageUrl).isNull()
349-
}
343+
val post = createPost(cardType = GALLERY, hasFeaturedImage = true)
344+
// Act
345+
val uiState = mapPostToUiState(post)
346+
// Assert
347+
assertThat(uiState.featuredImageUrl).isNull()
350348
}
351349

352350
@Test
353-
fun `featured image is not displayed for other than photo and default card types for new UI`() = test {
351+
fun `featured image is not displayed for gallery card type for new UI`() = test {
354352
// Arrange
355-
ReaderCardType.values().filter { it != PHOTO && it != DEFAULT }.forEach {
356-
val post = createPost(cardType = it, hasFeaturedImage = true)
357-
// Act
358-
val uiState = mapPostToUiState(post)
359-
// Assert
360-
assertThat(uiState.featuredImageUrl).isNull()
361-
}
353+
val post = createPost(cardType = GALLERY, hasFeaturedImage = true)
354+
// Act
355+
val uiState = mapPostToUiState(post)
356+
// Assert
357+
assertThat(uiState.featuredImageUrl).isNull()
362358
}
363359

364360
@Test
@@ -380,6 +376,21 @@ class ReaderPostUiStateBuilderTest : BaseUnitTest() {
380376
// Assert
381377
assertThat(uiState.featuredImageUrl).isNull()
382378
}
379+
380+
@Test
381+
fun `video card shows featured media area when only video is available`() = test {
382+
// Arrange
383+
val post = createPost(
384+
cardType = VIDEO,
385+
hasFeaturedVideo = true,
386+
featuredVideoUrl = "video://example",
387+
hasFeaturedImage = false
388+
)
389+
// Act
390+
val uiState = mapPostToUiState(post)
391+
// Assert
392+
assertThat(uiState.featuredImageVisibility).isTrue
393+
}
383394
// endregion
384395

385396
// region TITLE & EXCERPT

0 commit comments

Comments
 (0)