Browse Source

Merge pull request #3758 from element-hq/feature/bma/editorStateFixture

Editor state fixture and preview improvement
pull/3780/head
Benoit Marty 20 hours ago committed by GitHub
parent
commit
1dd2ad0c5c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 5
      features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesStateProvider.kt
  2. 11
      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. 195
      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. 2
      libraries/textcomposer/impl/src/test/kotlin/io/element/android/libraries/textcomposer/impl/components/markdown/MarkdownTextInputTest.kt
  10. 24
      libraries/textcomposer/impl/src/test/kotlin/io/element/android/libraries/textcomposer/impl/model/MarkdownTextEditorStateTest.kt
  11. 4
      tests/uitests/src/test/snapshots/images/libraries.textcomposer_MarkdownTextComposerEdit_Day_0_en.png
  12. 4
      tests/uitests/src/test/snapshots/images/libraries.textcomposer_MarkdownTextComposerEdit_Night_0_en.png
  13. 4
      tests/uitests/src/test/snapshots/images/libraries.textcomposer_TextComposerEdit_Day_0_en.png
  14. 4
      tests/uitests/src/test/snapshots/images/libraries.textcomposer_TextComposerEdit_Night_0_en.png
  15. 4
      tests/uitests/src/test/snapshots/images/libraries.textcomposer_TextComposerFormatting_Day_0_en.png
  16. 4
      tests/uitests/src/test/snapshots/images/libraries.textcomposer_TextComposerFormatting_Night_0_en.png
  17. 4
      tests/uitests/src/test/snapshots/images/libraries.textcomposer_TextComposerReply_Day_0_en.png
  18. 4
      tests/uitests/src/test/snapshots/images/libraries.textcomposer_TextComposerReply_Day_10_en.png
  19. 4
      tests/uitests/src/test/snapshots/images/libraries.textcomposer_TextComposerReply_Day_11_en.png
  20. 4
      tests/uitests/src/test/snapshots/images/libraries.textcomposer_TextComposerReply_Day_1_en.png
  21. 4
      tests/uitests/src/test/snapshots/images/libraries.textcomposer_TextComposerReply_Day_2_en.png
  22. 4
      tests/uitests/src/test/snapshots/images/libraries.textcomposer_TextComposerReply_Day_3_en.png
  23. 4
      tests/uitests/src/test/snapshots/images/libraries.textcomposer_TextComposerReply_Day_4_en.png
  24. 4
      tests/uitests/src/test/snapshots/images/libraries.textcomposer_TextComposerReply_Day_5_en.png
  25. 4
      tests/uitests/src/test/snapshots/images/libraries.textcomposer_TextComposerReply_Day_6_en.png
  26. 4
      tests/uitests/src/test/snapshots/images/libraries.textcomposer_TextComposerReply_Day_7_en.png
  27. 4
      tests/uitests/src/test/snapshots/images/libraries.textcomposer_TextComposerReply_Day_8_en.png
  28. 4
      tests/uitests/src/test/snapshots/images/libraries.textcomposer_TextComposerReply_Day_9_en.png
  29. 4
      tests/uitests/src/test/snapshots/images/libraries.textcomposer_TextComposerReply_Night_0_en.png
  30. 4
      tests/uitests/src/test/snapshots/images/libraries.textcomposer_TextComposerReply_Night_10_en.png
  31. 4
      tests/uitests/src/test/snapshots/images/libraries.textcomposer_TextComposerReply_Night_11_en.png
  32. 4
      tests/uitests/src/test/snapshots/images/libraries.textcomposer_TextComposerReply_Night_1_en.png
  33. 4
      tests/uitests/src/test/snapshots/images/libraries.textcomposer_TextComposerReply_Night_2_en.png
  34. 4
      tests/uitests/src/test/snapshots/images/libraries.textcomposer_TextComposerReply_Night_3_en.png
  35. 4
      tests/uitests/src/test/snapshots/images/libraries.textcomposer_TextComposerReply_Night_4_en.png
  36. 4
      tests/uitests/src/test/snapshots/images/libraries.textcomposer_TextComposerReply_Night_5_en.png
  37. 4
      tests/uitests/src/test/snapshots/images/libraries.textcomposer_TextComposerReply_Night_6_en.png
  38. 4
      tests/uitests/src/test/snapshots/images/libraries.textcomposer_TextComposerReply_Night_7_en.png
  39. 4
      tests/uitests/src/test/snapshots/images/libraries.textcomposer_TextComposerReply_Night_8_en.png
  40. 4
      tests/uitests/src/test/snapshots/images/libraries.textcomposer_TextComposerReply_Night_9_en.png

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

