Create fixtures for TextEditorState.
This commit is contained in:
parent
1c020bcf26
commit
26a4441d64
9 changed files with 104 additions and 68 deletions
|
|
@ -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
|
|||
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
|
||||
|
|
@ -500,7 +501,7 @@ internal fun TextComposerSimplePreview() = ElementPreview {
|
|||
items = persistentListOf(
|
||||
{
|
||||
ATextComposer(
|
||||
TextEditorState.Markdown(aMarkdownTextEditorState(initialText = "", initialFocus = true)),
|
||||
state = aTextEditorStateMarkdown(initialText = "", initialFocus = true),
|
||||
voiceMessageState = VoiceMessageState.Idle,
|
||||
composerMode = MessageComposerMode.Normal,
|
||||
enableVoiceMessages = true,
|
||||
|
|
@ -508,7 +509,7 @@ internal fun TextComposerSimplePreview() = ElementPreview {
|
|||
},
|
||||
{
|
||||
ATextComposer(
|
||||
TextEditorState.Markdown(aMarkdownTextEditorState(initialText = "A message", initialFocus = true)),
|
||||
state = aTextEditorStateMarkdown(initialText = "A message", initialFocus = true),
|
||||
voiceMessageState = VoiceMessageState.Idle,
|
||||
composerMode = MessageComposerMode.Normal,
|
||||
enableVoiceMessages = true,
|
||||
|
|
@ -516,11 +517,9 @@ internal fun TextComposerSimplePreview() = ElementPreview {
|
|||
},
|
||||
{
|
||||
ATextComposer(
|
||||
TextEditorState.Markdown(
|
||||
aMarkdownTextEditorState(
|
||||
initialText = "A message\nWith several lines\nTo preview larger textfields and long lines with overflow",
|
||||
initialFocus = true
|
||||
)
|
||||
state = aTextEditorStateMarkdown(
|
||||
initialText = "A message\nWith several lines\nTo preview larger textfields and long lines with overflow",
|
||||
initialFocus = true,
|
||||
),
|
||||
voiceMessageState = VoiceMessageState.Idle,
|
||||
composerMode = MessageComposerMode.Normal,
|
||||
|
|
@ -529,7 +528,7 @@ internal fun TextComposerSimplePreview() = ElementPreview {
|
|||
},
|
||||
{
|
||||
ATextComposer(
|
||||
TextEditorState.Markdown(aMarkdownTextEditorState(initialText = "A message without focus", initialFocus = false)),
|
||||
state = aTextEditorStateMarkdown(initialText = "A message without focus", initialFocus = false),
|
||||
voiceMessageState = VoiceMessageState.Idle,
|
||||
composerMode = MessageComposerMode.Normal,
|
||||
enableVoiceMessages = true,
|
||||
|
|
@ -544,7 +543,7 @@ internal fun TextComposerSimplePreview() = ElementPreview {
|
|||
internal fun TextComposerFormattingPreview() = ElementPreview {
|
||||
PreviewColumn(items = persistentListOf({
|
||||
ATextComposer(
|
||||
TextEditorState.Rich(aRichTextEditorState()),
|
||||
state = aTextEditorStateRich(),
|
||||
voiceMessageState = VoiceMessageState.Idle,
|
||||
showTextFormatting = true,
|
||||
composerMode = MessageComposerMode.Normal,
|
||||
|
|
@ -552,7 +551,7 @@ internal fun TextComposerFormattingPreview() = ElementPreview {
|
|||
)
|
||||
}, {
|
||||
ATextComposer(
|
||||
TextEditorState.Rich(aRichTextEditorState(initialText = "A message")),
|
||||
state = aTextEditorStateRich(initialText = "A message"),
|
||||
voiceMessageState = VoiceMessageState.Idle,
|
||||
showTextFormatting = true,
|
||||
composerMode = MessageComposerMode.Normal,
|
||||
|
|
@ -560,10 +559,8 @@ internal fun TextComposerFormattingPreview() = ElementPreview {
|
|||
)
|
||||
}, {
|
||||
ATextComposer(
|
||||
TextEditorState.Rich(
|
||||
aRichTextEditorState(
|
||||
initialText = "A message\nWith several lines\nTo preview larger textfields and long lines with overflow",
|
||||
)
|
||||
state = aTextEditorStateRich(
|
||||
initialText = "A message\nWith several lines\nTo preview larger textfields and long lines with overflow",
|
||||
),
|
||||
voiceMessageState = VoiceMessageState.Idle,
|
||||
showTextFormatting = true,
|
||||
|
|
@ -578,7 +575,7 @@ internal fun TextComposerFormattingPreview() = ElementPreview {
|
|||
internal fun TextComposerEditPreview() = ElementPreview {
|
||||
PreviewColumn(items = persistentListOf({
|
||||
ATextComposer(
|
||||
TextEditorState.Rich(aRichTextEditorState(initialText = "A message", initialFocus = true)),
|
||||
state = aTextEditorStateRich(initialText = "A message", initialFocus = true),
|
||||
voiceMessageState = VoiceMessageState.Idle,
|
||||
composerMode = aMessageComposerModeEdit(),
|
||||
enableVoiceMessages = true,
|
||||
|
|
@ -591,7 +588,7 @@ internal fun TextComposerEditPreview() = ElementPreview {
|
|||
internal fun MarkdownTextComposerEditPreview() = ElementPreview {
|
||||
PreviewColumn(items = persistentListOf({
|
||||
ATextComposer(
|
||||
TextEditorState.Markdown(aMarkdownTextEditorState(initialText = "A message", initialFocus = true)),
|
||||
state = aTextEditorStateMarkdown(initialText = "A message", initialFocus = true),
|
||||
voiceMessageState = VoiceMessageState.Idle,
|
||||
composerMode = aMessageComposerModeEdit(),
|
||||
enableVoiceMessages = true,
|
||||
|
|
@ -603,7 +600,7 @@ internal fun MarkdownTextComposerEditPreview() = ElementPreview {
|
|||
@Composable
|
||||
internal fun TextComposerReplyPreview(@PreviewParameter(InReplyToDetailsProvider::class) inReplyToDetails: InReplyToDetails) = ElementPreview {
|
||||
ATextComposer(
|
||||
state = TextEditorState.Rich(aRichTextEditorState()),
|
||||
state = aTextEditorStateRich(),
|
||||
voiceMessageState = VoiceMessageState.Idle,
|
||||
composerMode = aMessageComposerModeReply(
|
||||
replyToDetails = inReplyToDetails,
|
||||
|
|
@ -619,7 +616,7 @@ internal fun TextComposerVoicePreview() = ElementPreview {
|
|||
fun VoicePreview(
|
||||
voiceMessageState: VoiceMessageState
|
||||
) = ATextComposer(
|
||||
TextEditorState.Rich(aRichTextEditorState(initialFocus = true)),
|
||||
state = aTextEditorStateRich(initialFocus = true),
|
||||
voiceMessageState = voiceMessageState,
|
||||
composerMode = MessageComposerMode.Normal,
|
||||
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(
|
||||
eventOrTransactionId: EventOrTransactionId = EventId("$1234").toEventOrTransactionId(),
|
||||
content: String = "Some text",
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
@ -78,8 +79,8 @@ fun MarkdownTextInput(
|
|||
|
||||
AndroidView(
|
||||
modifier = Modifier
|
||||
.padding(top = 6.dp, bottom = 6.dp)
|
||||
.fillMaxWidth(),
|
||||
.padding(top = 6.dp, bottom = 6.dp)
|
||||
.fillMaxWidth(),
|
||||
factory = { context ->
|
||||
MarkdownEditText(context).apply {
|
||||
tag = TestTags.plainTextEditor.value // Needed for UI tests
|
||||
|
|
@ -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() {
|
|||
)
|
||||
}
|
||||
}
|
||||
|
||||
internal fun aMarkdownTextEditorState(
|
||||
initialText: String = "Hello, World!",
|
||||
initialFocus: Boolean = true,
|
||||
) = MarkdownTextEditorState(
|
||||
initialText = initialText,
|
||||
initialFocus = initialFocus,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue