feat(gift): 선물함 표시 정책을 추가한다
This commit is contained in:
@@ -0,0 +1,35 @@
|
|||||||
|
package kr.co.vividnext.sodalive.v2.gift
|
||||||
|
|
||||||
|
import androidx.annotation.StringRes
|
||||||
|
import kr.co.vividnext.sodalive.common.ToastMessage
|
||||||
|
|
||||||
|
enum class GiftInboxViewMode { ALL, SENT, RECEIVED }
|
||||||
|
enum class GiftInboxDirection { SENT, RECEIVED }
|
||||||
|
enum class GiftInboxRowType { NOTICE, ADDRESS, SENT, RECEIVED, EMPTY_RECEIVED, INQUIRY, LOADING, RETRY }
|
||||||
|
|
||||||
|
data class GiftInboxCardUiModel(
|
||||||
|
val applicationNo: String,
|
||||||
|
val direction: GiftInboxDirection,
|
||||||
|
val status: ToastMessage,
|
||||||
|
@param:StringRes val subtitleRes: Int?,
|
||||||
|
val createdDate: String,
|
||||||
|
@param:StringRes val dateLabelRes: Int,
|
||||||
|
val sizeName: String,
|
||||||
|
val categoryName: String,
|
||||||
|
val addressRequired: Boolean,
|
||||||
|
val counterpartMemberId: Long,
|
||||||
|
val counterpartNickname: String,
|
||||||
|
val counterpartProfileImageUrl: String?
|
||||||
|
)
|
||||||
|
|
||||||
|
sealed class GiftInboxRow(val type: GiftInboxRowType) {
|
||||||
|
data class Notice(val received: Boolean) : GiftInboxRow(GiftInboxRowType.NOTICE)
|
||||||
|
data class Address(val card: GiftInboxCardUiModel) : GiftInboxRow(GiftInboxRowType.ADDRESS)
|
||||||
|
data class Card(val card: GiftInboxCardUiModel) : GiftInboxRow(
|
||||||
|
if (card.direction == GiftInboxDirection.SENT) GiftInboxRowType.SENT else GiftInboxRowType.RECEIVED
|
||||||
|
)
|
||||||
|
data object EmptyReceived : GiftInboxRow(GiftInboxRowType.EMPTY_RECEIVED)
|
||||||
|
data object Inquiry : GiftInboxRow(GiftInboxRowType.INQUIRY)
|
||||||
|
data object Loading : GiftInboxRow(GiftInboxRowType.LOADING)
|
||||||
|
data object Retry : GiftInboxRow(GiftInboxRowType.RETRY)
|
||||||
|
}
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
package kr.co.vividnext.sodalive.v2.gift
|
||||||
|
|
||||||
|
import kr.co.vividnext.sodalive.R
|
||||||
|
import kr.co.vividnext.sodalive.common.ToastMessage
|
||||||
|
import kr.co.vividnext.sodalive.v2.gift.data.GiftInboxItemResponse
|
||||||
|
|
||||||
|
object GiftInboxPresenter {
|
||||||
|
fun toCard(item: GiftInboxItemResponse): GiftInboxCardUiModel {
|
||||||
|
val received = item.direction == "RECEIVED"
|
||||||
|
val statusRes = if (received) {
|
||||||
|
when (item.status) {
|
||||||
|
"TRACKING_REGISTERED" -> R.string.gift_inbox_address_required
|
||||||
|
"ARRIVED_AT_MAILBOX" -> R.string.gift_inbox_inspecting
|
||||||
|
"INSPECTION_COMPLETED" -> R.string.gift_inbox_inspected
|
||||||
|
"DELIVERED" -> R.string.gift_inbox_delivered
|
||||||
|
"UNDELIVERABLE" -> R.string.gift_inbox_undeliverable
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
when (item.status) {
|
||||||
|
"RECEIVED" -> R.string.gift_inbox_tracking_required
|
||||||
|
"TRACKING_REGISTERED" -> R.string.gift_inbox_sent_confirmed
|
||||||
|
"ARRIVED_AT_MAILBOX" -> R.string.gift_inbox_arrived
|
||||||
|
"INSPECTION_COMPLETED" -> R.string.gift_inbox_inspected
|
||||||
|
"DELIVERED" -> R.string.gift_inbox_delivered
|
||||||
|
"UNDELIVERABLE" -> R.string.gift_inbox_undeliverable
|
||||||
|
"CANCELED" -> R.string.gift_inbox_canceled
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val subtitle = if (received) {
|
||||||
|
when (item.status) {
|
||||||
|
"TRACKING_REGISTERED" -> R.string.gift_inbox_expected
|
||||||
|
"ARRIVED_AT_MAILBOX" -> R.string.gift_inbox_checking
|
||||||
|
"INSPECTION_COMPLETED" -> R.string.gift_inbox_shipping
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
return GiftInboxCardUiModel(
|
||||||
|
applicationNo = item.applicationNo,
|
||||||
|
direction = if (received) GiftInboxDirection.RECEIVED else GiftInboxDirection.SENT,
|
||||||
|
status = if (statusRes != null) ToastMessage(resId = statusRes) else ToastMessage(message = item.statusName),
|
||||||
|
subtitleRes = subtitle,
|
||||||
|
createdDate = item.createdAt?.substringBefore('T')?.replace('-', '.').orEmpty(),
|
||||||
|
dateLabelRes = R.string.gift_inbox_applied_date,
|
||||||
|
sizeName = item.sizeName,
|
||||||
|
categoryName = item.categoryName,
|
||||||
|
addressRequired = received && item.status == "TRACKING_REGISTERED",
|
||||||
|
counterpartMemberId = item.counterpartMemberId,
|
||||||
|
counterpartNickname = item.counterpartNickname,
|
||||||
|
counterpartProfileImageUrl = item.counterpartProfileImageUrl?.takeIf { it.isNotBlank() }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun toUiModels(
|
||||||
|
items: List<GiftInboxItemResponse>,
|
||||||
|
viewMode: GiftInboxViewMode,
|
||||||
|
isCreator: Boolean,
|
||||||
|
isAppending: Boolean = false,
|
||||||
|
canRetry: Boolean = false
|
||||||
|
): List<GiftInboxRow> {
|
||||||
|
val cards = items.filter { viewMode == GiftInboxViewMode.ALL || it.direction == viewMode.name }.map(::toCard)
|
||||||
|
val rows = if (cards.isEmpty()) {
|
||||||
|
val received = viewMode == GiftInboxViewMode.RECEIVED || (viewMode == GiftInboxViewMode.ALL && isCreator)
|
||||||
|
listOf(if (received) GiftInboxRow.EmptyReceived else GiftInboxRow.Notice(false))
|
||||||
|
} else {
|
||||||
|
buildList {
|
||||||
|
if (cards.any { it.direction == GiftInboxDirection.SENT }) add(GiftInboxRow.Notice(false))
|
||||||
|
val hasReceived = cards.any { it.direction == GiftInboxDirection.RECEIVED }
|
||||||
|
if (hasReceived) add(GiftInboxRow.Notice(true))
|
||||||
|
cards.firstOrNull { it.addressRequired }?.let { add(GiftInboxRow.Address(it)) }
|
||||||
|
addAll(cards.map(GiftInboxRow::Card))
|
||||||
|
if (hasReceived) add(GiftInboxRow.Inquiry)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return rows + when {
|
||||||
|
isAppending -> listOf(GiftInboxRow.Loading)
|
||||||
|
canRetry -> listOf(GiftInboxRow.Retry)
|
||||||
|
else -> emptyList()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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