mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-04 01:19:33 +00:00
Add missing test on EventItemFactory
This commit is contained in:
+318
@@ -20,12 +20,15 @@ import io.element.android.libraries.matrix.api.media.MediaSource
|
|||||||
import io.element.android.libraries.matrix.api.media.VideoInfo
|
import io.element.android.libraries.matrix.api.media.VideoInfo
|
||||||
import io.element.android.libraries.matrix.api.notification.CallIntent
|
import io.element.android.libraries.matrix.api.notification.CallIntent
|
||||||
import io.element.android.libraries.matrix.api.timeline.MatrixTimelineItem
|
import io.element.android.libraries.matrix.api.timeline.MatrixTimelineItem
|
||||||
|
import io.element.android.libraries.matrix.api.core.UniqueId
|
||||||
import io.element.android.libraries.matrix.api.timeline.item.event.AudioMessageType
|
import io.element.android.libraries.matrix.api.timeline.item.event.AudioMessageType
|
||||||
import io.element.android.libraries.matrix.api.timeline.item.event.CallNotifyContent
|
import io.element.android.libraries.matrix.api.timeline.item.event.CallNotifyContent
|
||||||
import io.element.android.libraries.matrix.api.timeline.item.event.EmoteMessageType
|
import io.element.android.libraries.matrix.api.timeline.item.event.EmoteMessageType
|
||||||
import io.element.android.libraries.matrix.api.timeline.item.event.FailedToParseMessageLikeContent
|
import io.element.android.libraries.matrix.api.timeline.item.event.FailedToParseMessageLikeContent
|
||||||
import io.element.android.libraries.matrix.api.timeline.item.event.FailedToParseStateContent
|
import io.element.android.libraries.matrix.api.timeline.item.event.FailedToParseStateContent
|
||||||
import io.element.android.libraries.matrix.api.timeline.item.event.FileMessageType
|
import io.element.android.libraries.matrix.api.timeline.item.event.FileMessageType
|
||||||
|
import io.element.android.libraries.matrix.api.timeline.item.event.GalleryItemType
|
||||||
|
import io.element.android.libraries.matrix.api.timeline.item.event.GalleryMessageType
|
||||||
import io.element.android.libraries.matrix.api.timeline.item.event.ImageMessageType
|
import io.element.android.libraries.matrix.api.timeline.item.event.ImageMessageType
|
||||||
import io.element.android.libraries.matrix.api.timeline.item.event.LegacyCallInviteContent
|
import io.element.android.libraries.matrix.api.timeline.item.event.LegacyCallInviteContent
|
||||||
import io.element.android.libraries.matrix.api.timeline.item.event.LocationMessageType
|
import io.element.android.libraries.matrix.api.timeline.item.event.LocationMessageType
|
||||||
@@ -377,6 +380,321 @@ class DefaultEventItemFactoryTest {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `create for GalleryMessageType with image item`() {
|
||||||
|
val factory = createEventItemFactory()
|
||||||
|
val result = factory.create(
|
||||||
|
MatrixTimelineItem.Event(
|
||||||
|
uniqueId = A_UNIQUE_ID,
|
||||||
|
event = anEventTimelineItem(
|
||||||
|
content = aMessageContent(
|
||||||
|
messageType = GalleryMessageType(
|
||||||
|
body = "Gallery body",
|
||||||
|
formatted = null,
|
||||||
|
items = listOf(
|
||||||
|
GalleryItemType.Image(
|
||||||
|
content = ImageMessageType(
|
||||||
|
filename = "image.jpg",
|
||||||
|
caption = "caption",
|
||||||
|
formattedCaption = null,
|
||||||
|
source = MediaSource("image_url"),
|
||||||
|
info = ImageInfo(
|
||||||
|
mimetype = MimeTypes.Jpeg,
|
||||||
|
size = 123L,
|
||||||
|
thumbnailInfo = null,
|
||||||
|
thumbnailSource = MediaSource("thumbnail_url"),
|
||||||
|
height = 1L,
|
||||||
|
width = 2L,
|
||||||
|
blurhash = null,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
assertThat(result).containsExactly(
|
||||||
|
MediaItem.Image(
|
||||||
|
id = UniqueId("aUniqueId_0"),
|
||||||
|
eventId = AN_EVENT_ID,
|
||||||
|
mediaInfo = MediaInfo(
|
||||||
|
mimeType = MimeTypes.Jpeg,
|
||||||
|
filename = "image.jpg",
|
||||||
|
fileSize = 123L,
|
||||||
|
caption = "caption",
|
||||||
|
formattedFileSize = "123 Bytes",
|
||||||
|
fileExtension = "jpg",
|
||||||
|
senderId = A_USER_ID,
|
||||||
|
senderName = "alice",
|
||||||
|
senderAvatar = null,
|
||||||
|
dateSent = "0 Day false",
|
||||||
|
dateSentFull = "0 Full false",
|
||||||
|
waveform = null,
|
||||||
|
duration = null,
|
||||||
|
),
|
||||||
|
mediaSource = MediaSource("image_url"),
|
||||||
|
thumbnailSource = MediaSource("thumbnail_url"),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `create for GalleryMessageType with video item`() {
|
||||||
|
val factory = createEventItemFactory()
|
||||||
|
val result = factory.create(
|
||||||
|
MatrixTimelineItem.Event(
|
||||||
|
uniqueId = A_UNIQUE_ID,
|
||||||
|
event = anEventTimelineItem(
|
||||||
|
content = aMessageContent(
|
||||||
|
messageType = GalleryMessageType(
|
||||||
|
body = "Gallery body",
|
||||||
|
formatted = null,
|
||||||
|
items = listOf(
|
||||||
|
GalleryItemType.Video(
|
||||||
|
content = VideoMessageType(
|
||||||
|
filename = "video.mp4",
|
||||||
|
caption = "caption",
|
||||||
|
formattedCaption = null,
|
||||||
|
source = MediaSource("video_url"),
|
||||||
|
info = VideoInfo(
|
||||||
|
mimetype = MimeTypes.Mp4,
|
||||||
|
size = 123L,
|
||||||
|
thumbnailInfo = null,
|
||||||
|
duration = 123.seconds,
|
||||||
|
height = 1L,
|
||||||
|
width = 2L,
|
||||||
|
thumbnailSource = MediaSource("thumbnail_url"),
|
||||||
|
blurhash = null,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
assertThat(result).containsExactly(
|
||||||
|
MediaItem.Video(
|
||||||
|
id = UniqueId("aUniqueId_0"),
|
||||||
|
eventId = AN_EVENT_ID,
|
||||||
|
mediaInfo = MediaInfo(
|
||||||
|
mimeType = MimeTypes.Mp4,
|
||||||
|
filename = "video.mp4",
|
||||||
|
fileSize = 123L,
|
||||||
|
caption = "caption",
|
||||||
|
formattedFileSize = "123 Bytes",
|
||||||
|
fileExtension = "mp4",
|
||||||
|
senderId = A_USER_ID,
|
||||||
|
senderName = "alice",
|
||||||
|
senderAvatar = null,
|
||||||
|
dateSent = "0 Day false",
|
||||||
|
dateSentFull = "0 Full false",
|
||||||
|
waveform = null,
|
||||||
|
duration = "2:03",
|
||||||
|
),
|
||||||
|
mediaSource = MediaSource("video_url"),
|
||||||
|
thumbnailSource = MediaSource("thumbnail_url"),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `create for GalleryMessageType with audio item`() {
|
||||||
|
val factory = createEventItemFactory()
|
||||||
|
val result = factory.create(
|
||||||
|
MatrixTimelineItem.Event(
|
||||||
|
uniqueId = A_UNIQUE_ID,
|
||||||
|
event = anEventTimelineItem(
|
||||||
|
content = aMessageContent(
|
||||||
|
messageType = GalleryMessageType(
|
||||||
|
body = "Gallery body",
|
||||||
|
formatted = null,
|
||||||
|
items = listOf(
|
||||||
|
GalleryItemType.Audio(
|
||||||
|
content = AudioMessageType(
|
||||||
|
filename = "audio.mp3",
|
||||||
|
caption = "caption",
|
||||||
|
formattedCaption = null,
|
||||||
|
source = MediaSource("audio_url"),
|
||||||
|
info = AudioInfo(
|
||||||
|
mimetype = MimeTypes.Mp3,
|
||||||
|
size = 123L,
|
||||||
|
duration = 456.seconds,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
assertThat(result).containsExactly(
|
||||||
|
MediaItem.Audio(
|
||||||
|
id = UniqueId("aUniqueId_0"),
|
||||||
|
eventId = AN_EVENT_ID,
|
||||||
|
mediaInfo = MediaInfo(
|
||||||
|
mimeType = MimeTypes.Mp3,
|
||||||
|
filename = "audio.mp3",
|
||||||
|
fileSize = 123L,
|
||||||
|
caption = "caption",
|
||||||
|
formattedFileSize = "123 Bytes",
|
||||||
|
fileExtension = "mp3",
|
||||||
|
senderId = A_USER_ID,
|
||||||
|
senderName = "alice",
|
||||||
|
senderAvatar = null,
|
||||||
|
dateSent = "0 Day false",
|
||||||
|
dateSentFull = "0 Full false",
|
||||||
|
waveform = null,
|
||||||
|
duration = null,
|
||||||
|
),
|
||||||
|
mediaSource = MediaSource("audio_url"),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `create for GalleryMessageType with file item`() {
|
||||||
|
val factory = createEventItemFactory()
|
||||||
|
val result = factory.create(
|
||||||
|
MatrixTimelineItem.Event(
|
||||||
|
uniqueId = A_UNIQUE_ID,
|
||||||
|
event = anEventTimelineItem(
|
||||||
|
content = aMessageContent(
|
||||||
|
messageType = GalleryMessageType(
|
||||||
|
body = "Gallery body",
|
||||||
|
formatted = null,
|
||||||
|
items = listOf(
|
||||||
|
GalleryItemType.File(
|
||||||
|
content = FileMessageType(
|
||||||
|
filename = "document.pdf",
|
||||||
|
caption = "caption",
|
||||||
|
formattedCaption = null,
|
||||||
|
source = MediaSource("file_url"),
|
||||||
|
info = FileInfo(
|
||||||
|
mimetype = MimeTypes.Pdf,
|
||||||
|
size = 456L,
|
||||||
|
thumbnailInfo = null,
|
||||||
|
thumbnailSource = null,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
assertThat(result).containsExactly(
|
||||||
|
MediaItem.File(
|
||||||
|
id = UniqueId("aUniqueId_0"),
|
||||||
|
eventId = AN_EVENT_ID,
|
||||||
|
mediaInfo = MediaInfo(
|
||||||
|
mimeType = MimeTypes.Pdf,
|
||||||
|
filename = "document.pdf",
|
||||||
|
fileSize = 456L,
|
||||||
|
caption = "caption",
|
||||||
|
formattedFileSize = "456 Bytes",
|
||||||
|
fileExtension = "pdf",
|
||||||
|
senderId = A_USER_ID,
|
||||||
|
senderName = "alice",
|
||||||
|
senderAvatar = null,
|
||||||
|
dateSent = "0 Day false",
|
||||||
|
dateSentFull = "0 Full false",
|
||||||
|
waveform = null,
|
||||||
|
duration = null,
|
||||||
|
),
|
||||||
|
mediaSource = MediaSource("file_url"),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `create for GalleryMessageType with Other item returns empty list`() {
|
||||||
|
val factory = createEventItemFactory()
|
||||||
|
val result = factory.create(
|
||||||
|
MatrixTimelineItem.Event(
|
||||||
|
uniqueId = A_UNIQUE_ID,
|
||||||
|
event = anEventTimelineItem(
|
||||||
|
content = aMessageContent(
|
||||||
|
messageType = GalleryMessageType(
|
||||||
|
body = "Gallery body",
|
||||||
|
formatted = null,
|
||||||
|
items = listOf(
|
||||||
|
GalleryItemType.Other(itemType = "unknown_type", body = "Some body")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
assertThat(result).isEmpty()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `create for GalleryMessageType with multiple items produces indexed IDs`() {
|
||||||
|
val factory = createEventItemFactory()
|
||||||
|
val result = factory.create(
|
||||||
|
MatrixTimelineItem.Event(
|
||||||
|
uniqueId = A_UNIQUE_ID,
|
||||||
|
event = anEventTimelineItem(
|
||||||
|
content = aMessageContent(
|
||||||
|
messageType = GalleryMessageType(
|
||||||
|
body = "Gallery body",
|
||||||
|
formatted = null,
|
||||||
|
items = listOf(
|
||||||
|
GalleryItemType.Image(
|
||||||
|
content = ImageMessageType(
|
||||||
|
filename = "image.jpg",
|
||||||
|
caption = null,
|
||||||
|
formattedCaption = null,
|
||||||
|
source = MediaSource("image_url"),
|
||||||
|
info = ImageInfo(
|
||||||
|
mimetype = MimeTypes.Jpeg,
|
||||||
|
size = 123L,
|
||||||
|
thumbnailInfo = null,
|
||||||
|
thumbnailSource = null,
|
||||||
|
height = 1L,
|
||||||
|
width = 2L,
|
||||||
|
blurhash = null,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
),
|
||||||
|
GalleryItemType.Video(
|
||||||
|
content = VideoMessageType(
|
||||||
|
filename = "video.mp4",
|
||||||
|
caption = null,
|
||||||
|
formattedCaption = null,
|
||||||
|
source = MediaSource("video_url"),
|
||||||
|
info = VideoInfo(
|
||||||
|
mimetype = MimeTypes.Mp4,
|
||||||
|
size = 456L,
|
||||||
|
thumbnailInfo = null,
|
||||||
|
duration = null,
|
||||||
|
height = 1L,
|
||||||
|
width = 2L,
|
||||||
|
thumbnailSource = null,
|
||||||
|
blurhash = null,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
),
|
||||||
|
GalleryItemType.Other(itemType = "unknown_type", body = "ignored"),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
assertThat(result).hasSize(2)
|
||||||
|
assertThat(result[0]).isInstanceOf(MediaItem.Image::class.java)
|
||||||
|
assertThat((result[0] as MediaItem.Image).id).isEqualTo(UniqueId("aUniqueId_0"))
|
||||||
|
assertThat(result[1]).isInstanceOf(MediaItem.Video::class.java)
|
||||||
|
assertThat((result[1] as MediaItem.Video).id).isEqualTo(UniqueId("aUniqueId_1"))
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `create for StickerMessageType`() {
|
fun `create for StickerMessageType`() {
|
||||||
val factory = createEventItemFactory()
|
val factory = createEventItemFactory()
|
||||||
|
|||||||
Reference in New Issue
Block a user