From c809b43c9fd840168aea91189146ce3c62447e6a Mon Sep 17 00:00:00 2001 From: jonnyandrew Date: Thu, 16 Nov 2023 10:43:59 +0000 Subject: [PATCH] [Android] Test composable selection state restoration (#868) --- .../wysiwyg/compose/RichTextEditorStateTest.kt | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/platforms/android/library-compose/src/androidTest/java/io/element/android/wysiwyg/compose/RichTextEditorStateTest.kt b/platforms/android/library-compose/src/androidTest/java/io/element/android/wysiwyg/compose/RichTextEditorStateTest.kt index fd567683d..ad32c772f 100644 --- a/platforms/android/library-compose/src/androidTest/java/io/element/android/wysiwyg/compose/RichTextEditorStateTest.kt +++ b/platforms/android/library-compose/src/androidTest/java/io/element/android/wysiwyg/compose/RichTextEditorStateTest.kt @@ -15,8 +15,10 @@ import androidx.test.espresso.assertion.ViewAssertions.matches import androidx.test.espresso.matcher.ViewMatchers.isDisplayed import androidx.test.espresso.matcher.ViewMatchers.withText import io.element.android.wysiwyg.utils.NBSP +import io.element.android.wysiwyg.view.models.InlineFormat import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.test.runTest +import org.junit.Assert.assertEquals import org.junit.Assert import org.junit.Rule import org.junit.Test @@ -44,17 +46,24 @@ class RichTextEditorStateTest { } } - state.setHtml("Hello, world") + state.setHtml("Hello,
world") + state.setSelection(0, 5) composeTestRule.awaitIdle() composeTestRule.onNodeWithText("Main editor").assertIsDisplayed() - onView(withText("Hello, world")).check(matches(isDisplayed())) + onView(withText("Hello,\nworld")).check(matches(isDisplayed())) showAlternateEditor.emit(true) composeTestRule.awaitIdle() composeTestRule.onNodeWithText("Alternative editor").assertIsDisplayed() - onView(withText("Hello, world")).check(matches(isDisplayed())) + onView(withText("Hello,\nworld")).check(matches(isDisplayed())) + assertEquals(2, state.lineCount) + + state.toggleInlineFormat(InlineFormat.Bold) + composeTestRule.awaitIdle() + + assertEquals("Hello,
world", state.messageHtml) } @Test