Fix tests after change on InReplyTo classes
This commit is contained in:
parent
4de8713b5f
commit
906650b8d2
4 changed files with 45 additions and 40 deletions
|
|
@ -92,6 +92,7 @@ import io.element.android.features.messages.impl.timeline.model.event.TimelineIt
|
|||
import io.element.android.features.messages.impl.timeline.model.event.aTimelineItemImageContent
|
||||
import io.element.android.features.messages.impl.timeline.model.event.aTimelineItemTextContent
|
||||
import io.element.android.features.messages.impl.timeline.model.event.canBeRepliedTo
|
||||
import io.element.android.features.messages.impl.timeline.model.eventId
|
||||
import io.element.android.features.messages.impl.timeline.model.metadata
|
||||
import io.element.android.libraries.designsystem.atomic.atoms.PlaceholderAtom
|
||||
import io.element.android.libraries.designsystem.colors.AvatarColorsProvider
|
||||
|
|
@ -146,7 +147,7 @@ fun TimelineItemEventRow(
|
|||
}
|
||||
|
||||
fun inReplyToClicked() {
|
||||
val inReplyToEventId = event.inReplyTo?.eventId ?: return
|
||||
val inReplyToEventId = event.inReplyTo?.eventId() ?: return
|
||||
inReplyToClick(inReplyToEventId)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package io.element.android.features.messages.impl.timeline.model
|
||||
|
||||
import androidx.compose.runtime.Immutable
|
||||
import io.element.android.libraries.matrix.api.core.EventId
|
||||
import io.element.android.libraries.matrix.api.core.UserId
|
||||
import io.element.android.libraries.matrix.api.permalink.PermalinkParser
|
||||
|
|
@ -27,17 +28,24 @@ import io.element.android.libraries.matrix.api.timeline.item.event.StickerConten
|
|||
import io.element.android.libraries.matrix.api.timeline.item.event.TextMessageType
|
||||
import io.element.android.libraries.matrix.ui.messages.toPlainText
|
||||
|
||||
sealed class InReplyToDetails(val eventId: EventId) {
|
||||
class Ready(
|
||||
eventId: EventId,
|
||||
@Immutable
|
||||
sealed interface InReplyToDetails {
|
||||
data class Ready(
|
||||
val eventId: EventId,
|
||||
val senderId: UserId,
|
||||
val senderProfile: ProfileTimelineDetails,
|
||||
val eventContent: EventContent?,
|
||||
val textContent: String?,
|
||||
) : InReplyToDetails(eventId)
|
||||
) : InReplyToDetails
|
||||
|
||||
class Loading(eventId: EventId) : InReplyToDetails(eventId)
|
||||
class Error(eventId: EventId, val message: String) : InReplyToDetails(eventId)
|
||||
data class Loading(val eventId: EventId) : InReplyToDetails
|
||||
data class Error(val eventId: EventId, val message: String) : InReplyToDetails
|
||||
}
|
||||
|
||||
fun InReplyToDetails.eventId() = when (this) {
|
||||
is InReplyToDetails.Ready -> eventId
|
||||
is InReplyToDetails.Loading -> eventId
|
||||
is InReplyToDetails.Error -> eventId
|
||||
}
|
||||
|
||||
fun InReplyTo.map(
|
||||
|
|
|
|||
|
|
@ -32,22 +32,22 @@ import org.junit.Test
|
|||
|
||||
class InReplyToDetailTest {
|
||||
@Test
|
||||
fun `map - with a not ready InReplyTo does not work`() {
|
||||
fun `map - with a not ready InReplyTo return expected object`() {
|
||||
assertThat(
|
||||
InReplyTo.Pending.map(
|
||||
InReplyTo.Pending(AN_EVENT_ID).map(
|
||||
permalinkParser = FakePermalinkParser()
|
||||
)
|
||||
).isNull()
|
||||
).isEqualTo(InReplyToDetails.Loading(AN_EVENT_ID))
|
||||
assertThat(
|
||||
InReplyTo.NotLoaded(AN_EVENT_ID).map(
|
||||
permalinkParser = FakePermalinkParser()
|
||||
)
|
||||
).isNull()
|
||||
).isEqualTo(InReplyToDetails.Loading(AN_EVENT_ID))
|
||||
assertThat(
|
||||
InReplyTo.Error.map(
|
||||
InReplyTo.Error(AN_EVENT_ID, "a message").map(
|
||||
permalinkParser = FakePermalinkParser()
|
||||
)
|
||||
).isNull()
|
||||
).isEqualTo(InReplyToDetails.Error(AN_EVENT_ID, "a message"))
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -65,7 +65,7 @@ class InReplyToDetailTest {
|
|||
permalinkParser = FakePermalinkParser()
|
||||
)
|
||||
assertThat(inReplyToDetails).isNotNull()
|
||||
assertThat(inReplyToDetails?.textContent).isNull()
|
||||
assertThat((inReplyToDetails as InReplyToDetails.Ready).textContent).isNull()
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -89,9 +89,7 @@ class InReplyToDetailTest {
|
|||
)
|
||||
)
|
||||
assertThat(
|
||||
inReplyTo.map(
|
||||
permalinkParser = FakePermalinkParser()
|
||||
)?.textContent
|
||||
(inReplyTo.map(permalinkParser = FakePermalinkParser()) as InReplyToDetails.Ready).textContent
|
||||
).isEqualTo("Hello!")
|
||||
}
|
||||
|
||||
|
|
@ -113,9 +111,7 @@ class InReplyToDetailTest {
|
|||
)
|
||||
)
|
||||
assertThat(
|
||||
inReplyTo.map(
|
||||
permalinkParser = FakePermalinkParser()
|
||||
)?.textContent
|
||||
(inReplyTo.map(permalinkParser = FakePermalinkParser()) as InReplyToDetails.Ready).textContent
|
||||
).isEqualTo("**Hello!**")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ class InReplyToMetadataKtTest {
|
|||
@Test
|
||||
fun `any message content`() = runTest {
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
anInReplyToDetails(eventContent = aMessageContent()).metadata()
|
||||
anInReplyToDetailsReady(eventContent = aMessageContent()).metadata()
|
||||
}.test {
|
||||
awaitItem().let {
|
||||
assertThat(it).isEqualTo(InReplyToMetadata.Text("textContent"))
|
||||
|
|
@ -81,7 +81,7 @@ class InReplyToMetadataKtTest {
|
|||
@Test
|
||||
fun `an image message content`() = runTest {
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
anInReplyToDetails(
|
||||
anInReplyToDetailsReady(
|
||||
eventContent = aMessageContent(
|
||||
messageType = ImageMessageType(
|
||||
body = "body",
|
||||
|
|
@ -111,7 +111,7 @@ class InReplyToMetadataKtTest {
|
|||
@Test
|
||||
fun `a sticker message content`() = runTest {
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
anInReplyToDetails(
|
||||
anInReplyToDetailsReady(
|
||||
eventContent = StickerContent(
|
||||
body = "body",
|
||||
info = anImageInfo(),
|
||||
|
|
@ -137,7 +137,7 @@ class InReplyToMetadataKtTest {
|
|||
@Test
|
||||
fun `a video message content`() = runTest {
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
anInReplyToDetails(
|
||||
anInReplyToDetailsReady(
|
||||
eventContent = aMessageContent(
|
||||
messageType = VideoMessageType(
|
||||
body = "body",
|
||||
|
|
@ -167,7 +167,7 @@ class InReplyToMetadataKtTest {
|
|||
@Test
|
||||
fun `a file message content`() = runTest {
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
anInReplyToDetails(
|
||||
anInReplyToDetailsReady(
|
||||
eventContent = aMessageContent(
|
||||
messageType = FileMessageType(
|
||||
body = "body",
|
||||
|
|
@ -200,7 +200,7 @@ class InReplyToMetadataKtTest {
|
|||
@Test
|
||||
fun `a audio message content`() = runTest {
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
anInReplyToDetails(
|
||||
anInReplyToDetailsReady(
|
||||
eventContent = aMessageContent(
|
||||
messageType = AudioMessageType(
|
||||
body = "body",
|
||||
|
|
@ -232,7 +232,7 @@ class InReplyToMetadataKtTest {
|
|||
fun `a location message content`() = runTest {
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
testEnv {
|
||||
anInReplyToDetails(
|
||||
anInReplyToDetailsReady(
|
||||
eventContent = aMessageContent(
|
||||
messageType = LocationMessageType(
|
||||
body = "body",
|
||||
|
|
@ -262,7 +262,7 @@ class InReplyToMetadataKtTest {
|
|||
fun `a voice message content`() = runTest {
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
testEnv {
|
||||
anInReplyToDetails(
|
||||
anInReplyToDetailsReady(
|
||||
eventContent = aMessageContent(
|
||||
messageType = VoiceMessageType(
|
||||
body = "body",
|
||||
|
|
@ -292,7 +292,7 @@ class InReplyToMetadataKtTest {
|
|||
@Test
|
||||
fun `a poll content`() = runTest {
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
anInReplyToDetails(
|
||||
anInReplyToDetailsReady(
|
||||
eventContent = aPollContent()
|
||||
).metadata()
|
||||
}.test {
|
||||
|
|
@ -314,7 +314,7 @@ class InReplyToMetadataKtTest {
|
|||
@Test
|
||||
fun `redacted content`() = runTest {
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
anInReplyToDetails(
|
||||
anInReplyToDetailsReady(
|
||||
eventContent = RedactedContent
|
||||
).metadata()
|
||||
}.test {
|
||||
|
|
@ -327,7 +327,7 @@ class InReplyToMetadataKtTest {
|
|||
@Test
|
||||
fun `unable to decrypt content`() = runTest {
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
anInReplyToDetails(
|
||||
anInReplyToDetailsReady(
|
||||
eventContent = UnableToDecryptContent(UnableToDecryptContent.Data.Unknown)
|
||||
).metadata()
|
||||
}.test {
|
||||
|
|
@ -340,7 +340,7 @@ class InReplyToMetadataKtTest {
|
|||
@Test
|
||||
fun `failed to parse message content`() = runTest {
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
anInReplyToDetails(
|
||||
anInReplyToDetailsReady(
|
||||
eventContent = FailedToParseMessageLikeContent("", "")
|
||||
).metadata()
|
||||
}.test {
|
||||
|
|
@ -353,7 +353,7 @@ class InReplyToMetadataKtTest {
|
|||
@Test
|
||||
fun `failed to parse state content`() = runTest {
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
anInReplyToDetails(
|
||||
anInReplyToDetailsReady(
|
||||
eventContent = FailedToParseStateContent("", "", "")
|
||||
).metadata()
|
||||
}.test {
|
||||
|
|
@ -366,7 +366,7 @@ class InReplyToMetadataKtTest {
|
|||
@Test
|
||||
fun `profile change content`() = runTest {
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
anInReplyToDetails(
|
||||
anInReplyToDetailsReady(
|
||||
eventContent = ProfileChangeContent("", "", "", "")
|
||||
).metadata()
|
||||
}.test {
|
||||
|
|
@ -379,7 +379,7 @@ class InReplyToMetadataKtTest {
|
|||
@Test
|
||||
fun `room membership content`() = runTest {
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
anInReplyToDetails(
|
||||
anInReplyToDetailsReady(
|
||||
eventContent = RoomMembershipContent(A_USER_ID, null)
|
||||
).metadata()
|
||||
}.test {
|
||||
|
|
@ -392,7 +392,7 @@ class InReplyToMetadataKtTest {
|
|||
@Test
|
||||
fun `state content`() = runTest {
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
anInReplyToDetails(
|
||||
anInReplyToDetailsReady(
|
||||
eventContent = StateContent("", OtherState.RoomJoinRules)
|
||||
).metadata()
|
||||
}.test {
|
||||
|
|
@ -405,7 +405,7 @@ class InReplyToMetadataKtTest {
|
|||
@Test
|
||||
fun `unknown content`() = runTest {
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
anInReplyToDetails(
|
||||
anInReplyToDetailsReady(
|
||||
eventContent = UnknownContent
|
||||
).metadata()
|
||||
}.test {
|
||||
|
|
@ -418,7 +418,7 @@ class InReplyToMetadataKtTest {
|
|||
@Test
|
||||
fun `null content`() = runTest {
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
anInReplyToDetails(
|
||||
anInReplyToDetailsReady(
|
||||
eventContent = null
|
||||
).metadata()
|
||||
}.test {
|
||||
|
|
@ -429,13 +429,13 @@ class InReplyToMetadataKtTest {
|
|||
}
|
||||
}
|
||||
|
||||
fun anInReplyToDetails(
|
||||
private fun anInReplyToDetailsReady(
|
||||
eventId: EventId = AN_EVENT_ID,
|
||||
senderId: UserId = A_USER_ID,
|
||||
senderProfile: ProfileTimelineDetails = aProfileTimelineDetails(),
|
||||
eventContent: EventContent? = aMessageContent(),
|
||||
textContent: String? = "textContent",
|
||||
) = InReplyToDetails(
|
||||
) = InReplyToDetails.Ready(
|
||||
eventId = eventId,
|
||||
senderId = senderId,
|
||||
senderProfile = senderProfile,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue