Browse Source

Create fixtures for TextEditorState.

pull/3758/head
Benoit Marty 2 days ago
parent
commit
26a4441d64
  1. 5
      features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesStateProvider.kt
  2. 7
      features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/crypto/identity/MessagesViewWithIdentityChangePreview.kt
  3. 4
      features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/messagecomposer/MessageComposerStateProvider.kt
  4. 4
      features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/MessagesPresenterTest.kt
  5. 42
      libraries/textcomposer/impl/src/main/kotlin/io/element/android/libraries/textcomposer/TextComposer.kt
  6. 2
      libraries/textcomposer/impl/src/main/kotlin/io/element/android/libraries/textcomposer/components/TextFormatting.kt
  7. 11
      libraries/textcomposer/impl/src/main/kotlin/io/element/android/libraries/textcomposer/components/markdown/MarkdownTextInput.kt
  8. 61
      libraries/textcomposer/impl/src/main/kotlin/io/element/android/libraries/textcomposer/model/Fixtures.kt
  9. 24
      libraries/textcomposer/impl/src/test/kotlin/io/element/android/libraries/textcomposer/impl/model/MarkdownTextEditorStateTest.kt

5
features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesStateProvider.kt

@ -37,9 +37,8 @@ import io.element.android.libraries.architecture.AsyncData
import io.element.android.libraries.designsystem.components.avatar.AvatarData import io.element.android.libraries.designsystem.components.avatar.AvatarData
import io.element.android.libraries.designsystem.components.avatar.AvatarSize import io.element.android.libraries.designsystem.components.avatar.AvatarSize
import io.element.android.libraries.matrix.api.core.RoomId import io.element.android.libraries.matrix.api.core.RoomId
import io.element.android.libraries.textcomposer.aRichTextEditorState
import io.element.android.libraries.textcomposer.model.MessageComposerMode import io.element.android.libraries.textcomposer.model.MessageComposerMode
import io.element.android.libraries.textcomposer.model.TextEditorState import io.element.android.libraries.textcomposer.model.aTextEditorStateRich
import kotlinx.collections.immutable.persistentListOf import kotlinx.collections.immutable.persistentListOf
import kotlinx.collections.immutable.persistentSetOf import kotlinx.collections.immutable.persistentSetOf
@ -97,7 +96,7 @@ fun aMessagesState(
roomAvatar: AsyncData<AvatarData> = AsyncData.Success(AvatarData("!id:domain", "Room name", size = AvatarSize.TimelineRoom)), roomAvatar: AsyncData<AvatarData> = AsyncData.Success(AvatarData("!id:domain", "Room name", size = AvatarSize.TimelineRoom)),
userEventPermissions: UserEventPermissions = aUserEventPermissions(), userEventPermissions: UserEventPermissions = aUserEventPermissions(),
composerState: MessageComposerState = aMessageComposerState( composerState: MessageComposerState = aMessageComposerState(
textEditorState = TextEditorState.Rich(aRichTextEditorState(initialText = "Hello", initialFocus = true)), textEditorState = aTextEditorStateRich(initialText = "Hello", initialFocus = true),
isFullScreen = false, isFullScreen = false,
mode = MessageComposerMode.Normal, mode = MessageComposerMode.Normal,
), ),

7
features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/crypto/identity/MessagesViewWithIdentityChangePreview.kt

@ -14,8 +14,7 @@ import io.element.android.features.messages.impl.aMessagesState
import io.element.android.features.messages.impl.messagecomposer.aMessageComposerState import io.element.android.features.messages.impl.messagecomposer.aMessageComposerState
import io.element.android.libraries.designsystem.preview.ElementPreview import io.element.android.libraries.designsystem.preview.ElementPreview
import io.element.android.libraries.designsystem.preview.PreviewsDayNight import io.element.android.libraries.designsystem.preview.PreviewsDayNight
import io.element.android.libraries.textcomposer.model.MarkdownTextEditorState import io.element.android.libraries.textcomposer.model.aTextEditorStateMarkdown
import io.element.android.libraries.textcomposer.model.TextEditorState
@PreviewsDayNight @PreviewsDayNight
@Composable @Composable
@ -25,12 +24,10 @@ internal fun MessagesViewWithIdentityChangePreview(
MessagesView( MessagesView(
state = aMessagesState( state = aMessagesState(
composerState = aMessageComposerState( composerState = aMessageComposerState(
textEditorState = TextEditorState.Markdown( textEditorState = aTextEditorStateMarkdown(
state = MarkdownTextEditorState(
initialText = "", initialText = "",
initialFocus = false, initialFocus = false,
) )
)
), ),
identityChangeState = identityChangeState, identityChangeState = identityChangeState,
), ),

4
features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/messagecomposer/MessageComposerStateProvider.kt

@ -8,10 +8,10 @@
package io.element.android.features.messages.impl.messagecomposer package io.element.android.features.messages.impl.messagecomposer
import androidx.compose.ui.tooling.preview.PreviewParameterProvider import androidx.compose.ui.tooling.preview.PreviewParameterProvider
import io.element.android.libraries.textcomposer.aRichTextEditorState
import io.element.android.libraries.textcomposer.mentions.ResolvedSuggestion import io.element.android.libraries.textcomposer.mentions.ResolvedSuggestion
import io.element.android.libraries.textcomposer.model.MessageComposerMode import io.element.android.libraries.textcomposer.model.MessageComposerMode
import io.element.android.libraries.textcomposer.model.TextEditorState import io.element.android.libraries.textcomposer.model.TextEditorState
import io.element.android.libraries.textcomposer.model.aTextEditorStateRich
import io.element.android.wysiwyg.display.TextDisplay import io.element.android.wysiwyg.display.TextDisplay
import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentListOf import kotlinx.collections.immutable.persistentListOf
@ -24,7 +24,7 @@ open class MessageComposerStateProvider : PreviewParameterProvider<MessageCompos
} }
fun aMessageComposerState( fun aMessageComposerState(
textEditorState: TextEditorState = TextEditorState.Rich(aRichTextEditorState()), textEditorState: TextEditorState = aTextEditorStateRich(),
isFullScreen: Boolean = false, isFullScreen: Boolean = false,
mode: MessageComposerMode = MessageComposerMode.Normal, mode: MessageComposerMode = MessageComposerMode.Normal,
showTextFormatting: Boolean = false, showTextFormatting: Boolean = false,

4
features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/MessagesPresenterTest.kt

@ -69,9 +69,9 @@ import io.element.android.libraries.matrix.test.room.aRoomInfo
import io.element.android.libraries.matrix.test.room.aRoomMember import io.element.android.libraries.matrix.test.room.aRoomMember
import io.element.android.libraries.matrix.test.timeline.FakeTimeline import io.element.android.libraries.matrix.test.timeline.FakeTimeline
import io.element.android.libraries.matrix.ui.messages.reply.InReplyToDetails import io.element.android.libraries.matrix.ui.messages.reply.InReplyToDetails
import io.element.android.libraries.textcomposer.model.MarkdownTextEditorState
import io.element.android.libraries.textcomposer.model.MessageComposerMode import io.element.android.libraries.textcomposer.model.MessageComposerMode
import io.element.android.libraries.textcomposer.model.TextEditorState import io.element.android.libraries.textcomposer.model.TextEditorState
import io.element.android.libraries.textcomposer.model.aTextEditorStateMarkdown
import io.element.android.services.analytics.test.FakeAnalyticsService import io.element.android.services.analytics.test.FakeAnalyticsService
import io.element.android.tests.testutils.EventsRecorder import io.element.android.tests.testutils.EventsRecorder
import io.element.android.tests.testutils.WarmUpRule import io.element.android.tests.testutils.WarmUpRule
@ -1005,7 +1005,7 @@ class MessagesPresenterTest {
messageComposerPresenter: Presenter<MessageComposerState> = Presenter { messageComposerPresenter: Presenter<MessageComposerState> = Presenter {
aMessageComposerState( aMessageComposerState(
// Use TextEditorState.Markdown, so that we can request focus manually. // Use TextEditorState.Markdown, so that we can request focus manually.
textEditorState = TextEditorState.Markdown(MarkdownTextEditorState(initialText = "", initialFocus = false)) textEditorState = aTextEditorStateMarkdown(initialText = "", initialFocus = false)
) )
}, },
actionListEventSink: (ActionListEvents) -> Unit = {}, actionListEventSink: (ActionListEvents) -> Unit = {},

42
libraries/textcomposer/impl/src/main/kotlin/io/element/android/libraries/textcomposer/TextComposer.kt

@ -57,7 +57,6 @@ import io.element.android.libraries.textcomposer.components.VoiceMessagePreview
import io.element.android.libraries.textcomposer.components.VoiceMessageRecorderButton import io.element.android.libraries.textcomposer.components.VoiceMessageRecorderButton
import io.element.android.libraries.textcomposer.components.VoiceMessageRecording import io.element.android.libraries.textcomposer.components.VoiceMessageRecording
import io.element.android.libraries.textcomposer.components.markdown.MarkdownTextInput import io.element.android.libraries.textcomposer.components.markdown.MarkdownTextInput
import io.element.android.libraries.textcomposer.components.markdown.aMarkdownTextEditorState
import io.element.android.libraries.textcomposer.components.textInputRoundedCornerShape import io.element.android.libraries.textcomposer.components.textInputRoundedCornerShape
import io.element.android.libraries.textcomposer.model.MessageComposerMode import io.element.android.libraries.textcomposer.model.MessageComposerMode
import io.element.android.libraries.textcomposer.model.Suggestion import io.element.android.libraries.textcomposer.model.Suggestion
@ -65,6 +64,8 @@ import io.element.android.libraries.textcomposer.model.TextEditorState
import io.element.android.libraries.textcomposer.model.VoiceMessagePlayerEvent import io.element.android.libraries.textcomposer.model.VoiceMessagePlayerEvent
import io.element.android.libraries.textcomposer.model.VoiceMessageRecorderEvent import io.element.android.libraries.textcomposer.model.VoiceMessageRecorderEvent
import io.element.android.libraries.textcomposer.model.VoiceMessageState import io.element.android.libraries.textcomposer.model.VoiceMessageState
import io.element.android.libraries.textcomposer.model.aTextEditorStateMarkdown
import io.element.android.libraries.textcomposer.model.aTextEditorStateRich
import io.element.android.libraries.ui.strings.CommonStrings import io.element.android.libraries.ui.strings.CommonStrings
import io.element.android.wysiwyg.compose.RichTextEditor import io.element.android.wysiwyg.compose.RichTextEditor
import io.element.android.wysiwyg.compose.RichTextEditorState import io.element.android.wysiwyg.compose.RichTextEditorState
@ -500,7 +501,7 @@ internal fun TextComposerSimplePreview() = ElementPreview {
items = persistentListOf( items = persistentListOf(
{ {
ATextComposer( ATextComposer(
TextEditorState.Markdown(aMarkdownTextEditorState(initialText = "", initialFocus = true)), state = aTextEditorStateMarkdown(initialText = "", initialFocus = true),
voiceMessageState = VoiceMessageState.Idle, voiceMessageState = VoiceMessageState.Idle,
composerMode = MessageComposerMode.Normal, composerMode = MessageComposerMode.Normal,
enableVoiceMessages = true, enableVoiceMessages = true,
@ -508,7 +509,7 @@ internal fun TextComposerSimplePreview() = ElementPreview {
}, },
{ {
ATextComposer( ATextComposer(
TextEditorState.Markdown(aMarkdownTextEditorState(initialText = "A message", initialFocus = true)), state = aTextEditorStateMarkdown(initialText = "A message", initialFocus = true),
voiceMessageState = VoiceMessageState.Idle, voiceMessageState = VoiceMessageState.Idle,
composerMode = MessageComposerMode.Normal, composerMode = MessageComposerMode.Normal,
enableVoiceMessages = true, enableVoiceMessages = true,
@ -516,11 +517,9 @@ internal fun TextComposerSimplePreview() = ElementPreview {
}, },
{ {
ATextComposer( ATextComposer(
TextEditorState.Markdown( state = aTextEditorStateMarkdown(
aMarkdownTextEditorState(
initialText = "A message\nWith several lines\nTo preview larger textfields and long lines with overflow", initialText = "A message\nWith several lines\nTo preview larger textfields and long lines with overflow",
initialFocus = true initialFocus = true,
)
), ),
voiceMessageState = VoiceMessageState.Idle, voiceMessageState = VoiceMessageState.Idle,
composerMode = MessageComposerMode.Normal, composerMode = MessageComposerMode.Normal,
@ -529,7 +528,7 @@ internal fun TextComposerSimplePreview() = ElementPreview {
}, },
{ {
ATextComposer( ATextComposer(
TextEditorState.Markdown(aMarkdownTextEditorState(initialText = "A message without focus", initialFocus = false)), state = aTextEditorStateMarkdown(initialText = "A message without focus", initialFocus = false),
voiceMessageState = VoiceMessageState.Idle, voiceMessageState = VoiceMessageState.Idle,
composerMode = MessageComposerMode.Normal, composerMode = MessageComposerMode.Normal,
enableVoiceMessages = true, enableVoiceMessages = true,
@ -544,7 +543,7 @@ internal fun TextComposerSimplePreview() = ElementPreview {
internal fun TextComposerFormattingPreview() = ElementPreview { internal fun TextComposerFormattingPreview() = ElementPreview {
PreviewColumn(items = persistentListOf({ PreviewColumn(items = persistentListOf({
ATextComposer( ATextComposer(
TextEditorState.Rich(aRichTextEditorState()), state = aTextEditorStateRich(),
voiceMessageState = VoiceMessageState.Idle, voiceMessageState = VoiceMessageState.Idle,
showTextFormatting = true, showTextFormatting = true,
composerMode = MessageComposerMode.Normal, composerMode = MessageComposerMode.Normal,
@ -552,7 +551,7 @@ internal fun TextComposerFormattingPreview() = ElementPreview {
) )
}, { }, {
ATextComposer( ATextComposer(
TextEditorState.Rich(aRichTextEditorState(initialText = "A message")), state = aTextEditorStateRich(initialText = "A message"),
voiceMessageState = VoiceMessageState.Idle, voiceMessageState = VoiceMessageState.Idle,
showTextFormatting = true, showTextFormatting = true,
composerMode = MessageComposerMode.Normal, composerMode = MessageComposerMode.Normal,
@ -560,10 +559,8 @@ internal fun TextComposerFormattingPreview() = ElementPreview {
) )
}, { }, {
ATextComposer( ATextComposer(
TextEditorState.Rich( state = aTextEditorStateRich(
aRichTextEditorState(
initialText = "A message\nWith several lines\nTo preview larger textfields and long lines with overflow", initialText = "A message\nWith several lines\nTo preview larger textfields and long lines with overflow",
)
), ),
voiceMessageState = VoiceMessageState.Idle, voiceMessageState = VoiceMessageState.Idle,
showTextFormatting = true, showTextFormatting = true,
@ -578,7 +575,7 @@ internal fun TextComposerFormattingPreview() = ElementPreview {
internal fun TextComposerEditPreview() = ElementPreview { internal fun TextComposerEditPreview() = ElementPreview {
PreviewColumn(items = persistentListOf({ PreviewColumn(items = persistentListOf({
ATextComposer( ATextComposer(
TextEditorState.Rich(aRichTextEditorState(initialText = "A message", initialFocus = true)), state = aTextEditorStateRich(initialText = "A message", initialFocus = true),
voiceMessageState = VoiceMessageState.Idle, voiceMessageState = VoiceMessageState.Idle,
composerMode = aMessageComposerModeEdit(), composerMode = aMessageComposerModeEdit(),
enableVoiceMessages = true, enableVoiceMessages = true,
@ -591,7 +588,7 @@ internal fun TextComposerEditPreview() = ElementPreview {
internal fun MarkdownTextComposerEditPreview() = ElementPreview { internal fun MarkdownTextComposerEditPreview() = ElementPreview {
PreviewColumn(items = persistentListOf({ PreviewColumn(items = persistentListOf({
ATextComposer( ATextComposer(
TextEditorState.Markdown(aMarkdownTextEditorState(initialText = "A message", initialFocus = true)), state = aTextEditorStateMarkdown(initialText = "A message", initialFocus = true),
voiceMessageState = VoiceMessageState.Idle, voiceMessageState = VoiceMessageState.Idle,
composerMode = aMessageComposerModeEdit(), composerMode = aMessageComposerModeEdit(),
enableVoiceMessages = true, enableVoiceMessages = true,
@ -603,7 +600,7 @@ internal fun MarkdownTextComposerEditPreview() = ElementPreview {
@Composable @Composable
internal fun TextComposerReplyPreview(@PreviewParameter(InReplyToDetailsProvider::class) inReplyToDetails: InReplyToDetails) = ElementPreview { internal fun TextComposerReplyPreview(@PreviewParameter(InReplyToDetailsProvider::class) inReplyToDetails: InReplyToDetails) = ElementPreview {
ATextComposer( ATextComposer(
state = TextEditorState.Rich(aRichTextEditorState()), state = aTextEditorStateRich(),
voiceMessageState = VoiceMessageState.Idle, voiceMessageState = VoiceMessageState.Idle,
composerMode = aMessageComposerModeReply( composerMode = aMessageComposerModeReply(
replyToDetails = inReplyToDetails, replyToDetails = inReplyToDetails,
@ -619,7 +616,7 @@ internal fun TextComposerVoicePreview() = ElementPreview {
fun VoicePreview( fun VoicePreview(
voiceMessageState: VoiceMessageState voiceMessageState: VoiceMessageState
) = ATextComposer( ) = ATextComposer(
TextEditorState.Rich(aRichTextEditorState(initialFocus = true)), state = aTextEditorStateRich(initialFocus = true),
voiceMessageState = voiceMessageState, voiceMessageState = voiceMessageState,
composerMode = MessageComposerMode.Normal, composerMode = MessageComposerMode.Normal,
enableVoiceMessages = true, enableVoiceMessages = true,
@ -708,17 +705,6 @@ private fun ATextComposer(
) )
} }
fun aRichTextEditorState(
initialText: String = "",
initialHtml: String = initialText,
initialMarkdown: String = initialText,
initialFocus: Boolean = false,
) = RichTextEditorState(
initialHtml = initialHtml,
initialMarkdown = initialMarkdown,
initialFocus = initialFocus,
)
fun aMessageComposerModeEdit( fun aMessageComposerModeEdit(
eventOrTransactionId: EventOrTransactionId = EventId("$1234").toEventOrTransactionId(), eventOrTransactionId: EventOrTransactionId = EventId("$1234").toEventOrTransactionId(),
content: String = "Some text", content: String = "Some text",

2
libraries/textcomposer/impl/src/main/kotlin/io/element/android/libraries/textcomposer/components/TextFormatting.kt

@ -26,7 +26,7 @@ import io.element.android.libraries.designsystem.preview.ElementPreview
import io.element.android.libraries.designsystem.preview.PreviewsDayNight import io.element.android.libraries.designsystem.preview.PreviewsDayNight
import io.element.android.libraries.textcomposer.R import io.element.android.libraries.textcomposer.R
import io.element.android.libraries.textcomposer.TextComposerLinkDialog import io.element.android.libraries.textcomposer.TextComposerLinkDialog
import io.element.android.libraries.textcomposer.aRichTextEditorState import io.element.android.libraries.textcomposer.model.aRichTextEditorState
import io.element.android.wysiwyg.compose.RichTextEditorState import io.element.android.wysiwyg.compose.RichTextEditorState
import io.element.android.wysiwyg.view.models.InlineFormat import io.element.android.wysiwyg.view.models.InlineFormat
import io.element.android.wysiwyg.view.models.LinkAction import io.element.android.wysiwyg.view.models.LinkAction

11
libraries/textcomposer/impl/src/main/kotlin/io/element/android/libraries/textcomposer/components/markdown/MarkdownTextInput.kt

@ -36,6 +36,7 @@ import io.element.android.libraries.textcomposer.mentions.updateMentionStyles
import io.element.android.libraries.textcomposer.model.MarkdownTextEditorState import io.element.android.libraries.textcomposer.model.MarkdownTextEditorState
import io.element.android.libraries.textcomposer.model.Suggestion import io.element.android.libraries.textcomposer.model.Suggestion
import io.element.android.libraries.textcomposer.model.SuggestionType import io.element.android.libraries.textcomposer.model.SuggestionType
import io.element.android.libraries.textcomposer.model.aMarkdownTextEditorState
import io.element.android.wysiwyg.compose.RichTextEditorStyle import io.element.android.wysiwyg.compose.RichTextEditorStyle
import io.element.android.wysiwyg.compose.internal.applyStyleInCompose import io.element.android.wysiwyg.compose.internal.applyStyleInCompose
@ -184,7 +185,7 @@ internal fun MarkdownTextInputPreview() {
ElementPreview { ElementPreview {
val style = ElementRichTextEditorStyle.composerStyle(hasFocus = true) val style = ElementRichTextEditorStyle.composerStyle(hasFocus = true)
MarkdownTextInput( MarkdownTextInput(
state = aMarkdownTextEditorState(), state = aMarkdownTextEditorState(initialText = "Hello, World!"),
subcomposing = false, subcomposing = false,
onTyping = {}, onTyping = {},
onReceiveSuggestion = {}, onReceiveSuggestion = {},
@ -193,11 +194,3 @@ internal fun MarkdownTextInputPreview() {
) )
} }
} }
internal fun aMarkdownTextEditorState(
initialText: String = "Hello, World!",
initialFocus: Boolean = true,
) = MarkdownTextEditorState(
initialText = initialText,
initialFocus = initialFocus,
)

61
libraries/textcomposer/impl/src/main/kotlin/io/element/android/libraries/textcomposer/model/Fixtures.kt

@ -0,0 +1,61 @@
/*
* Copyright 2024 New Vector Ltd.
*
* SPDX-License-Identifier: AGPL-3.0-only
* Please see LICENSE in the repository root for full details.
*/
package io.element.android.libraries.textcomposer.model
import io.element.android.wysiwyg.compose.RichTextEditorState
fun aTextEditorStateMarkdown(
initialText: String? = "",
initialFocus: Boolean = false,
): TextEditorState {
return TextEditorState.Markdown(
aMarkdownTextEditorState(
initialText = initialText,
initialFocus = initialFocus,
)
)
}
fun aMarkdownTextEditorState(
initialText: String? = "",
initialFocus: Boolean = false,
): MarkdownTextEditorState {
return MarkdownTextEditorState(
initialText = initialText,
initialFocus = initialFocus,
)
}
fun aTextEditorStateRich(
initialText: String = "",
initialHtml: String = initialText,
initialMarkdown: String = initialText,
initialFocus: Boolean = false,
): TextEditorState {
return TextEditorState.Rich(
aRichTextEditorState(
initialText = initialText,
initialHtml = initialHtml,
initialMarkdown = initialMarkdown,
initialFocus = initialFocus,
)
)
}
fun aRichTextEditorState(
initialText: String = "",
initialHtml: String = initialText,
initialMarkdown: String = initialText,
initialFocus: Boolean = false,
): RichTextEditorState {
return RichTextEditorState(
initialHtml = initialHtml,
initialMarkdown = initialMarkdown,
initialFocus = initialFocus,
)
}

24
libraries/textcomposer/impl/src/test/kotlin/io/element/android/libraries/textcomposer/impl/model/MarkdownTextEditorStateTest.kt

@ -23,9 +23,9 @@ import io.element.android.libraries.matrix.test.room.aRoomMember
import io.element.android.libraries.textcomposer.mentions.MentionSpan import io.element.android.libraries.textcomposer.mentions.MentionSpan
import io.element.android.libraries.textcomposer.mentions.MentionSpanProvider import io.element.android.libraries.textcomposer.mentions.MentionSpanProvider
import io.element.android.libraries.textcomposer.mentions.ResolvedSuggestion import io.element.android.libraries.textcomposer.mentions.ResolvedSuggestion
import io.element.android.libraries.textcomposer.model.MarkdownTextEditorState
import io.element.android.libraries.textcomposer.model.Suggestion import io.element.android.libraries.textcomposer.model.Suggestion
import io.element.android.libraries.textcomposer.model.SuggestionType import io.element.android.libraries.textcomposer.model.SuggestionType
import io.element.android.libraries.textcomposer.model.aMarkdownTextEditorState
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
@ -33,7 +33,7 @@ import org.junit.runner.RunWith
class MarkdownTextEditorStateTest { class MarkdownTextEditorStateTest {
@Test @Test
fun `insertMention - room alias - getMentions return empty list`() { fun `insertMention - room alias - getMentions return empty list`() {
val state = MarkdownTextEditorState(initialText = "Hello @", initialFocus = true) val state = aMarkdownTextEditorState(initialText = "Hello @", initialFocus = true)
val suggestion = aRoomAliasSuggestion() val suggestion = aRoomAliasSuggestion()
val permalinkBuilder = FakePermalinkBuilder() val permalinkBuilder = FakePermalinkBuilder()
val mentionSpanProvider = aMentionSpanProvider() val mentionSpanProvider = aMentionSpanProvider()
@ -43,7 +43,7 @@ class MarkdownTextEditorStateTest {
@Test @Test
fun `insertSuggestion - room alias - with member but failed PermalinkBuilder result`() { fun `insertSuggestion - room alias - with member but failed PermalinkBuilder result`() {
val state = MarkdownTextEditorState(initialText = "Hello #", initialFocus = true).apply { val state = aMarkdownTextEditorState(initialText = "Hello #", initialFocus = true).apply {
currentSuggestion = Suggestion(start = 6, end = 7, type = SuggestionType.Room, text = "") currentSuggestion = Suggestion(start = 6, end = 7, type = SuggestionType.Room, text = "")
} }
val suggestion = aRoomAliasSuggestion() val suggestion = aRoomAliasSuggestion()
@ -55,7 +55,7 @@ class MarkdownTextEditorStateTest {
@Test @Test
fun `insertSuggestion - room alias`() { fun `insertSuggestion - room alias`() {
val state = MarkdownTextEditorState(initialText = "Hello #", initialFocus = true).apply { val state = aMarkdownTextEditorState(initialText = "Hello #", initialFocus = true).apply {
currentSuggestion = Suggestion(start = 6, end = 7, type = SuggestionType.Room, text = "") currentSuggestion = Suggestion(start = 6, end = 7, type = SuggestionType.Room, text = "")
} }
val suggestion = aRoomAliasSuggestion() val suggestion = aRoomAliasSuggestion()
@ -67,7 +67,7 @@ class MarkdownTextEditorStateTest {
@Test @Test
fun `insertSuggestion - with no currentMentionSuggestion does nothing`() { fun `insertSuggestion - with no currentMentionSuggestion does nothing`() {
val state = MarkdownTextEditorState(initialText = "Hello @", initialFocus = true) val state = aMarkdownTextEditorState(initialText = "Hello @", initialFocus = true)
val member = aRoomMember() val member = aRoomMember()
val mention = ResolvedSuggestion.Member(member) val mention = ResolvedSuggestion.Member(member)
val permalinkBuilder = FakePermalinkBuilder() val permalinkBuilder = FakePermalinkBuilder()
@ -80,7 +80,7 @@ class MarkdownTextEditorStateTest {
@Test @Test
fun `insertSuggestion - with member but failed PermalinkBuilder result`() { fun `insertSuggestion - with member but failed PermalinkBuilder result`() {
val state = MarkdownTextEditorState(initialText = "Hello @", initialFocus = true).apply { val state = aMarkdownTextEditorState(initialText = "Hello @", initialFocus = true).apply {
currentSuggestion = Suggestion(start = 6, end = 7, type = SuggestionType.Mention, text = "") currentSuggestion = Suggestion(start = 6, end = 7, type = SuggestionType.Mention, text = "")
} }
val member = aRoomMember() val member = aRoomMember()
@ -97,7 +97,7 @@ class MarkdownTextEditorStateTest {
@Test @Test
fun `insertSuggestion - with member`() { fun `insertSuggestion - with member`() {
val state = MarkdownTextEditorState(initialText = "Hello @", initialFocus = true).apply { val state = aMarkdownTextEditorState(initialText = "Hello @", initialFocus = true).apply {
currentSuggestion = Suggestion(start = 6, end = 7, type = SuggestionType.Mention, text = "") currentSuggestion = Suggestion(start = 6, end = 7, type = SuggestionType.Mention, text = "")
} }
val member = aRoomMember() val member = aRoomMember()
@ -115,7 +115,7 @@ class MarkdownTextEditorStateTest {
@Test @Test
fun `insertSuggestion - with @room`() { fun `insertSuggestion - with @room`() {
val state = MarkdownTextEditorState(initialText = "Hello @", initialFocus = true).apply { val state = aMarkdownTextEditorState(initialText = "Hello @", initialFocus = true).apply {
currentSuggestion = Suggestion(start = 6, end = 7, type = SuggestionType.Mention, text = "") currentSuggestion = Suggestion(start = 6, end = 7, type = SuggestionType.Mention, text = "")
} }
val mention = ResolvedSuggestion.AtRoom val mention = ResolvedSuggestion.AtRoom
@ -133,7 +133,7 @@ class MarkdownTextEditorStateTest {
@Test @Test
fun `getMessageMarkdown - when there are no MentionSpans returns the same text`() { fun `getMessageMarkdown - when there are no MentionSpans returns the same text`() {
val text = "No mentions here" val text = "No mentions here"
val state = MarkdownTextEditorState(initialText = text, initialFocus = true) val state = aMarkdownTextEditorState(initialText = text, initialFocus = true)
val markdown = state.getMessageMarkdown(FakePermalinkBuilder()) val markdown = state.getMessageMarkdown(FakePermalinkBuilder())
@ -147,7 +147,7 @@ class MarkdownTextEditorStateTest {
permalinkForUserLambda = { Result.success("https://matrix.to/#/$it") }, permalinkForUserLambda = { Result.success("https://matrix.to/#/$it") },
permalinkForRoomAliasLambda = { Result.success("https://matrix.to/#/$it") }, permalinkForRoomAliasLambda = { Result.success("https://matrix.to/#/$it") },
) )
val state = MarkdownTextEditorState(initialText = text, initialFocus = true) val state = aMarkdownTextEditorState(initialText = text, initialFocus = true)
state.text.update(aMarkdownTextWithMentions(), needsDisplaying = false) state.text.update(aMarkdownTextWithMentions(), needsDisplaying = false)
val markdown = state.getMessageMarkdown(permalinkBuilder = permalinkBuilder) val markdown = state.getMessageMarkdown(permalinkBuilder = permalinkBuilder)
@ -160,14 +160,14 @@ class MarkdownTextEditorStateTest {
@Test @Test
fun `getMentions - when there are no MentionSpans returns empty list of mentions`() { fun `getMentions - when there are no MentionSpans returns empty list of mentions`() {
val state = MarkdownTextEditorState(initialText = "Hello @", initialFocus = true) val state = aMarkdownTextEditorState(initialText = "Hello @", initialFocus = true)
assertThat(state.getMentions()).isEmpty() assertThat(state.getMentions()).isEmpty()
} }
@Test @Test
fun `getMentions - when there are MentionSpans returns a list of mentions`() { fun `getMentions - when there are MentionSpans returns a list of mentions`() {
val state = MarkdownTextEditorState(initialText = "Hello @", initialFocus = true) val state = aMarkdownTextEditorState(initialText = "Hello @", initialFocus = true)
state.text.update(aMarkdownTextWithMentions(), needsDisplaying = false) state.text.update(aMarkdownTextWithMentions(), needsDisplaying = false)
val mentions = state.getMentions() val mentions = state.getMentions()

Loading…
Cancel
Save