11
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 @@ -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.libraries.designsystem.preview.ElementPreview
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
import io.element.android.libraries.textcomposer.model.MarkdownTextEditorState
import io.element.android.libraries.textcomposer.model.TextEditorState
import io.element.android.libraries.textcomposer.model.aTextEditorStateMarkdown
@PreviewsDayNight
@Composable
@ -25,11 +24,9 @@ internal fun MessagesViewWithIdentityChangePreview( @@ -25,11 +24,9 @@ internal fun MessagesViewWithIdentityChangePreview(
MessagesView(
state = aMessagesState(
composerState = aMessageComposerState(
textEditorState = TextEditorState.Markdown(
state = MarkdownTextEditorState(
initialText = "",
initialFocus = false,
)
textEditorState = aTextEditorStateMarkdown(
initialText = "",
initialFocus = false,
)
),
identityChangeState = identityChangeState,

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

@ -8,10 +8,10 @@ @@ -8,10 +8,10 @@
package io.element.android.features.messages.impl.messagecomposer
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.model.MessageComposerMode
import io.element.android.libraries.textcomposer.model.TextEditorState
import io.element.android.libraries.textcomposer.model.aTextEditorStateRich
import io.element.android.wysiwyg.display.TextDisplay
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentListOf
@ -24,7 +24,7 @@ open class MessageComposerStateProvider : PreviewParameterProvider<MessageCompos @@ -24,7 +24,7 @@ open class MessageComposerStateProvider : PreviewParameterProvider<MessageCompos
}
fun aMessageComposerState(
textEditorState: TextEditorState = TextEditorState.Rich(aRichTextEditorState()),
textEditorState: TextEditorState = aTextEditorStateRich(),
isFullScreen: Boolean = false,
mode: MessageComposerMode = MessageComposerMode.Normal,
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 @@ -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.timeline.FakeTimeline
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.TextEditorState
import io.element.android.libraries.textcomposer.model.aTextEditorStateMarkdown
import io.element.android.services.analytics.test.FakeAnalyticsService
import io.element.android.tests.testutils.EventsRecorder
import io.element.android.tests.testutils.WarmUpRule
@ -1005,7 +1005,7 @@ class MessagesPresenterTest { @@ -1005,7 +1005,7 @@ class MessagesPresenterTest {
messageComposerPresenter: Presenter<MessageComposerState> = Presenter {
aMessageComposerState(
// 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 = {},

195
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 @@ -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.VoiceMessageRecording
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.model.MessageComposerMode
import io.element.android.libraries.textcomposer.model.Suggestion
@ -65,6 +64,8 @@ import io.element.android.libraries.textcomposer.model.TextEditorState @@ -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.VoiceMessageRecorderEvent
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.wysiwyg.compose.RichTextEditor
import io.element.android.wysiwyg.compose.RichTextEditorState
@ -493,185 +494,156 @@ private fun TextInput( @@ -493,185 +494,156 @@ private fun TextInput(
}
}
private fun aTextEditorStateMarkdownList() = persistentListOf(
aTextEditorStateMarkdown(initialText = "", initialFocus = true),
aTextEditorStateMarkdown(initialText = "A message", initialFocus = true),
aTextEditorStateMarkdown(
initialText = "A message\nWith several lines\nTo preview larger textfields and long lines with overflow",
initialFocus = true,
),
aTextEditorStateMarkdown(initialText = "A message without focus", initialFocus = false),
)
private fun aTextEditorStateRichList() = persistentListOf(
aTextEditorStateRich(initialFocus = true),
aTextEditorStateRich(initialText = "A message", initialFocus = true),
aTextEditorStateRich(
initialText = "A message\nWith several lines\nTo preview larger textfields and long lines with overflow",
initialFocus = true
),
aTextEditorStateRich(initialText = "A message without focus", initialFocus = false),
)
@PreviewsDayNight
@Composable
internal fun TextComposerSimplePreview() = ElementPreview {
PreviewColumn(
items = persistentListOf(
{
ATextComposer(
TextEditorState.Markdown(aMarkdownTextEditorState(initialText = "", initialFocus = true)),
voiceMessageState = VoiceMessageState.Idle,
composerMode = MessageComposerMode.Normal,
enableVoiceMessages = true,
)
},
{
ATextComposer(
TextEditorState.Markdown(aMarkdownTextEditorState(initialText = "A message", initialFocus = true)),
voiceMessageState = VoiceMessageState.Idle,
composerMode = MessageComposerMode.Normal,
enableVoiceMessages = true,
)
},
{
ATextComposer(
TextEditorState.Markdown(
aMarkdownTextEditorState(
initialText = "A message\nWith several lines\nTo preview larger textfields and long lines with overflow",
initialFocus = true
)
),
voiceMessageState = VoiceMessageState.Idle,
composerMode = MessageComposerMode.Normal,
enableVoiceMessages = true,
)
},
{
ATextComposer(
TextEditorState.Markdown(aMarkdownTextEditorState(initialText = "A message without focus", initialFocus = false)),
voiceMessageState = VoiceMessageState.Idle,
composerMode = MessageComposerMode.Normal,
enableVoiceMessages = true,
)
}
items = aTextEditorStateMarkdownList()
) { textEditorState ->
ATextComposer(
state = textEditorState,
voiceMessageState = VoiceMessageState.Idle,
composerMode = MessageComposerMode.Normal,
enableVoiceMessages = true,
)
)
}
}
@PreviewsDayNight
@Composable
internal fun TextComposerFormattingPreview() = ElementPreview {
PreviewColumn(items = persistentListOf({
ATextComposer(
TextEditorState.Rich(aRichTextEditorState()),
voiceMessageState = VoiceMessageState.Idle,
showTextFormatting = true,
composerMode = MessageComposerMode.Normal,
enableVoiceMessages = true,
)
}, {
ATextComposer(
TextEditorState.Rich(aRichTextEditorState(initialText = "A message")),
voiceMessageState = VoiceMessageState.Idle,
showTextFormatting = true,
composerMode = MessageComposerMode.Normal,
enableVoiceMessages = true,
)
}, {
PreviewColumn(
items = aTextEditorStateRichList()
) { textEditorState ->
ATextComposer(
TextEditorState.Rich(
aRichTextEditorState(
initialText = "A message\nWith several lines\nTo preview larger textfields and long lines with overflow",
)
),
state = textEditorState,
voiceMessageState = VoiceMessageState.Idle,
showTextFormatting = true,
composerMode = MessageComposerMode.Normal,
enableVoiceMessages = true,
)
}))
}
}
@PreviewsDayNight
@Composable
internal fun TextComposerEditPreview() = ElementPreview {
PreviewColumn(items = persistentListOf({
PreviewColumn(
items = aTextEditorStateRichList()
) { textEditorState ->
ATextComposer(
TextEditorState.Rich(aRichTextEditorState(initialText = "A message", initialFocus = true)),
state = textEditorState,
voiceMessageState = VoiceMessageState.Idle,
composerMode = aMessageComposerModeEdit(),
enableVoiceMessages = true,
)
}))
}
}
@PreviewsDayNight
@Composable
internal fun MarkdownTextComposerEditPreview() = ElementPreview {
PreviewColumn(items = persistentListOf({
PreviewColumn(
items = aTextEditorStateMarkdownList()
) { textEditorState ->
ATextComposer(
TextEditorState.Markdown(aMarkdownTextEditorState(initialText = "A message", initialFocus = true)),
state = textEditorState,
voiceMessageState = VoiceMessageState.Idle,
composerMode = aMessageComposerModeEdit(),
enableVoiceMessages = true,
)
}))
}
}
@PreviewsDayNight
@Composable
internal fun TextComposerReplyPreview(@PreviewParameter(InReplyToDetailsProvider::class) inReplyToDetails: InReplyToDetails) = ElementPreview {
ATextComposer(
state = TextEditorState.Rich(aRichTextEditorState()),
voiceMessageState = VoiceMessageState.Idle,
composerMode = aMessageComposerModeReply(
replyToDetails = inReplyToDetails,
),
enableVoiceMessages = true,
)
PreviewColumn(
items = aTextEditorStateRichList()
) { textEditorState ->
ATextComposer(
state = textEditorState,
voiceMessageState = VoiceMessageState.Idle,
composerMode = aMessageComposerModeReply(
replyToDetails = inReplyToDetails,
),
enableVoiceMessages = true,
)
}
}
@PreviewsDayNight
@Composable
internal fun TextComposerVoicePreview() = ElementPreview {
@Composable
fun VoicePreview(
voiceMessageState: VoiceMessageState
) = ATextComposer(
TextEditorState.Rich(aRichTextEditorState(initialFocus = true)),
voiceMessageState = voiceMessageState,
composerMode = MessageComposerMode.Normal,
enableVoiceMessages = true,
)
PreviewColumn(items = persistentListOf({
VoicePreview(voiceMessageState = VoiceMessageState.Recording(61.seconds, createFakeWaveform()))
}, {
VoicePreview(
voiceMessageState = VoiceMessageState.Preview(
PreviewColumn(
items = persistentListOf(
VoiceMessageState.Recording(61.seconds, createFakeWaveform()),
VoiceMessageState.Preview(
isSending = false,
isPlaying = false,
showCursor = false,
waveform = createFakeWaveform(),
time = 0.seconds,
playbackProgress = 0.0f
)
)
}, {
VoicePreview(
voiceMessageState = VoiceMessageState.Preview(
),
VoiceMessageState.Preview(
isSending = false,
isPlaying = true,
showCursor = true,
waveform = createFakeWaveform(),
time = 3.seconds,
playbackProgress = 0.2f
)
)
}, {
VoicePreview(
voiceMessageState = VoiceMessageState.Preview(
),
VoiceMessageState.Preview(
isSending = true,
isPlaying = false,
showCursor = false,
waveform = createFakeWaveform(),
time = 61.seconds,
playbackProgress = 0.0f
)
),
)
}))
) { voiceMessageState ->
ATextComposer(
state = aTextEditorStateRich(initialFocus = true),
voiceMessageState = voiceMessageState,
composerMode = MessageComposerMode.Normal,
enableVoiceMessages = true,
)
}
}
@Composable
private fun PreviewColumn(
items: ImmutableList<@Composable () -> Unit>,
private fun <T> PreviewColumn(
items: ImmutableList<T>,
view: @Composable (T) -> Unit,
) {
Column {
items.forEach { item ->
Box(
modifier = Modifier.height(IntrinsicSize.Min)
) {
item()
view(item)
}
}
}
@ -708,17 +680,6 @@ private fun ATextComposer( @@ -708,17 +680,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(
eventOrTransactionId: EventOrTransactionId = EventId("$1234").toEventOrTransactionId(),
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 @@ -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.textcomposer.R
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.view.models.InlineFormat
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 @@ -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.Suggestion
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.internal.applyStyleInCompose
@ -184,7 +185,7 @@ internal fun MarkdownTextInputPreview() { @@ -184,7 +185,7 @@ internal fun MarkdownTextInputPreview() {
ElementPreview {
val style = ElementRichTextEditorStyle.composerStyle(hasFocus = true)
MarkdownTextInput(
state = aMarkdownTextEditorState(),
state = aMarkdownTextEditorState(initialText = "Hello, World!"),
subcomposing = false,
onTyping = {},
onReceiveSuggestion = {},
@ -193,11 +194,3 @@ internal fun MarkdownTextInputPreview() { @@ -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 @@ @@ -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,
)
}

2
libraries/textcomposer/impl/src/test/kotlin/io/element/android/libraries/textcomposer/impl/components/markdown/MarkdownTextInputTest.kt

@ -22,13 +22,13 @@ import io.element.android.libraries.matrix.test.room.aRoomMember @@ -22,13 +22,13 @@ import io.element.android.libraries.matrix.test.room.aRoomMember
import io.element.android.libraries.testtags.TestTags
import io.element.android.libraries.textcomposer.ElementRichTextEditorStyle
import io.element.android.libraries.textcomposer.components.markdown.MarkdownTextInput
import io.element.android.libraries.textcomposer.components.markdown.aMarkdownTextEditorState
import io.element.android.libraries.textcomposer.mentions.MentionSpan
import io.element.android.libraries.textcomposer.mentions.MentionSpanProvider
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.SuggestionType
import io.element.android.libraries.textcomposer.model.aMarkdownTextEditorState
import io.element.android.tests.testutils.EnsureCalledOnceWithParam
import io.element.android.tests.testutils.EventsRecorder
import kotlinx.coroutines.test.runTest

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 @@ -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.MentionSpanProvider
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.SuggestionType
import io.element.android.libraries.textcomposer.model.aMarkdownTextEditorState
import org.junit.Test
import org.junit.runner.RunWith
@ -33,7 +33,7 @@ import org.junit.runner.RunWith @@ -33,7 +33,7 @@ import org.junit.runner.RunWith
class MarkdownTextEditorStateTest {
@Test
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 permalinkBuilder = FakePermalinkBuilder()
val mentionSpanProvider = aMentionSpanProvider()
@ -43,7 +43,7 @@ class MarkdownTextEditorStateTest { @@ -43,7 +43,7 @@ class MarkdownTextEditorStateTest {
@Test
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 = "")
}
val suggestion = aRoomAliasSuggestion()
@ -55,7 +55,7 @@ class MarkdownTextEditorStateTest { @@ -55,7 +55,7 @@ class MarkdownTextEditorStateTest {
@Test
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 = "")
}
val suggestion = aRoomAliasSuggestion()
@ -67,7 +67,7 @@ class MarkdownTextEditorStateTest { @@ -67,7 +67,7 @@ class MarkdownTextEditorStateTest {
@Test
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 mention = ResolvedSuggestion.Member(member)
val permalinkBuilder = FakePermalinkBuilder()
@ -80,7 +80,7 @@ class MarkdownTextEditorStateTest { @@ -80,7 +80,7 @@ class MarkdownTextEditorStateTest {
@Test
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 = "")
}
val member = aRoomMember()
@ -97,7 +97,7 @@ class MarkdownTextEditorStateTest { @@ -97,7 +97,7 @@ class MarkdownTextEditorStateTest {
@Test
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 = "")
}
val member = aRoomMember()
@ -115,7 +115,7 @@ class MarkdownTextEditorStateTest { @@ -115,7 +115,7 @@ class MarkdownTextEditorStateTest {
@Test
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 = "")
}
val mention = ResolvedSuggestion.AtRoom
@ -133,7 +133,7 @@ class MarkdownTextEditorStateTest { @@ -133,7 +133,7 @@ class MarkdownTextEditorStateTest {
@Test
fun `getMessageMarkdown - when there are no MentionSpans returns the same text`() {
val text = "No mentions here"
val state = MarkdownTextEditorState(initialText = text, initialFocus = true)
val state = aMarkdownTextEditorState(initialText = text, initialFocus = true)
val markdown = state.getMessageMarkdown(FakePermalinkBuilder())
@ -147,7 +147,7 @@ class MarkdownTextEditorStateTest { @@ -147,7 +147,7 @@ class MarkdownTextEditorStateTest {
permalinkForUserLambda = { 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)
val markdown = state.getMessageMarkdown(permalinkBuilder = permalinkBuilder)
@ -160,14 +160,14 @@ class MarkdownTextEditorStateTest { @@ -160,14 +160,14 @@ class MarkdownTextEditorStateTest {
@Test
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()
}
@Test
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)
val mentions = state.getMentions()

4
tests/uitests/src/test/snapshots/images/libraries.textcomposer_MarkdownTextComposerEdit_Day_0_en.png

@ -1,3 +1,3 @@ @@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:1196ef582a13714f6f33a0dc1f04996cb55e38c247585d8aa1b3804eb39d030d
size 12325
oid sha256:997f06a80f20ea48389fc05cf0abb7eb584ef02688f6eebb3e5dc0151afbaa04
size 50460

4
tests/uitests/src/test/snapshots/images/libraries.textcomposer_MarkdownTextComposerEdit_Night_0_en.png

@ -1,3 +1,3 @@ @@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:5bf752831831664d3fa3caf4877ff606956e268c69066b8c4c66062771d12eef
size 11779
oid sha256:f05e63ae7b68f0049c8c702c584ec276c0cca2d7680d9b401f652d155870717d
size 48946

4
tests/uitests/src/test/snapshots/images/libraries.textcomposer_TextComposerEdit_Day_0_en.png

@ -1,3 +1,3 @@ @@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:1196ef582a13714f6f33a0dc1f04996cb55e38c247585d8aa1b3804eb39d030d
size 12325
oid sha256:997f06a80f20ea48389fc05cf0abb7eb584ef02688f6eebb3e5dc0151afbaa04
size 50460

4
tests/uitests/src/test/snapshots/images/libraries.textcomposer_TextComposerEdit_Night_0_en.png

@ -1,3 +1,3 @@ @@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:5bf752831831664d3fa3caf4877ff606956e268c69066b8c4c66062771d12eef
size 11779
oid sha256:f05e63ae7b68f0049c8c702c584ec276c0cca2d7680d9b401f652d155870717d
size 48946

4
tests/uitests/src/test/snapshots/images/libraries.textcomposer_TextComposerFormatting_Day_0_en.png

@ -1,3 +1,3 @@ @@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:9c1096dd5654c5c6bcd274812f51fd7a278084f63cc2879c4217c3f1bd8fbaaa
size 41102
oid sha256:8a2232abaacfc851133d6c30e6c88a83304beb7a3ba594793c70dad307330c36
size 51848

4
tests/uitests/src/test/snapshots/images/libraries.textcomposer_TextComposerFormatting_Night_0_en.png

@ -1,3 +1,3 @@ @@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:afc6b93d2e4ce6bcb02c38eccb115e61f0ebd682a7c0b8037e74c20952d8ae2b
size 38429
oid sha256:c215ef11337a05564282b052d6a725f41d9e929c493fd74bc1e785f21293acbe
size 50191

4
tests/uitests/src/test/snapshots/images/libraries.textcomposer_TextComposerReply_Day_0_en.png

@ -1,3 +1,3 @@ @@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:0ba137e031bf871e7dfc4e02dde94543a2fdae300182e943f5e231a63767df21
size 19952
oid sha256:f515200dc9a53f034ad2476ede89f4c3c94cfd6fd316ee61e6fa13deb7ba6e02
size 74514

4
tests/uitests/src/test/snapshots/images/libraries.textcomposer_TextComposerReply_Day_10_en.png

@ -1,3 +1,3 @@ @@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:eec0c7c8a131d5e17833897ee777eebd7272e15ee8c664fe106bfb924617d6e4
size 15465
oid sha256:ee4c30220a64f8751bf2d51b9b09d75ab1e69bbbe4d34b63093740070e7c35c4
size 57833

4
tests/uitests/src/test/snapshots/images/libraries.textcomposer_TextComposerReply_Day_11_en.png

@ -1,3 +1,3 @@ @@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:0fe4485cd7a3194f9805e8ca3f83146ca4ef84bc8fe7b7d314908c27fc1f55e9
size 19341
oid sha256:ab63cc4ccf3082558b1571e7ee5399d3409ab8f6205f68b907c6359fdaea7be4
size 72521

4
tests/uitests/src/test/snapshots/images/libraries.textcomposer_TextComposerReply_Day_1_en.png

@ -1,3 +1,3 @@ @@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:40061abbccaf9416b767383eb7c31aa213490dddae7d5ebf0a43e160fcfaa0d4
size 22480
oid sha256:c51b345180a86b2826430c121e54aabbfad2405f6d422b7c0e1112582fa9f755
size 83966

4
tests/uitests/src/test/snapshots/images/libraries.textcomposer_TextComposerReply_Day_2_en.png

@ -1,3 +1,3 @@ @@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:8b3b984b2c549b30f18bc7ea8afae134d10b223137c98461cc99c09d8f2c7a7b
size 16288
oid sha256:f1c8e13e73696d0aa32cdf17915a6e488072db61af2349dba78e6add23c6a8e5
size 60982

4
tests/uitests/src/test/snapshots/images/libraries.textcomposer_TextComposerReply_Day_3_en.png

@ -1,3 +1,3 @@ @@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:332c75d3dfd87165edfd3c7550864424f12048b90f8fe2204e5127f23607762c
size 15862
oid sha256:0207816e0da278a25a7da9d456d664cf925ed419f8a5046a69465ffef985ff95
size 59299

4
tests/uitests/src/test/snapshots/images/libraries.textcomposer_TextComposerReply_Day_4_en.png

@ -1,3 +1,3 @@ @@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:4521f8d315cbdb95e5e3e1f34fe395e543aef52ee402b6ff0072a81cc170f37c
size 18253
oid sha256:da1e22e5b3de270fba766ff027113ce7836ffd72b1cf4de2e6cac6544086fff4
size 67786

4
tests/uitests/src/test/snapshots/images/libraries.textcomposer_TextComposerReply_Day_5_en.png

@ -1,3 +1,3 @@ @@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:7dbc2ec4e7fa64dbb8214457aac6c049a71cf438ddda9819400837e50e13fa79
size 15580
oid sha256:10510c2a67fc859d0564c6e34a7021e81f1119eaca448c5b5e928bc0a7d5a619
size 58228

4
tests/uitests/src/test/snapshots/images/libraries.textcomposer_TextComposerReply_Day_6_en.png

@ -1,3 +1,3 @@ @@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:5e956f8706aa28409214bd473953d5d21455bba28730098c8107a02ba9fe3cbc
size 15788
oid sha256:b1b7e7050bc5135b0166a752f5d3a5276348e6fa4a35cab8721a2adb324360ed
size 59040

4
tests/uitests/src/test/snapshots/images/libraries.textcomposer_TextComposerReply_Day_7_en.png

@ -1,3 +1,3 @@ @@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:631320ef054296d5bd1cbe4d2efc93fc2cf4d502e6cde6092df9fd0a53ff0cc4
size 16319
oid sha256:d7e4015c9c11b473205c611694cf2b5d52d20d49bee6cd6f61474f09a87de696
size 61191

4
tests/uitests/src/test/snapshots/images/libraries.textcomposer_TextComposerReply_Day_8_en.png

@ -1,3 +1,3 @@ @@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:d13a2471950e1fa8a1e006e5f37ad19d2046ed5b894735b13dee153e22a317d6
size 18349
oid sha256:5b274f77b1b017d7385ae1dfffb8051bb95db6372a7f32ce6838fa692c3f2562
size 68381

4
tests/uitests/src/test/snapshots/images/libraries.textcomposer_TextComposerReply_Day_9_en.png

@ -1,3 +1,3 @@ @@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:2564c5807df45b8bf1ce9557bcb49121bd34fc831affe17abd440dc53b915467
size 15666
oid sha256:fc0952625f2a7c5901a3949135c1a0a343f40b33d4192425a97245dbe6b5a04a
size 58502

4
tests/uitests/src/test/snapshots/images/libraries.textcomposer_TextComposerReply_Night_0_en.png

@ -1,3 +1,3 @@ @@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:e5bf7c115d5c0e25f325d8e8e7b01f98466c4d8fbd752882db8e8b3e2e4ea70b
size 18846
oid sha256:8b06693cde76b2ac00c31b1c767910e46dbac4f099abf17e66ceb2de87acb445
size 72106

4
tests/uitests/src/test/snapshots/images/libraries.textcomposer_TextComposerReply_Night_10_en.png

@ -1,3 +1,3 @@ @@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:82ce783813417d6da3db55ae1d4f8a6690b775c4e809c3480ca66494662921ab
size 14624
oid sha256:1fff7343bff8fe781d50732fb4e1fd7e6caf228f9520b9f639cab367db4dfd5c
size 55852

4
tests/uitests/src/test/snapshots/images/libraries.textcomposer_TextComposerReply_Night_11_en.png

@ -1,3 +1,3 @@ @@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:2dfd6f04f64d1a6a750c67b10f55f74fa423c884b8788b5e5de520bdaa7b6564
size 18446
oid sha256:08d653cdcc4c65cc1b1dbd89789cf24594e00a8f7fa2941d56fb93fda7681e4e
size 70210

4
tests/uitests/src/test/snapshots/images/libraries.textcomposer_TextComposerReply_Night_1_en.png

@ -1,3 +1,3 @@ @@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:4af010eaab0dedba3220446203abd237c7f9817df08e8458896e5e6edcef7f87
size 21295
oid sha256:01c2360b1d526713d82566794154743924fb15e1bb6e8ec250a2cc5629b5db02
size 81247

4
tests/uitests/src/test/snapshots/images/libraries.textcomposer_TextComposerReply_Night_2_en.png

@ -1,3 +1,3 @@ @@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:b094fa4d99b60bec8131d02afb0b004929120a13e9b6f56fe5ec80899db23367
size 15549
oid sha256:447b98cc3293ed3eee779cb9ffca62191b5f2d8911bc6e5912c4b23a2115b514
size 59195

4
tests/uitests/src/test/snapshots/images/libraries.textcomposer_TextComposerReply_Night_3_en.png

@ -1,3 +1,3 @@ @@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:0e556677d17885e1daa1054f19fc91a9adb2c3cce6fb386aee95e0f7f5869218
size 15137
oid sha256:862065af54f5ceaba8304d3c15f24c7021146db4e9becec859705888cdde4bae
size 57523

4
tests/uitests/src/test/snapshots/images/libraries.textcomposer_TextComposerReply_Night_4_en.png

@ -1,3 +1,3 @@ @@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:1a4c6d53fac8158b00f0b3dbf82cd355da6416eb373b3bd57b58cf0a782bc0a6
size 17374
oid sha256:a61b8ca772feebb1ccb86949b4a63080d42f2d26a29ec3ea90e47404e9ff3912
size 65950

4
tests/uitests/src/test/snapshots/images/libraries.textcomposer_TextComposerReply_Night_5_en.png

@ -1,3 +1,3 @@ @@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:5273133c6205403ade60a42e415c74aa988fcf60cf3125aa50ae10e0d3257558
size 14833
oid sha256:e75e80ffc8761b0a91f0ee3137df1987104b9a0546a6edc05d55cbc29262c313
size 56483

4
tests/uitests/src/test/snapshots/images/libraries.textcomposer_TextComposerReply_Night_6_en.png

@ -1,3 +1,3 @@ @@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:fb093750e294a6e271f743dd40e3a8acad1783c7d7b6ef3e715a78854ede40ae
size 14968
oid sha256:1ccbf26f9c3cbbba607bcb1d1a4f3701717a8d39d7c4194a393a0fb1746114c1
size 57164

4
tests/uitests/src/test/snapshots/images/libraries.textcomposer_TextComposerReply_Night_7_en.png

@ -1,3 +1,3 @@ @@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:e99bd0a813c6130c77f549c3bda2743ef5cad1b442c789796a765737ce2a52e0
size 15616
oid sha256:224bc191f6bd8761d5301039f29bebf1b3a9773ee454820cb9c64ab2d9c7b612
size 59458

4
tests/uitests/src/test/snapshots/images/libraries.textcomposer_TextComposerReply_Night_8_en.png

@ -1,3 +1,3 @@ @@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:3840ff79977e18a589db993e62575d9a81484cb712e64eef0b5df740f3255fa4
size 17459
oid sha256:c491288bfd12be3e23272f35a49beafac768bac836b43cc1bde0507ed810094e
size 66436

4
tests/uitests/src/test/snapshots/images/libraries.textcomposer_TextComposerReply_Night_9_en.png

@ -1,3 +1,3 @@ @@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:0e366992f5cefcede77af4511e1f06464fa62352f341161cf0f0e5c320dffdfd
size 14869
oid sha256:079cd865d0feb88d5746c3966f8ec0d72e40140626d5ffd6a918095e38f09fcd
size 56699

Loading…
Cancel
Save