Skip to content

Commit 28a5640

Browse files
committed
Cover unnamed-fallback branches of attachment remove descriptions
Add three Paparazzi snapshot tests rendering each composer attachment item (image, video, file) with a copy of the existing preview data that clears the title and name, exercising the previously uncovered fallback arms of fileAttachmentRemoveDescription and mediaAttachmentRemoveDescription. Extract a shared MessageComposerAttachmentItem helper to dedupe the preview-handler wiring across the four media-item previews.
1 parent 31c1d17 commit 28a5640

7 files changed

Lines changed: 78 additions & 10 deletions

stream-chat-android-compose/api/stream-chat-android-compose.api

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2060,16 +2060,17 @@ public final class io/getstream/chat/android/compose/ui/messages/composer/intern
20602060
public final class io/getstream/chat/android/compose/ui/messages/composer/internal/attachments/ComposableSingletons$MessageComposerAttachmentFileItemKt {
20612061
public static final field INSTANCE Lio/getstream/chat/android/compose/ui/messages/composer/internal/attachments/ComposableSingletons$MessageComposerAttachmentFileItemKt;
20622062
public fun <init> ()V
2063+
public final fun getLambda$-1126442206$stream_chat_android_compose_release ()Lkotlin/jvm/functions/Function2;
20632064
public final fun getLambda$1955682816$stream_chat_android_compose_release ()Lkotlin/jvm/functions/Function2;
20642065
}
20652066

20662067
public final class io/getstream/chat/android/compose/ui/messages/composer/internal/attachments/ComposableSingletons$MessageComposerAttachmentMediaItemKt {
20672068
public static final field INSTANCE Lio/getstream/chat/android/compose/ui/messages/composer/internal/attachments/ComposableSingletons$MessageComposerAttachmentMediaItemKt;
20682069
public fun <init> ()V
20692070
public final fun getLambda$-932284221$stream_chat_android_compose_release ()Lkotlin/jvm/functions/Function2;
2070-
public final fun getLambda$116152749$stream_chat_android_compose_release ()Lkotlin/jvm/functions/Function2;
2071-
public final fun getLambda$1523175629$stream_chat_android_compose_release ()Lkotlin/jvm/functions/Function2;
2071+
public final fun getLambda$369677867$stream_chat_android_compose_release ()Lkotlin/jvm/functions/Function2;
20722072
public final fun getLambda$384447459$stream_chat_android_compose_release ()Lkotlin/jvm/functions/Function2;
2073+
public final fun getLambda$485971275$stream_chat_android_compose_release ()Lkotlin/jvm/functions/Function2;
20732074
}
20742075

20752076
public final class io/getstream/chat/android/compose/ui/messages/composer/internal/attachments/ComposableSingletons$MessageComposerAttachmentsKt {

stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/messages/composer/internal/attachments/MessageComposerAttachmentFileItem.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,18 @@ internal fun MessageComposerAttachmentFileItem() {
139139
attachment = PreviewAttachmentData.attachmentFile1,
140140
)
141141
}
142+
143+
@Preview
144+
@Composable
145+
private fun MessageComposerAttachmentFileItemUnnamedPreview() {
146+
ChatTheme {
147+
MessageComposerAttachmentFileItemUnnamed()
148+
}
149+
}
150+
151+
@Composable
152+
internal fun MessageComposerAttachmentFileItemUnnamed() {
153+
MessageComposerAttachmentFileItem(
154+
attachment = PreviewAttachmentData.attachmentFile1.copy(name = null),
155+
)
156+
}

stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/messages/composer/internal/attachments/MessageComposerAttachmentMediaItem.kt

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,13 @@ private fun mediaAttachmentRemoveDescription(attachment: Attachment): String {
100100
return when {
101101
isVideo && !displayName.isNullOrBlank() ->
102102
stringResource(R.string.stream_compose_remove_attachment_video_named, displayName)
103+
103104
isVideo ->
104105
stringResource(R.string.stream_compose_remove_attachment_video)
106+
105107
!displayName.isNullOrBlank() ->
106108
stringResource(R.string.stream_compose_remove_attachment_photo_named, displayName)
109+
107110
else ->
108111
stringResource(R.string.stream_compose_remove_attachment_photo)
109112
}
@@ -121,16 +124,24 @@ private fun MessageComposerAttachmentImageItemPreview() {
121124

122125
@Composable
123126
internal fun MessageComposerAttachmentImageItem() {
124-
val previewHandler = AsyncImagePreviewHandler {
125-
ColorImage(color = Color.Green.toArgb(), width = 200, height = 150)
126-
}
127-
CompositionLocalProvider(LocalAsyncImagePreviewHandler provides previewHandler) {
128-
MessageComposerAttachmentMediaItem(
129-
attachment = PreviewAttachmentData.attachmentImage1,
130-
)
127+
MessageComposerAttachmentItem(attachment = PreviewAttachmentData.attachmentImage1)
128+
}
129+
130+
@Preview
131+
@Composable
132+
private fun MessageComposerAttachmentImageItemUnnamedPreview() {
133+
ChatTheme {
134+
MessageComposerAttachmentImageItemUnnamed()
131135
}
132136
}
133137

138+
@Composable
139+
internal fun MessageComposerAttachmentImageItemUnnamed() {
140+
MessageComposerAttachmentItem(
141+
attachment = PreviewAttachmentData.attachmentImage1.copy(name = null),
142+
)
143+
}
144+
134145
@Preview
135146
@Composable
136147
private fun MessageComposerAttachmentVideoItemPreview() {
@@ -141,12 +152,32 @@ private fun MessageComposerAttachmentVideoItemPreview() {
141152

142153
@Composable
143154
internal fun MessageComposerAttachmentVideoItem() {
155+
MessageComposerAttachmentItem(attachment = PreviewAttachmentData.attachmentVideo1)
156+
}
157+
158+
@Preview
159+
@Composable
160+
private fun MessageComposerAttachmentVideoItemUnnamedPreview() {
161+
ChatTheme {
162+
MessageComposerAttachmentVideoItemUnnamed()
163+
}
164+
}
165+
166+
@Composable
167+
internal fun MessageComposerAttachmentVideoItemUnnamed() {
168+
MessageComposerAttachmentItem(
169+
attachment = PreviewAttachmentData.attachmentVideo1.copy(name = null),
170+
)
171+
}
172+
173+
@Composable
174+
private fun MessageComposerAttachmentItem(attachment: Attachment) {
144175
val previewHandler = AsyncImagePreviewHandler {
145176
ColorImage(color = Color.Green.toArgb(), width = 200, height = 150)
146177
}
147178
CompositionLocalProvider(LocalAsyncImagePreviewHandler provides previewHandler) {
148179
MessageComposerAttachmentMediaItem(
149-
attachment = PreviewAttachmentData.attachmentVideo1,
180+
attachment = attachment,
150181
)
151182
}
152183
}

stream-chat-android-compose/src/test/kotlin/io/getstream/chat/android/compose/ui/messages/composer/internal/attachments/MessageComposerAttachmentsTest.kt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,25 @@ internal class MessageComposerAttachmentsTest : PaparazziComposeTest {
6666
MessageComposerAttachmentFileItem()
6767
}
6868
}
69+
70+
@Test
71+
fun `image attachment item without title or name`() {
72+
snapshotWithDarkModeRow {
73+
MessageComposerAttachmentImageItemUnnamed()
74+
}
75+
}
76+
77+
@Test
78+
fun `video attachment item without title or name`() {
79+
snapshotWithDarkModeRow {
80+
MessageComposerAttachmentVideoItemUnnamed()
81+
}
82+
}
83+
84+
@Test
85+
fun `file attachment item without title or name`() {
86+
snapshotWithDarkModeRow {
87+
MessageComposerAttachmentFileItemUnnamed()
88+
}
89+
}
6990
}

0 commit comments

Comments
 (0)