From eeb13b3f6ceb4e5f200412e2a5844ab1706b963f Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Mon, 24 Oct 2022 22:56:17 +0100 Subject: [PATCH] adding missing rich text test usages --- .../st/notifications/RoomEventsToNotifiableMapperTest.kt | 8 +++++--- .../app/dapk/st/engine/MergeWithLocalEchosUseCaseTest.kt | 3 ++- .../engine/ObserveUnreadRenderNotificationsUseCaseTest.kt | 5 +++-- .../test/kotlin/app/dapk/st/engine/TimelineUseCaseTest.kt | 3 ++- .../src/testFixtures/kotlin/fixture/MessageFixture.kt | 3 ++- test-harness/src/test/kotlin/test/Test.kt | 6 ++++-- 6 files changed, 18 insertions(+), 10 deletions(-) diff --git a/features/notifications/src/test/kotlin/app/dapk/st/notifications/RoomEventsToNotifiableMapperTest.kt b/features/notifications/src/test/kotlin/app/dapk/st/notifications/RoomEventsToNotifiableMapperTest.kt index 11d8241..b128732 100644 --- a/features/notifications/src/test/kotlin/app/dapk/st/notifications/RoomEventsToNotifiableMapperTest.kt +++ b/features/notifications/src/test/kotlin/app/dapk/st/notifications/RoomEventsToNotifiableMapperTest.kt @@ -1,5 +1,7 @@ package app.dapk.st.notifications +import app.dapk.st.matrix.common.RichText +import app.dapk.st.matrix.common.asString import fixture.aRoomImageMessageEvent import fixture.aRoomMessageEvent import fixture.aRoomReplyMessageEvent @@ -18,7 +20,7 @@ class RoomEventsToNotifiableMapperTest { result shouldBeEqualTo listOf( Notifiable( - content = event.content, + content = event.content.asString(), utcTimestamp = event.utcTimestamp, author = event.author ) @@ -42,14 +44,14 @@ class RoomEventsToNotifiableMapperTest { @Test fun `given reply event with message, when mapping, then uses message for content`() { - val reply = aRoomMessageEvent(utcTimestamp = -1, content = "hello") + val reply = aRoomMessageEvent(utcTimestamp = -1, content = RichText.of("hello")) val event = aRoomReplyMessageEvent(reply, replyingTo = aRoomImageMessageEvent(utcTimestamp = -1)) val result = mapper.map(listOf(event)) result shouldBeEqualTo listOf( Notifiable( - content = reply.content, + content = reply.content.asString(), utcTimestamp = event.utcTimestamp, author = event.author ) diff --git a/matrix-chat-engine/src/test/kotlin/app/dapk/st/engine/MergeWithLocalEchosUseCaseTest.kt b/matrix-chat-engine/src/test/kotlin/app/dapk/st/engine/MergeWithLocalEchosUseCaseTest.kt index 5603193..4868445 100644 --- a/matrix-chat-engine/src/test/kotlin/app/dapk/st/engine/MergeWithLocalEchosUseCaseTest.kt +++ b/matrix-chat-engine/src/test/kotlin/app/dapk/st/engine/MergeWithLocalEchosUseCaseTest.kt @@ -1,6 +1,7 @@ package app.dapk.st.engine import app.dapk.st.matrix.common.EventId +import app.dapk.st.matrix.common.RichText import app.dapk.st.matrix.message.MessageService import fixture.* import org.amshove.kluent.shouldBeEqualTo @@ -54,7 +55,7 @@ class MergeWithLocalEchosUseCaseTest { private fun createLocalEcho(eventId: EventId, body: String, state: MessageService.LocalEcho.State) = aLocalEcho( eventId, - aTextMessage(aTextContent(body)), + aTextMessage(aTextContent(RichText.of(body))), state, ) } \ No newline at end of file diff --git a/matrix-chat-engine/src/test/kotlin/app/dapk/st/engine/ObserveUnreadRenderNotificationsUseCaseTest.kt b/matrix-chat-engine/src/test/kotlin/app/dapk/st/engine/ObserveUnreadRenderNotificationsUseCaseTest.kt index 50bd2b9..075de8e 100644 --- a/matrix-chat-engine/src/test/kotlin/app/dapk/st/engine/ObserveUnreadRenderNotificationsUseCaseTest.kt +++ b/matrix-chat-engine/src/test/kotlin/app/dapk/st/engine/ObserveUnreadRenderNotificationsUseCaseTest.kt @@ -1,5 +1,6 @@ package app.dapk.st.engine +import app.dapk.st.matrix.common.RichText import fake.FakeRoomStore import fixture.NotificationDiffFixtures.aNotificationDiff import fixture.aMatrixRoomMessageEvent @@ -15,8 +16,8 @@ import app.dapk.st.matrix.sync.RoomEvent as MatrixRoomEvent import app.dapk.st.matrix.sync.RoomOverview as MatrixRoomOverview private val NO_UNREADS = emptyMap>() -private val A_MESSAGE = aMatrixRoomMessageEvent(eventId = anEventId("1"), content = "hello", utcTimestamp = 1000) -private val A_MESSAGE_2 = aMatrixRoomMessageEvent(eventId = anEventId("2"), content = "world", utcTimestamp = 2000) +private val A_MESSAGE = aMatrixRoomMessageEvent(eventId = anEventId("1"), content = RichText.of("hello"), utcTimestamp = 1000) +private val A_MESSAGE_2 = aMatrixRoomMessageEvent(eventId = anEventId("2"), content = RichText.of("world"), utcTimestamp = 2000) private val A_ROOM_OVERVIEW = aMatrixRoomOverview(roomId = aRoomId("1")) private val A_ROOM_OVERVIEW_2 = aMatrixRoomOverview(roomId = aRoomId("2")) diff --git a/matrix-chat-engine/src/test/kotlin/app/dapk/st/engine/TimelineUseCaseTest.kt b/matrix-chat-engine/src/test/kotlin/app/dapk/st/engine/TimelineUseCaseTest.kt index c2edd7d..ae5b47e 100644 --- a/matrix-chat-engine/src/test/kotlin/app/dapk/st/engine/TimelineUseCaseTest.kt +++ b/matrix-chat-engine/src/test/kotlin/app/dapk/st/engine/TimelineUseCaseTest.kt @@ -1,5 +1,6 @@ package app.dapk.st.engine +import app.dapk.st.matrix.common.RichText import app.dapk.st.matrix.common.RoomId import app.dapk.st.matrix.common.RoomMember import app.dapk.st.matrix.common.UserId @@ -24,7 +25,7 @@ import test.delegateReturn private val A_ROOM_ID = aRoomId() private val AN_USER_ID = aUserId() private val A_ROOM_STATE = aMatrixRoomState() -private val A_MERGED_ROOM_STATE = A_ROOM_STATE.copy(events = listOf(aMatrixRoomMessageEvent(content = "a merged event"))) +private val A_MERGED_ROOM_STATE = A_ROOM_STATE.copy(events = listOf(aMatrixRoomMessageEvent(content = RichText.of("a merged event")))) private val A_LOCAL_ECHOS_LIST = listOf(aLocalEcho()) private val A_ROOM_MEMBER = aRoomMember() diff --git a/matrix/services/message/src/testFixtures/kotlin/fixture/MessageFixture.kt b/matrix/services/message/src/testFixtures/kotlin/fixture/MessageFixture.kt index 79c9e57..479b696 100644 --- a/matrix/services/message/src/testFixtures/kotlin/fixture/MessageFixture.kt +++ b/matrix/services/message/src/testFixtures/kotlin/fixture/MessageFixture.kt @@ -1,6 +1,7 @@ package fixture import app.dapk.st.matrix.common.MessageType +import app.dapk.st.matrix.common.RichText import app.dapk.st.matrix.common.RoomId import app.dapk.st.matrix.message.MessageService @@ -13,6 +14,6 @@ fun aTextMessage( ) = MessageService.Message.TextMessage(content, sendEncrypted, roomId, localId, timestampUtc) fun aTextContent( - body: String = "text content body", + body: RichText = RichText.of("text content body"), type: String = MessageType.TEXT.value, ) = MessageService.Message.Content.TextContent(body, type) diff --git a/test-harness/src/test/kotlin/test/Test.kt b/test-harness/src/test/kotlin/test/Test.kt index e0403a2..731927c 100644 --- a/test-harness/src/test/kotlin/test/Test.kt +++ b/test-harness/src/test/kotlin/test/Test.kt @@ -5,8 +5,10 @@ package test import TestMessage import TestUser import app.dapk.st.core.extensions.ifNull +import app.dapk.st.matrix.common.RichText import app.dapk.st.matrix.common.RoomId import app.dapk.st.matrix.common.RoomMember +import app.dapk.st.matrix.common.asString import app.dapk.st.matrix.crypto.MatrixMediaDecrypter import app.dapk.st.matrix.message.MessageService import app.dapk.st.matrix.message.messageService @@ -138,7 +140,7 @@ class MatrixTestScope(private val testScope: TestScope) { suspend fun TestMatrix.expectTextMessage(roomId: RoomId, message: TestMessage) { println("expecting ${message.content}") this.client.syncService().room(roomId) - .map { it.events.filterIsInstance().map { TestMessage(it.content, it.author) }.firstOrNull() } + .map { it.events.filterIsInstance().map { TestMessage(it.content.asString(), it.author) }.firstOrNull() } .assert(message) } @@ -170,7 +172,7 @@ class MatrixTestScope(private val testScope: TestScope) { println("sending $content") this.client.messageService().scheduleMessage( MessageService.Message.TextMessage( - content = MessageService.Message.Content.TextContent(body = content), + content = MessageService.Message.Content.TextContent(body = RichText.of(content)), roomId = roomId, sendEncrypted = isEncrypted, localId = "local.${UUID.randomUUID()}",