test(chat-room): 타이핑 인디케이터 표시/중복/숨김 테스트 추가

- showTypingIndicator 중복 호출 시 중복 삽입 방지 검증
- hideTypingIndicator 안전성 검증(표시되지 않은 경우도 안전)
- NPE 회귀 방지

fix(adapter): RecyclerView 미부착 상태에서 notify 호출로 NPE 발생 방지
This commit is contained in:
2025-08-14 19:19:38 +09:00
parent c1012586ce
commit 02747c539b
2 changed files with 43 additions and 2 deletions

View File

@@ -5,6 +5,34 @@ import org.junit.Test
class ChatMessageAdapterTest {
@Test
fun `typing indicator shows only once and hides correctly`() {
val adapter = ChatMessageAdapter()
// 초기 아이템 1개 추가
val base = listOf(
ChatListItem.AiMessage(ChatMessage(1, "hi", "", mine = false, createdAt = 1L))
)
adapter.setItemsForTest(base)
val initialCount = adapter.itemCount
// 1) 표시: 하나 추가되고 마지막 아이템이 TypingIndicator 여야 함
adapter.showTypingIndicator()
assertEquals(initialCount + 1, adapter.itemCount)
assertEquals(ChatMessageAdapter.VIEW_TYPE_TYPING_INDICATOR, adapter.getItemViewType(adapter.itemCount - 1))
// 2) 중복 표시 시 개수 변화 없음
adapter.showTypingIndicator()
assertEquals(initialCount + 1, adapter.itemCount)
// 3) 숨김: 다시 원래 개수로 돌아감
adapter.hideTypingIndicator()
assertEquals(initialCount, adapter.itemCount)
// 4) 숨길 것이 없을 때 호출해도 안전 (변화 없음)
adapter.hideTypingIndicator()
assertEquals(initialCount, adapter.itemCount)
}
@Test
fun `getItemViewType returns correct types`() {
val adapter = ChatMessageAdapter()