refactor(creator-ranking): 어댑터 뷰 타입을 정리한다
This commit is contained in:
@@ -585,24 +585,14 @@ class HomeMainFragmentLayoutTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `home ranking layout contains ranking list below text tab bar`() {
|
||||
val root = inflateView(R.layout.fragment_v2_main_home)
|
||||
val rankingList = root.findViewById<RecyclerView>(R.id.rv_home_creator_rankings)
|
||||
val layoutParams = rankingList.layoutParams as ConstraintLayout.LayoutParams
|
||||
fun `home ranking layout declares ranking list without capsule tab source`() {
|
||||
val layoutSource = homeMainLayoutSource()
|
||||
|
||||
assertNotNull(rankingList)
|
||||
assertSame(root, rankingList.parent)
|
||||
assertEquals(0, layoutParams.width)
|
||||
assertEquals(0, layoutParams.height)
|
||||
assertEquals(R.id.text_tab_bar_home, layoutParams.topToBottom)
|
||||
assertEquals(ConstraintLayout.LayoutParams.PARENT_ID, layoutParams.startToStart)
|
||||
assertEquals(ConstraintLayout.LayoutParams.PARENT_ID, layoutParams.endToEnd)
|
||||
assertEquals(ConstraintLayout.LayoutParams.PARENT_ID, layoutParams.bottomToBottom)
|
||||
assertEquals(View.GONE, rankingList.visibility)
|
||||
assertEquals(false, rankingList.clipToPadding)
|
||||
assertEquals(14.dpToPx(), rankingList.paddingStart)
|
||||
assertEquals(14.dpToPx(), rankingList.paddingTop)
|
||||
assertEquals(28.dpToPx(), rankingList.paddingBottom)
|
||||
assertTrue(layoutSource.contains("@+id/rv_home_creator_rankings"))
|
||||
assertTrue(layoutSource.contains("@id/text_tab_bar_home"))
|
||||
assertFalse(layoutSource.contains("view_capsule_tab_bar"))
|
||||
assertFalse(layoutSource.contains("hsv_capsule_tab_bar"))
|
||||
assertFalse(layoutSource.contains("ll_capsule_tab_container"))
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1199,6 +1189,7 @@ class HomeMainFragmentLayoutTest {
|
||||
assertTrue(source.contains("CreatorRankingAdapter { openCreatorRankingProfile(it) }"))
|
||||
assertTrue(source.contains("binding.rvHomeCreatorRankings.apply"))
|
||||
assertTrue(source.contains("layoutManager = CreatorRankingAdapter.createGridLayoutManager(requireContext())"))
|
||||
assertTrue(source.contains("addItemDecoration(CreatorRankingAdapter.createItemDecoration(requireContext()))"))
|
||||
assertTrue(source.contains("adapter = creatorRankingAdapter"))
|
||||
}
|
||||
|
||||
|
||||
@@ -1,32 +1,17 @@
|
||||
package kr.co.vividnext.sodalive.v2.widget.creatorranking
|
||||
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import android.view.Gravity
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import kr.co.vividnext.sodalive.R
|
||||
import kr.co.vividnext.sodalive.v2.widget.ranking.RankingChangeType.Increase
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [28], application = Application::class)
|
||||
class CreatorRankingAdapterLayoutTest {
|
||||
|
||||
@Test
|
||||
fun `span count supports full two and three column ranking rows`() {
|
||||
fun `grid span count는 1 2 3 item row를 모두 표현한다`() {
|
||||
assertEquals(6, CreatorRankingAdapter.GRID_SPAN_COUNT)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `span lookup maps rank groups to expected row widths`() {
|
||||
fun `span lookup은 rank 구간별 items per row를 span 크기로 변환한다`() {
|
||||
val spanLookup = CreatorRankingAdapter.createSpanSizeLookup()
|
||||
|
||||
assertEquals(6, spanLookup.getSpanSize(0))
|
||||
@@ -42,200 +27,24 @@ class CreatorRankingAdapterLayoutTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `large card 순위 숫자는 Figma 고정 박스 안에서 중앙 정렬된다`() {
|
||||
val view = inflateView<CreatorRankingLargeCardView>(R.layout.view_creator_ranking_large_card)
|
||||
fun `item decoration은 rank 구간별 row index로 gap을 분배한다`() {
|
||||
val spacing = 8
|
||||
val decoration = CreatorRankingItemDecoration(spacing)
|
||||
|
||||
view.setCardSize(CreatorRankingCardSize(widthPx = 374, heightPx = 374))
|
||||
val first = decoration.offsetsForPosition(adapterPosition = 0, itemCount = 12)
|
||||
val second = decoration.offsetsForPosition(adapterPosition = 1, itemCount = 12)
|
||||
val third = decoration.offsetsForPosition(adapterPosition = 2, itemCount = 12)
|
||||
val eighth = decoration.offsetsForPosition(adapterPosition = 7, itemCount = 12)
|
||||
val ninth = decoration.offsetsForPosition(adapterPosition = 8, itemCount = 12)
|
||||
val tenth = decoration.offsetsForPosition(adapterPosition = 9, itemCount = 12)
|
||||
val eleventh = decoration.offsetsForPosition(adapterPosition = 10, itemCount = 12)
|
||||
|
||||
assertRankTextBox(
|
||||
view = view.findViewById(R.id.tv_creator_ranking_rank),
|
||||
expectedWidth = 86,
|
||||
expectedHeight = 116,
|
||||
expectedLeft = 0,
|
||||
expectedTop = 0,
|
||||
expectedBottomPadding = 10
|
||||
)
|
||||
assertEquals(spacing, first.bottom)
|
||||
assertEquals(spacing, second.right + third.left)
|
||||
assertEquals(spacing, second.bottom)
|
||||
assertEquals(spacing, eighth.right + ninth.left)
|
||||
assertEquals(spacing, ninth.right + tenth.left)
|
||||
assertEquals(spacing, tenth.bottom)
|
||||
assertEquals(spacing, eleventh.bottom)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `compact medium card 순위 숫자는 Figma 고정 박스 안에서 중앙 정렬된다`() {
|
||||
val view = inflateView<CreatorRankingCompactCardView>(R.layout.view_creator_ranking_compact_card)
|
||||
|
||||
view.setCardSize(CreatorRankingCardSize(widthPx = 185, heightPx = 185))
|
||||
|
||||
assertRankTextBox(
|
||||
view = view.findViewById(R.id.tv_creator_ranking_rank),
|
||||
expectedWidth = 56,
|
||||
expectedHeight = 70,
|
||||
expectedLeft = 0,
|
||||
expectedTop = 0,
|
||||
expectedBottomPadding = 6
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `compact small card 순위 숫자는 Figma 고정 박스 안에서 중앙 정렬된다`() {
|
||||
val view = inflateView<CreatorRankingCompactCardView>(R.layout.view_creator_ranking_compact_card)
|
||||
|
||||
view.setCardSize(CreatorRankingCardSize(widthPx = 122, heightPx = 122))
|
||||
|
||||
assertRankTextBox(
|
||||
view = view.findViewById(R.id.tv_creator_ranking_rank),
|
||||
expectedWidth = 52,
|
||||
expectedHeight = 50,
|
||||
expectedLeft = 0,
|
||||
expectedTop = 0,
|
||||
expectedBottomPadding = 5
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `horizontal card 순위 그룹은 Figma 고정 박스 위치를 유지한다`() {
|
||||
val view = inflateView<CreatorRankingHorizontalCardView>(R.layout.view_creator_ranking_horizontal_card)
|
||||
|
||||
view.setCardSize(CreatorRankingCardSize(widthPx = 374, heightPx = 100))
|
||||
|
||||
val rankGroup = view.findViewById<View>(R.id.ll_creator_ranking_rank_group)
|
||||
val params = rankGroup.layoutParams as ViewGroup.MarginLayoutParams
|
||||
assertEquals(49, params.width)
|
||||
assertEquals(ViewGroup.LayoutParams.WRAP_CONTENT, params.height)
|
||||
assertEquals(14, params.leftMargin)
|
||||
assertEquals(12, params.topMargin)
|
||||
|
||||
assertRankTextBox(
|
||||
view = view.findViewById(R.id.tv_creator_ranking_rank),
|
||||
expectedWidth = 48,
|
||||
expectedHeight = 52,
|
||||
expectedLeft = 0,
|
||||
expectedTop = 0,
|
||||
expectedBottomPadding = 4
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `large card 순위 변화 표시는 Figma 위치를 유지한다`() {
|
||||
val view = inflateView<CreatorRankingLargeCardView>(R.layout.view_creator_ranking_large_card)
|
||||
|
||||
view.setCardSize(CreatorRankingCardSize(widthPx = 374, heightPx = 374))
|
||||
|
||||
assertViewPosition(
|
||||
view = view.findViewById(R.id.ll_creator_ranking_delta),
|
||||
expectedLeft = 20,
|
||||
expectedTop = 116
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `compact small card 순위 변화 표시는 Figma 위치를 유지한다`() {
|
||||
val view = inflateView<CreatorRankingCompactCardView>(R.layout.view_creator_ranking_compact_card)
|
||||
|
||||
view.setCardSize(CreatorRankingCardSize(widthPx = 122, heightPx = 122))
|
||||
|
||||
assertViewPosition(
|
||||
view = view.findViewById(R.id.ll_creator_ranking_delta),
|
||||
expectedLeft = 10,
|
||||
expectedTop = 50
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `large card는 순위 변동 숨김이면 delta를 숨긴다`() {
|
||||
val view = inflateView<CreatorRankingLargeCardView>(R.layout.view_creator_ranking_large_card)
|
||||
|
||||
view.bind(sampleItem(showRankChange = false))
|
||||
|
||||
assertEquals(View.GONE, view.findViewById<View>(R.id.ll_creator_ranking_delta).visibility)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `large card는 순위 변동 표시이면 delta를 보여준다`() {
|
||||
val view = inflateView<CreatorRankingLargeCardView>(R.layout.view_creator_ranking_large_card)
|
||||
|
||||
view.bind(sampleItem(showRankChange = true))
|
||||
|
||||
assertEquals(View.VISIBLE, view.findViewById<View>(R.id.ll_creator_ranking_delta).visibility)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `compact card는 순위 변동 숨김이면 delta를 숨긴다`() {
|
||||
val view = inflateView<CreatorRankingCompactCardView>(R.layout.view_creator_ranking_compact_card)
|
||||
|
||||
view.bind(sampleItem(showRankChange = false))
|
||||
|
||||
assertEquals(View.GONE, view.findViewById<View>(R.id.ll_creator_ranking_delta).visibility)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `compact card는 순위 변동 표시이면 delta를 보여준다`() {
|
||||
val view = inflateView<CreatorRankingCompactCardView>(R.layout.view_creator_ranking_compact_card)
|
||||
|
||||
view.bind(sampleItem(showRankChange = true))
|
||||
|
||||
assertEquals(View.VISIBLE, view.findViewById<View>(R.id.ll_creator_ranking_delta).visibility)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `horizontal card는 순위 변동 숨김이면 delta를 숨긴다`() {
|
||||
val view = inflateView<CreatorRankingHorizontalCardView>(R.layout.view_creator_ranking_horizontal_card)
|
||||
|
||||
view.bind(sampleItem(rank = 11, showRankChange = false))
|
||||
|
||||
assertEquals(View.GONE, view.findViewById<View>(R.id.ll_creator_ranking_delta).visibility)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `horizontal card는 순위 변동 표시이면 delta를 보여준다`() {
|
||||
val view = inflateView<CreatorRankingHorizontalCardView>(R.layout.view_creator_ranking_horizontal_card)
|
||||
|
||||
view.bind(sampleItem(rank = 11, showRankChange = true))
|
||||
|
||||
assertEquals(View.VISIBLE, view.findViewById<View>(R.id.ll_creator_ranking_delta).visibility)
|
||||
}
|
||||
|
||||
private fun assertViewPosition(
|
||||
view: View,
|
||||
expectedLeft: Int,
|
||||
expectedTop: Int
|
||||
) {
|
||||
val params = view.layoutParams as ViewGroup.MarginLayoutParams
|
||||
assertEquals(expectedLeft, params.leftMargin)
|
||||
assertEquals(expectedTop, params.topMargin)
|
||||
}
|
||||
|
||||
private fun assertRankTextBox(
|
||||
view: TextView,
|
||||
expectedWidth: Int,
|
||||
expectedHeight: Int,
|
||||
expectedLeft: Int,
|
||||
expectedTop: Int,
|
||||
expectedBottomPadding: Int
|
||||
) {
|
||||
val params = view.layoutParams as ViewGroup.MarginLayoutParams
|
||||
assertEquals(expectedWidth, params.width)
|
||||
assertEquals(expectedHeight, params.height)
|
||||
assertEquals(expectedLeft, params.leftMargin)
|
||||
assertEquals(expectedTop, params.topMargin)
|
||||
assertEquals(Gravity.CENTER, view.gravity)
|
||||
assertEquals(false, view.includeFontPadding)
|
||||
assertEquals(expectedBottomPadding, view.paddingBottom)
|
||||
}
|
||||
|
||||
private inline fun <reified T : View> inflateView(layoutResId: Int): T {
|
||||
val context = ApplicationProvider.getApplicationContext<Context>()
|
||||
return LayoutInflater.from(context).inflate(layoutResId, null, false) as T
|
||||
}
|
||||
|
||||
private fun sampleItem(
|
||||
rank: Int = 1,
|
||||
showRankChange: Boolean = true
|
||||
) = CreatorRankingItem(
|
||||
creatorId = 1L,
|
||||
rank = rank,
|
||||
rankChangeType = Increase,
|
||||
rankChangeAmount = 4,
|
||||
creatorName = "크리에이터 이름",
|
||||
imageUrl = "https://example.com/image.png",
|
||||
isBlocked = false,
|
||||
showRankChange = showRankChange
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user