feat(widget): 커뮤니티 이미지와 유료 overlay를 추가한다
This commit is contained in:
@@ -11,12 +11,14 @@ import androidx.test.core.app.ApplicationProvider
|
||||
import kr.co.vividnext.sodalive.R
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertNotNull
|
||||
import org.junit.Assert.assertSame
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [28], application = Application::class)
|
||||
@@ -53,6 +55,80 @@ class FeedViewTest {
|
||||
assertEquals(View.GONE, view.findViewById<TextView>(R.id.tv_feed_community_keyword).visibility)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `community keeps keyword visible by default for existing feed usage`() {
|
||||
val view = inflateView<FeedCommunityView>(R.layout.view_feed_community)
|
||||
|
||||
view.bind(sampleCommunityItem(bodyText = "본문", keywordText = "#키워드"))
|
||||
|
||||
assertEquals(View.VISIBLE, view.findViewById<TextView>(R.id.tv_feed_community_keyword).visibility)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `community recommendation image is hidden when image url is null`() {
|
||||
val view = inflateView<FeedCommunityView>(R.layout.view_feed_community)
|
||||
|
||||
view.bind(sampleCommunityItem(bodyText = "본문", keywordText = "#키워드", imageUrl = null))
|
||||
|
||||
assertEquals(View.GONE, view.findViewById<FrameLayout>(R.id.fl_feed_community_image_container).visibility)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `community paid image shows lock overlay and price capsule only when not purchased`() {
|
||||
val view = inflateView<FeedCommunityView>(R.layout.view_feed_community)
|
||||
|
||||
view.bind(
|
||||
sampleCommunityItem(
|
||||
bodyText = "본문",
|
||||
keywordText = "",
|
||||
imageUrl = "https://example.com/post.png",
|
||||
price = 30,
|
||||
existOrdered = false,
|
||||
showKeyword = false
|
||||
)
|
||||
)
|
||||
|
||||
assertEquals(View.GONE, view.findViewById<TextView>(R.id.tv_feed_community_keyword).visibility)
|
||||
assertEquals(View.VISIBLE, view.findViewById<FrameLayout>(R.id.fl_feed_community_image_container).visibility)
|
||||
assertEquals(View.VISIBLE, view.findViewById<View>(R.id.ll_feed_community_paid_overlay).visibility)
|
||||
assertEquals("30", view.findViewById<TextView>(R.id.tv_feed_community_price).text.toString())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `community purchased paid image hides lock overlay and price capsule`() {
|
||||
val view = inflateView<FeedCommunityView>(R.layout.view_feed_community)
|
||||
|
||||
view.bind(
|
||||
sampleCommunityItem(
|
||||
bodyText = "본문",
|
||||
keywordText = "",
|
||||
imageUrl = "https://example.com/post.png",
|
||||
price = 30,
|
||||
existOrdered = true,
|
||||
showKeyword = false
|
||||
)
|
||||
)
|
||||
|
||||
assertEquals(View.VISIBLE, view.findViewById<FrameLayout>(R.id.fl_feed_community_image_container).visibility)
|
||||
assertEquals(View.GONE, view.findViewById<View>(R.id.ll_feed_community_paid_overlay).visibility)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `community image container follows measured card width ratio`() {
|
||||
val view = inflateView<FeedCommunityView>(R.layout.view_feed_community)
|
||||
val imageContainer = view.findViewById<FrameLayout>(R.id.fl_feed_community_image_container)
|
||||
|
||||
view.bind(sampleCommunityItem(bodyText = "본문", keywordText = "", imageUrl = "https://example.com/post.png"))
|
||||
|
||||
view.measure(exactly(402.dpToPx()), View.MeasureSpec.UNSPECIFIED)
|
||||
|
||||
val expectedImageWidth = 402.dpToPx() - view.paddingLeft - view.paddingRight
|
||||
assertEquals(expectedImageWidth, imageContainer.measuredWidth)
|
||||
assertEquals((expectedImageWidth * 236 / 346f).roundToInt(), imageContainer.measuredHeight)
|
||||
assertEquals(true, imageContainer.clipToOutline)
|
||||
assertNotNull(imageContainer.outlineProvider)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `rank overlay uses figma overflow position`() {
|
||||
val view = inflateView<FeedRankView>(R.layout.view_feed_rank)
|
||||
@@ -98,7 +174,12 @@ class FeedViewTest {
|
||||
|
||||
private fun sampleCommunityItem(
|
||||
bodyText: String,
|
||||
keywordText: String
|
||||
keywordText: String,
|
||||
imageUrl: String? = null,
|
||||
audioUrl: String? = null,
|
||||
price: Int = 0,
|
||||
existOrdered: Boolean = false,
|
||||
showKeyword: Boolean = true
|
||||
) = FeedItem.Community(
|
||||
feedId = "feed-community-1",
|
||||
creatorId = "creator-1",
|
||||
@@ -109,7 +190,12 @@ class FeedViewTest {
|
||||
keywordText = keywordText,
|
||||
createdAtText = "2분 전",
|
||||
commentCount = 5,
|
||||
likeCount = 6
|
||||
likeCount = 6,
|
||||
imageUrl = imageUrl,
|
||||
audioUrl = audioUrl,
|
||||
price = price,
|
||||
existOrdered = existOrdered,
|
||||
showKeyword = showKeyword
|
||||
)
|
||||
|
||||
private fun Int.dpToPx(): Int {
|
||||
@@ -117,6 +203,8 @@ class FeedViewTest {
|
||||
return (this * context.resources.displayMetrics.density).toInt()
|
||||
}
|
||||
|
||||
private fun exactly(size: Int): Int = View.MeasureSpec.makeMeasureSpec(size, View.MeasureSpec.EXACTLY)
|
||||
|
||||
private fun assertNotEmptyContentDescription(imageView: ImageView) {
|
||||
assertTrue(!imageView.contentDescription.isNullOrEmpty())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user