feat(gift): 선물함 표시 정책을 추가한다
This commit is contained in:
@@ -0,0 +1,182 @@
|
||||
package kr.co.vividnext.sodalive.v2.gift
|
||||
|
||||
import kr.co.vividnext.sodalive.R
|
||||
import kr.co.vividnext.sodalive.v2.gift.data.GiftInboxItemResponse
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
class GiftInboxPresenterTest {
|
||||
@Test
|
||||
fun `보낸 선물 상태 일곱 개를 표시 문구에 매핑한다`() {
|
||||
val expected = mapOf(
|
||||
"RECEIVED" to R.string.gift_inbox_tracking_required,
|
||||
"TRACKING_REGISTERED" to R.string.gift_inbox_sent_confirmed,
|
||||
"ARRIVED_AT_MAILBOX" to R.string.gift_inbox_arrived,
|
||||
"INSPECTION_COMPLETED" to R.string.gift_inbox_inspected,
|
||||
"DELIVERED" to R.string.gift_inbox_delivered,
|
||||
"UNDELIVERABLE" to R.string.gift_inbox_undeliverable,
|
||||
"CANCELED" to R.string.gift_inbox_canceled
|
||||
)
|
||||
expected.forEach { (status, label) ->
|
||||
val card = GiftInboxPresenter.toCard(inboxItem(status = status))
|
||||
assertEquals(GiftInboxDirection.SENT, card.direction)
|
||||
assertEquals(label, card.status.resId)
|
||||
assertEquals("2026.09.18", card.createdDate)
|
||||
assertEquals(R.string.gift_inbox_applied_date, card.dateLabelRes)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `받은 선물 상태와 보조 문구를 매핑한다`() {
|
||||
val expected = listOf(
|
||||
Triple("TRACKING_REGISTERED", R.string.gift_inbox_address_required, R.string.gift_inbox_expected),
|
||||
Triple("ARRIVED_AT_MAILBOX", R.string.gift_inbox_inspecting, R.string.gift_inbox_checking),
|
||||
Triple("INSPECTION_COMPLETED", R.string.gift_inbox_inspected, R.string.gift_inbox_shipping),
|
||||
Triple("DELIVERED", R.string.gift_inbox_delivered, null),
|
||||
Triple("UNDELIVERABLE", R.string.gift_inbox_undeliverable, null)
|
||||
)
|
||||
expected.forEach { (status, main, sub) ->
|
||||
val card = GiftInboxPresenter.toCard(inboxItem(direction = "RECEIVED", status = status))
|
||||
assertEquals(GiftInboxDirection.RECEIVED, card.direction)
|
||||
assertEquals(main, card.status.resId)
|
||||
assertEquals(sub, card.subtitleRes)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `알 수 없는 상태는 서버 표시명을 그대로 사용한다`() {
|
||||
val card = GiftInboxPresenter.toCard(inboxItem(status = "NEW_STATUS"))
|
||||
assertEquals("서버 상태", card.status.message)
|
||||
assertFalse(card.addressRequired)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `신청일이 없으면 날짜 표시값을 비운다`() {
|
||||
val card = GiftInboxPresenter.toCard(inboxItem(createdAt = null))
|
||||
|
||||
assertEquals("", card.createdDate)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `보내고 받은 선물은 상대방 프로필 정보를 카드에 매핑한다`() {
|
||||
val sent = GiftInboxPresenter.toCard(
|
||||
inboxItem(
|
||||
direction = "SENT",
|
||||
counterpartMemberId = 101L,
|
||||
counterpartNickname = "받는 크리에이터",
|
||||
counterpartProfileImageUrl = "https://example.com/creator.png"
|
||||
)
|
||||
)
|
||||
val received = GiftInboxPresenter.toCard(
|
||||
inboxItem(
|
||||
direction = "RECEIVED",
|
||||
counterpartMemberId = 202L,
|
||||
counterpartNickname = "보내는 팬",
|
||||
counterpartProfileImageUrl = "https://example.com/fan.png"
|
||||
)
|
||||
)
|
||||
|
||||
assertEquals(101L, sent.counterpartMemberId)
|
||||
assertEquals("받는 크리에이터", sent.counterpartNickname)
|
||||
assertEquals("https://example.com/creator.png", sent.counterpartProfileImageUrl)
|
||||
assertEquals(202L, received.counterpartMemberId)
|
||||
assertEquals("보내는 팬", received.counterpartNickname)
|
||||
assertEquals("https://example.com/fan.png", received.counterpartProfileImageUrl)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `보내고 받은 선물의 빈 상대방 프로필 이미지는 null로 정규화한다`() {
|
||||
listOf("SENT", "RECEIVED").forEach { direction ->
|
||||
listOf(null, "", " ").forEach { imageUrl ->
|
||||
val card = GiftInboxPresenter.toCard(
|
||||
inboxItem(direction = direction, counterpartProfileImageUrl = imageUrl)
|
||||
)
|
||||
|
||||
assertNull(card.counterpartProfileImageUrl)
|
||||
}
|
||||
assertEquals(
|
||||
"https://example.com/profile.png",
|
||||
GiftInboxPresenter.toCard(
|
||||
inboxItem(
|
||||
direction = direction,
|
||||
counterpartProfileImageUrl = "https://example.com/profile.png"
|
||||
)
|
||||
).counterpartProfileImageUrl
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `혼합 목록은 배너 뒤 서버 카드 순서와 문의를 유지하고 섹션 제목을 만들지 않는다`() {
|
||||
val items = listOf(inboxItem("z"), inboxItem("a", "RECEIVED", "TRACKING_REGISTERED"))
|
||||
val rows = GiftInboxPresenter.toUiModels(items, GiftInboxViewMode.ALL, false)
|
||||
assertEquals(
|
||||
listOf("NOTICE", "NOTICE", "ADDRESS", "SENT", "RECEIVED", "INQUIRY"),
|
||||
rows.map { it.type.name }
|
||||
)
|
||||
assertEquals(listOf("z", "a"), rows.filterIsInstance<GiftInboxRow.Card>().map { it.card.applicationNo })
|
||||
assertEquals("a", rows.filterIsInstance<GiftInboxRow.Address>().single().card.applicationNo)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `ALL 빈 목록은 크리에이터와 일반 회원 유형에 따라 분기한다`() {
|
||||
assertEquals(listOf(GiftInboxRowType.EMPTY_RECEIVED), rows(GiftInboxViewMode.ALL, true))
|
||||
assertEquals(listOf(GiftInboxRowType.NOTICE), rows(GiftInboxViewMode.ALL, false))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `명시적인 빈 목록 관점은 회원 역할보다 우선한다`() {
|
||||
assertEquals(listOf(GiftInboxRowType.NOTICE), rows(GiftInboxViewMode.SENT, true))
|
||||
assertEquals(listOf(GiftInboxRowType.EMPTY_RECEIVED), rows(GiftInboxViewMode.RECEIVED, false))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `배송지 배너는 첫 배송지 입력 필요 선물만 가리킨다`() {
|
||||
val rows = GiftInboxPresenter.toUiModels(
|
||||
listOf(inboxItem("one", "RECEIVED", "TRACKING_REGISTERED"), inboxItem("two", "RECEIVED", "TRACKING_REGISTERED")),
|
||||
GiftInboxViewMode.ALL,
|
||||
true
|
||||
)
|
||||
val banner = rows.filterIsInstance<GiftInboxRow.Address>().single()
|
||||
assertEquals("one", banner.card.applicationNo)
|
||||
assertEquals(R.string.gift_inbox_address_required, banner.card.status.resId)
|
||||
assertTrue(banner.card.addressRequired)
|
||||
}
|
||||
|
||||
private fun rows(mode: GiftInboxViewMode, creator: Boolean) =
|
||||
GiftInboxPresenter.toUiModels(emptyList(), mode, creator).map { it.type }
|
||||
|
||||
@Test
|
||||
fun `콘텐츠 로딩과 오류는 스크롤 목록의 마지막 행으로 표시된다`() {
|
||||
val items = listOf(inboxItem())
|
||||
val loading = GiftInboxPresenter.toUiModels(items, GiftInboxViewMode.ALL, false, isAppending = true)
|
||||
val error = GiftInboxPresenter.toUiModels(items, GiftInboxViewMode.ALL, false, canRetry = true)
|
||||
assertEquals(GiftInboxRowType.LOADING, loading.last().type)
|
||||
assertEquals(GiftInboxRowType.RETRY, error.last().type)
|
||||
}
|
||||
}
|
||||
|
||||
internal fun inboxItem(
|
||||
id: String = "test-gift",
|
||||
direction: String = "SENT",
|
||||
status: String = "RECEIVED",
|
||||
createdAt: String? = "2026-09-18T03:00:00Z",
|
||||
counterpartMemberId: Long = 1L,
|
||||
counterpartNickname: String = "상대방",
|
||||
counterpartProfileImageUrl: String? = null
|
||||
) = GiftInboxItemResponse(
|
||||
id,
|
||||
direction,
|
||||
status,
|
||||
"서버 상태",
|
||||
80,
|
||||
"카테고리",
|
||||
"소형",
|
||||
createdAt,
|
||||
counterpartMemberId,
|
||||
counterpartNickname,
|
||||
counterpartProfileImageUrl
|
||||
)
|
||||
Reference in New Issue
Block a user