Skip to content

Commit

Permalink
[IDLE-490] 읽지 않은 메세지 개수 100개 이상일경우 99+로 표시되도록 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
tgyuuAn committed Oct 31, 2024
1 parent dbf2be0 commit 93f2e89
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class GetChatRoomListUseCase @Inject constructor(
createdAt = LocalDateTime.now().minusDays(1),
lastMessage = "안녕하세요!안녕하세요!안녕하세요!안녕하세요!안녕하세요!안녕하세요!",
lastSentAt = LocalDateTime.now().minusHours(1),
unReadMessageCount = 3,
unReadMessageCount = 99,
profileImageUrl = "",
),
ChatRoom(
Expand All @@ -25,7 +25,7 @@ class GetChatRoomListUseCase @Inject constructor(
createdAt = LocalDateTime.now().minusDays(3),
lastMessage = "오늘 만날 수 있을까요?",
lastSentAt = LocalDateTime.now().minusHours(5),
unReadMessageCount = 99,
unReadMessageCount = 100,
profileImageUrl = "",
),
ChatRoom(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,12 @@ fun formatBusinessRegistrationNumber(businessRegistrationNumber: String): String

else -> throw IllegalArgumentException("사업자 등록번호 형식이 맞지 않습니다.")
}
}

fun Int.formatUnReadNumber(): String {
return when {
this < 0 -> "0"
this >= 100 -> "99+"
else -> this.toString()
}
}
36 changes: 36 additions & 0 deletions core/domain/src/test/kotlin/com/idle/domain/util/NumberUtilTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,40 @@ class NumberUtilTest {
formatBusinessRegistrationNumber(businessRegistrationNumber)
}
}

@Test
fun `음수일 경우 0으로 반환된다`() {
// Given
val number = -5

// When
val result = number.formatUnReadNumber()

// Then
assertEquals("0", result)
}

@Test
fun `99 이하의 숫자는 그대로 문자열로 반환된다`() {
// Given
val number = 99

// When
val result = number.formatUnReadNumber()

// Then
assertEquals("99", result)
}

@Test
fun `100 이상의 숫자는 '99+'로 반환된다`() {
// Given
val number = 100

// When
val result = number.formatUnReadNumber()

// Then
assertEquals("99+", result)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import com.idle.designsystem.compose.foundation.CareTheme
import com.idle.domain.model.auth.UserType
import com.idle.domain.model.chatting.ChatRoom
import com.idle.domain.util.formatRelativeDateTime
import com.idle.domain.util.formatUnReadNumber
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
Expand Down Expand Up @@ -234,7 +235,7 @@ internal fun ChatRoomItem(
) {
Text(
text = if (chatRoom.unReadMessageCount != 0)
chatRoom.unReadMessageCount.toString() else "",
chatRoom.unReadMessageCount.formatUnReadNumber() else "",
style = CareTheme.typography.caption1.copy(fontWeight = FontWeight.Bold),
color = CareTheme.colors.white000,
textAlign = TextAlign.Center,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import com.idle.designsystem.compose.foundation.CareTheme
import com.idle.domain.model.auth.UserType
import com.idle.domain.model.chatting.ChatRoom
import com.idle.domain.util.formatRelativeDateTime
import com.idle.domain.util.formatUnReadNumber
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
Expand Down Expand Up @@ -239,7 +240,7 @@ internal fun ChatRoomItem(
) {
Text(
text = if (chatRoom.unReadMessageCount != 0)
chatRoom.unReadMessageCount.toString() else "",
chatRoom.unReadMessageCount.formatUnReadNumber() else "",
style = CareTheme.typography.caption1.copy(fontWeight = FontWeight.Bold),
color = CareTheme.colors.white000,
textAlign = TextAlign.Center,
Expand Down

0 comments on commit 93f2e89

Please sign in to comment.