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

Commit

Permalink
[Android] Add edit link tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aringenbach committed Oct 12, 2023
1 parent fd62f2d commit c511e22
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,19 @@ class RichTextEditorTest {
assertEquals("Hello, [element](<https://matrix.org>)", state.messageMarkdown)
}

@Test
fun testEditLink() = runTest {
val state = createState()
composeTestRule.showContent(state)

state.setHtml("Hello, <a href=\"https://element.io\">element</a>")
state.editLink("https://matrix.org", "matrix")
composeTestRule.awaitIdle()

assertEquals("Hello, <a href=\"https://matrix.org\">matrix</a>", state.messageHtml)
assertEquals("Hello, [matrix](<https://matrix.org>)", state.messageMarkdown)
}

@Test
fun testLinkActionUpdates() = runTest {
val state = createState()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,23 @@ class EditorEditTextInputTests {
}))
}


@Test
fun testCreatingAndEditingALink() {
onView(withId(R.id.rich_text_edit_text))
.perform(ImeActions.setComposingText("link"))
.perform(ImeActions.setSelection(0, 4))
.perform(EditorActions.setLink("https://element.io"))
.check(matches(TextViewMatcher {
it.editableText.getSpans<LinkSpan>().first().url == "https://element.io"
}))
.perform(EditorActions.editLink("matrix", "https://matrix.org"))
.check(matches(withText("matrix")))
.check(matches(TextViewMatcher {
it.editableText.getSpans<LinkSpan>().first().url == "https://matrix.org"
}))
}

@Test
fun testRemovingLink() {
onView(withId(R.id.rich_text_edit_text))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,20 @@ object Editor {
}
}

data class EditLink(
val text: String,
val url: String,
) : ViewAction {
override fun getConstraints(): Matcher<View> = isDisplayed()

override fun getDescription(): String = "Edit link with text: ($text) and url: $url"

override fun perform(uiController: UiController?, view: View?) {
val editor = view as? EditorEditText ?: return
editor.editLink(url = url, text = text)
}
}

data class InsertLink(
val text: String,
val url: String,
Expand Down Expand Up @@ -231,6 +245,7 @@ object EditorActions {
fun setText(text: String) = Editor.SetText(text)
fun setHtml(html: String) = Editor.SetHtml(html)
fun setLink(url: String) = Editor.SetLink(url)
fun editLink(text: String, url: String) = Editor.EditLink(text, url)
fun insertLink(text: String, url: String) = Editor.InsertLink(text, url)
fun removeLink() = Editor.RemoveLink
fun insertMentionAtSuggestion(text: String, url: String) = Editor.InsertMentionAtSuggestion(text, url)
Expand Down

0 comments on commit c511e22

Please sign in to comment.