Skip to content
This repository has been archived by the owner on Sep 27, 2024. It is now read-only.

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jmartinesp committed Nov 2, 2023
1 parent 438441d commit cc01c08
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ internal class FakeViewActionCollector(
ViewAction.Unindent -> unindent()
is ViewAction.ReplaceSuggestionText -> {
state.messageHtml = state.messageHtml.replaceLast(Regex("(@\\w+)"), value.text)
state.messageMarkdown = state.messageMarkdown.replaceLast(Regex("(@\\w+)"), value.text)
}
is ViewAction.InsertMentionAtSuggestion -> {
state.messageHtml = state.messageHtml.replaceLast(Regex("(@\\w+)"), "<a href='${value.url}'>${value.text}</a>")
state.messageMarkdown = state.messageMarkdown.replaceLast(Regex("(@\\w+)"), "[${value.text}](${value.url})")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,33 @@ class FakeRichTextEditorStateTest {
}
}

@Test
fun `replaceSuggestion updates the state`() = runTest {
moleculeFlow(RecompositionMode.Immediate) {
val state = rememberRichTextEditorState(initialHtml = "@ro", initialSelection = 2 to 2, fake = true)
remember(state.messageHtml, state.messageMarkdown) { state }
}.test {
val initialState = awaitItem()
initialState.replaceSuggestion("@room")
val nextState = awaitItem()
assertThat(nextState.messageHtml, equalTo("@room"))
}
}

@Test
fun `insertMentionAtSuggestion updates the state with a mention link`() = runTest {
val url = "https://matrix.to/#/@user:matrix.org"
moleculeFlow(RecompositionMode.Immediate) {
val state = rememberRichTextEditorState(initialHtml = "@ro", initialSelection = 2 to 2, fake = true)
remember(state.messageHtml, state.messageMarkdown) { state }
}.test {
val initialState = awaitItem()
initialState.insertMentionAtSuggestion("@room", url)
val nextState = awaitItem()
assertThat(nextState.messageHtml, equalTo("<a href='$url'>@room</a>"))
}
}

@Test
fun `requestFocus updates the state`() = runTest {
moleculeFlow(RecompositionMode.Immediate) {
Expand All @@ -276,4 +303,4 @@ class FakeRichTextEditorStateTest {
assertThat(hasFocus, equalTo(true))
}
}
}
}

0 comments on commit cc01c08

Please sign in to comment.