refactor(chat): 채팅방 시간 표시 책임을 분리한다
This commit is contained in:
@@ -1,9 +1,8 @@
|
|||||||
package kr.co.vividnext.sodalive.v2.main.chat.model
|
package kr.co.vividnext.sodalive.v2.main.chat.model
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import kr.co.vividnext.sodalive.v2.main.chat.data.ChatRoomListItemResponse
|
import kr.co.vividnext.sodalive.v2.main.chat.data.ChatRoomListItemResponse
|
||||||
|
|
||||||
fun ChatRoomListItemResponse.toUiItem(context: Context): ChatRoomListUiItem? {
|
fun ChatRoomListItemResponse.toUiItem(): ChatRoomListUiItem? {
|
||||||
val type = when (chatType) {
|
val type = when (chatType) {
|
||||||
ChatRoomType.AI.name -> ChatRoomType.AI
|
ChatRoomType.AI.name -> ChatRoomType.AI
|
||||||
ChatRoomType.DM.name -> ChatRoomType.DM
|
ChatRoomType.DM.name -> ChatRoomType.DM
|
||||||
@@ -16,9 +15,9 @@ fun ChatRoomListItemResponse.toUiItem(context: Context): ChatRoomListUiItem? {
|
|||||||
targetName = targetName,
|
targetName = targetName,
|
||||||
targetImageUrl = targetImageUrl,
|
targetImageUrl = targetImageUrl,
|
||||||
lastMessage = lastMessage,
|
lastMessage = lastMessage,
|
||||||
lastMessageTimeText = formatChatRoomLastMessageTime(context, lastMessageAt),
|
lastMessageAt = lastMessageAt,
|
||||||
showDirectBadge = type == ChatRoomType.DM
|
showDirectBadge = type == ChatRoomType.DM
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun List<ChatRoomListItemResponse>.toUiItems(context: Context): List<ChatRoomListUiItem> = mapNotNull { it.toUiItem(context) }
|
fun List<ChatRoomListItemResponse>.toUiItems(): List<ChatRoomListUiItem> = mapNotNull { it.toUiItem() }
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ data class ChatRoomListUiItem(
|
|||||||
val targetName: String,
|
val targetName: String,
|
||||||
val targetImageUrl: String,
|
val targetImageUrl: String,
|
||||||
val lastMessage: String,
|
val lastMessage: String,
|
||||||
val lastMessageTimeText: String,
|
val lastMessageAt: String,
|
||||||
val showDirectBadge: Boolean
|
val showDirectBadge: Boolean
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,8 @@
|
|||||||
package kr.co.vividnext.sodalive.v2.main.chat
|
package kr.co.vividnext.sodalive.v2.main.chat
|
||||||
|
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
import android.content.Context
|
|
||||||
import androidx.test.core.app.ApplicationProvider
|
|
||||||
import kr.co.vividnext.sodalive.v2.main.chat.data.ChatRoomListItemResponse
|
import kr.co.vividnext.sodalive.v2.main.chat.data.ChatRoomListItemResponse
|
||||||
import kr.co.vividnext.sodalive.v2.main.chat.model.ChatRoomType
|
import kr.co.vividnext.sodalive.v2.main.chat.model.ChatRoomType
|
||||||
import kr.co.vividnext.sodalive.v2.main.chat.model.formatChatRoomLastMessageTime
|
|
||||||
import kr.co.vividnext.sodalive.v2.main.chat.model.toUiItem
|
import kr.co.vividnext.sodalive.v2.main.chat.model.toUiItem
|
||||||
import kr.co.vividnext.sodalive.v2.main.chat.model.toUiItems
|
import kr.co.vividnext.sodalive.v2.main.chat.model.toUiItems
|
||||||
import org.junit.Assert.assertEquals
|
import org.junit.Assert.assertEquals
|
||||||
@@ -21,11 +18,9 @@ import org.robolectric.annotation.Config
|
|||||||
@Config(sdk = [28], application = Application::class)
|
@Config(sdk = [28], application = Application::class)
|
||||||
class ChatRoomMapperTest {
|
class ChatRoomMapperTest {
|
||||||
|
|
||||||
private val context: Context = ApplicationProvider.getApplicationContext()
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `AI 채팅방은 Direct badge 미표시 item으로 매핑된다`() {
|
fun `AI 채팅방은 Direct badge 미표시 item으로 매핑된다`() {
|
||||||
val item = response(chatType = "AI").toUiItem(context)
|
val item = response(chatType = "AI").toUiItem()
|
||||||
|
|
||||||
requireNotNull(item)
|
requireNotNull(item)
|
||||||
assertEquals(ChatRoomType.AI, item.chatType)
|
assertEquals(ChatRoomType.AI, item.chatType)
|
||||||
@@ -34,7 +29,7 @@ class ChatRoomMapperTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `DM 채팅방은 Direct badge 표시 item으로 매핑된다`() {
|
fun `DM 채팅방은 Direct badge 표시 item으로 매핑된다`() {
|
||||||
val item = response(chatType = "DM").toUiItem(context)
|
val item = response(chatType = "DM").toUiItem()
|
||||||
|
|
||||||
requireNotNull(item)
|
requireNotNull(item)
|
||||||
assertEquals(ChatRoomType.DM, item.chatType)
|
assertEquals(ChatRoomType.DM, item.chatType)
|
||||||
@@ -42,27 +37,27 @@ class ChatRoomMapperTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `응답 필드는 그대로 전달하고 시간은 표시 문구로 매핑한다`() {
|
fun `응답 필드는 그대로 전달하고 시간은 원본 문자열로 매핑한다`() {
|
||||||
val item = response(
|
val item = response(
|
||||||
roomId = 20L,
|
roomId = 20L,
|
||||||
targetName = "상대방",
|
targetName = "상대방",
|
||||||
targetImageUrl = "https://example.com/profile.png",
|
targetImageUrl = "https://example.com/profile.png",
|
||||||
lastMessage = "마지막 메시지",
|
lastMessage = "마지막 메시지",
|
||||||
lastMessageAt = "2026-06-09T11:57:00Z"
|
lastMessageAt = "2026-06-09T11:57:00Z"
|
||||||
).toUiItem(context)
|
).toUiItem()
|
||||||
|
|
||||||
requireNotNull(item)
|
requireNotNull(item)
|
||||||
assertEquals(20L, item.roomId)
|
assertEquals(20L, item.roomId)
|
||||||
assertEquals("상대방", item.targetName)
|
assertEquals("상대방", item.targetName)
|
||||||
assertEquals("https://example.com/profile.png", item.targetImageUrl)
|
assertEquals("https://example.com/profile.png", item.targetImageUrl)
|
||||||
assertEquals("마지막 메시지", item.lastMessage)
|
assertEquals("마지막 메시지", item.lastMessage)
|
||||||
assertEquals(formatChatRoomLastMessageTime(context, "2026-06-09T11:57:00Z"), item.lastMessageTimeText)
|
assertEquals("2026-06-09T11:57:00Z", item.lastMessageAt)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `알 수 없는 chatType은 표시 대상에서 제외한다`() {
|
fun `알 수 없는 chatType은 표시 대상에서 제외한다`() {
|
||||||
assertNull(response(chatType = "GROUP").toUiItem(context))
|
assertNull(response(chatType = "GROUP").toUiItem())
|
||||||
assertEquals(emptyList<Any>(), listOf(response(chatType = "GROUP")).toUiItems(context))
|
assertEquals(emptyList<Any>(), listOf(response(chatType = "GROUP")).toUiItems())
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun response(
|
private fun response(
|
||||||
|
|||||||
Reference in New Issue
Block a user