Skip to content

Commit

Permalink
MBL-1202: Crash on CommentsViewHolderViewModel (#1948)
Browse files Browse the repository at this point in the history
* - Fix crash for empty path sent to `loadCircleImage`
  • Loading branch information
Arkariang committed Feb 13, 2024
1 parent 735c1f7 commit 3b7938e
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 6 deletions.
15 changes: 12 additions & 3 deletions app/src/main/java/com/kickstarter/ui/extensions/ImageViewExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,18 @@ import com.squareup.picasso.Picasso

fun ImageView.loadCircleImage(url: String?) {
url?.let {
Picasso.get().load(it)
.transform(CircleTransformation())
.into(this)
if (it.isBlank()) { // - load with drawable
Picasso.get()
.load(R.drawable.circle_grey_500)
.transform(CircleTransformation())
.into(this)
} else { // - load with url string
Picasso.get()
.load(it)
.placeholder(R.drawable.circle_grey_500)
.transform(CircleTransformation())
.into(this)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,14 @@ interface CommentsViewHolderViewModel {
.subscribe { this.commentAuthorName.onNext(it) }
.addToDisposable(disposables)

comment
.filter { it.author()?.avatar()?.medium().isNotNull() }
.map { it.author()?.avatar()?.medium() ?: "" }
comment // TODO: extract all logic around selecting image to an Avatar extension function, and refactor entire app
.filter { it.author().avatar().medium().isNotNull() }
.map { aComment ->
return@map aComment.author().avatar().medium().ifBlank {
return@ifBlank if (aComment.author().avatar().small().isNullOrBlank()) ""
else aComment.author().avatar().small()
}
}
.subscribe { this.commentAuthorAvatarUrl.onNext(it) }
.addToDisposable(disposables)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,39 @@ class CommentsViewHolderViewModelTest : KSRobolectricTestCase() {
this.commentCardStatus.assertValue(CommentCardStatus.COMMENT_FOR_LOGIN_BACKED_USERS)
}

@Test
fun testUserAvatarUrl_whenMediumIsEmpty_TrySmall() {
setUpEnvironment(environment())
val userAvatar = AvatarFactory.avatar().toBuilder()
.medium("")
.build()
val currentUser = UserFactory.user().toBuilder().id(111).avatar(
userAvatar
).build()
val commentCardData = CommentFactory.liveCommentCardData(createdAt = createdAt, currentUser = currentUser)
this.vm.inputs.configureWith(commentCardData)

this.commentAuthorAvatarUrl.assertValue(userAvatar.small())
this.commentCardStatus.assertValue(CommentCardStatus.COMMENT_FOR_LOGIN_BACKED_USERS)
}

@Test
fun testUserAvatarUrl_whenMediumAndSmallEmpty_Empty() {
setUpEnvironment(environment())
val userAvatar = AvatarFactory.avatar().toBuilder()
.medium("")
.small("")
.build()
val currentUser = UserFactory.user().toBuilder().id(111).avatar(
userAvatar
).build()
val commentCardData = CommentFactory.liveCommentCardData(createdAt = createdAt, currentUser = currentUser)
this.vm.inputs.configureWith(commentCardData)

this.commentAuthorAvatarUrl.assertValue("")
this.commentCardStatus.assertValue(CommentCardStatus.COMMENT_FOR_LOGIN_BACKED_USERS)
}

@Test
fun testCommentAuthorName() {
setUpEnvironment(environment())
Expand Down

0 comments on commit 3b7938e

Please sign in to comment.