diff --git a/app/src/androidTest/kotlin/org/wordpress/aztec/demo/Matchers.kt b/app/src/androidTest/kotlin/org/wordpress/aztec/demo/Matchers.kt index 71bfc1759..7d7f3500a 100644 --- a/app/src/androidTest/kotlin/org/wordpress/aztec/demo/Matchers.kt +++ b/app/src/androidTest/kotlin/org/wordpress/aztec/demo/Matchers.kt @@ -7,16 +7,37 @@ import org.hamcrest.Matcher import org.hamcrest.TypeSafeMatcher object Matchers { - fun withRegex(regex: Regex): Matcher { + fun withRegex(expected: Regex): Matcher { return object : TypeSafeMatcher() { override fun describeTo(description: Description) { - description.appendText("EditText matches $regex") + description.appendText("EditText matches $expected") } public override fun matchesSafely(view: View): Boolean { if (view is EditText) { - return view.text.toString().matches(regex) + val regex = Regex(">\\s+<") + val strippedText = view.text.toString().replace(regex, "><") + return strippedText.matches(expected) + } + + return false + } + } + } + + fun withStrippedText(expected: String): Matcher { + + return object : TypeSafeMatcher() { + override fun describeTo(description: Description) { + description.appendText("EditText matches $expected") + } + + public override fun matchesSafely(view: View): Boolean { + if (view is EditText) { + val regex = Regex(">\\s+<") + val strippedText = view.text.toString().replace(regex, "><") + return strippedText.equals(expected) } return false diff --git a/app/src/androidTest/kotlin/org/wordpress/aztec/demo/pages/EditorPage.kt b/app/src/androidTest/kotlin/org/wordpress/aztec/demo/pages/EditorPage.kt index 7db8cd579..a40c687ff 100644 --- a/app/src/androidTest/kotlin/org/wordpress/aztec/demo/pages/EditorPage.kt +++ b/app/src/androidTest/kotlin/org/wordpress/aztec/demo/pages/EditorPage.kt @@ -26,6 +26,9 @@ class EditorPage : BasePage() { private var editor: ViewInteraction private var htmlEditor: ViewInteraction + private var undoButton: ViewInteraction + private var redoButton: ViewInteraction + private var insertMediaButton: ViewInteraction private var headingButton: ViewInteraction private var listButton: ViewInteraction @@ -50,6 +53,9 @@ class EditorPage : BasePage() { editor = onView(withId(R.id.aztec)) htmlEditor = onView(withId(R.id.source)) + undoButton = onView(withId(R.id.undo)) + redoButton = onView(withId(R.id.redo)) + insertMediaButton = onView(withId(R.id.format_bar_button_media)) headingButton = onView(withId(R.id.format_bar_button_heading)) listButton = onView(withId(R.id.format_bar_button_list)) @@ -145,6 +151,20 @@ class EditorPage : BasePage() { label("Chose device photos") } + fun undoChange(): EditorPage { + undoButton.perform(Actions.invokeClick()) + label("Performed undo") + + return this + } + + fun redoChange(): EditorPage { + redoButton.perform(Actions.invokeClick()) + label("Performed redo") + + return this + } + fun makeHeader(style: HeadingStyle): EditorPage { headingButton.perform(betterScrollTo(), Actions.invokeClick()) label("Choosing heading style") @@ -276,7 +296,7 @@ class EditorPage : BasePage() { } fun verifyHTML(expected: String): EditorPage { - htmlEditor.check(matches(withText(expected))) + htmlEditor.check(matches(Matchers.withStrippedText(expected))) label("Verified expected editor contents") return this diff --git a/app/src/androidTest/kotlin/org/wordpress/aztec/demo/tests/ImageTests.kt b/app/src/androidTest/kotlin/org/wordpress/aztec/demo/tests/ImageTests.kt index 3bd5f899d..525ed0d8d 100644 --- a/app/src/androidTest/kotlin/org/wordpress/aztec/demo/tests/ImageTests.kt +++ b/app/src/androidTest/kotlin/org/wordpress/aztec/demo/tests/ImageTests.kt @@ -24,8 +24,28 @@ class ImageTests : BaseTest() { @JvmField val mActivityIntentsTestRule = IntentsTestRule(MainActivity::class.java) + // Simple photo test, also tests the issue described in + // https://github.com/wordpress-mobile/AztecEditor-Android/issues/306 @Test fun testAddPhoto() { + val regex = Regex("") + + createImageIntentFilter() + + EditorPage() + .tapTop() + .insertMedia() + + // Must wait for simulated upload + Thread.sleep(10000) + + EditorPage() + .toggleHtml() + .verifyHTML(regex) + } + + @Test + fun testAddPhotoAndText() { var sampleText = "sample text " val regex = Regex(".+.+") @@ -67,6 +87,25 @@ class ImageTests : BaseTest() { .verifyHTML(regex) } + // Tests the issue described in + // https://github.com/wordpress-mobile/AztecEditor-Android/issues/299 + @Test + fun testUndoImageUpload() { + createImageIntentFilter() + + EditorPage() + .tapTop() + .insertMedia() + + // Must wait for simulated upload to start + Thread.sleep(1000) + + EditorPage() + .undoChange() + .toggleHtml() + .verifyHTML("") + } + private fun addPhotoWithHTML() { val imageHtml = "" diff --git a/app/src/androidTest/kotlin/org/wordpress/aztec/demo/tests/MixedTextFormattingTests.kt b/app/src/androidTest/kotlin/org/wordpress/aztec/demo/tests/MixedTextFormattingTests.kt index 157cbaf3e..9fcb73533 100644 --- a/app/src/androidTest/kotlin/org/wordpress/aztec/demo/tests/MixedTextFormattingTests.kt +++ b/app/src/androidTest/kotlin/org/wordpress/aztec/demo/tests/MixedTextFormattingTests.kt @@ -108,4 +108,104 @@ class MixedTextFormattingTests : BaseTest() { .toggleHtml() .verifyHTML(text) } + + @Test + fun testTwoHeadings() { + val text = "some text" + val html = "

$text

$text

" + + EditorPage() + .makeHeader(EditorPage.HeadingStyle.ONE) + .insertText(text) + .insertText("\n") + .makeHeader(EditorPage.HeadingStyle.TWO) + .insertText(text) + .toggleHtml() + .verifyHTML(html) + } + + @Test + fun testEndHeadingFormatting() { + val text = "some text" + val html = "

$text

\n$text" + + EditorPage() + .makeHeader(EditorPage.HeadingStyle.ONE) + .insertText(text) + .insertText("\n") + .insertText(text) + .toggleHtml() + .verifyHTML(html) + } + + @Test + fun testEndQuoteFormatting() { + val text = "some text" + val html = "
$text
\n$text" + + EditorPage() + .toggleQuote() + .insertText(text) + .insertText("\n\n") + .insertText(text) + .toggleHtml() + .verifyHTML(html) + } + + @Test + fun testRemoveQuoteFormatting() { + val text = "some text" + val html = "
$text
\n$text" + + EditorPage() + .toggleQuote() + .insertText(text) + .insertText("\n") + .insertText(text) + .toggleQuote() + .toggleHtml() + .verifyHTML(html) + } + + @Test + fun testQuotedListFormatting() { + val text = "some text\nsome text\nsome text" + val html = "
  • some text
  • some text
  • some text
" + + EditorPage() + .toggleQuote() + .makeList(EditorPage.ListStyle.UNORDERED) + .insertText(text) + .toggleHtml() + .verifyHTML(html) + } + + @Test + fun testQuotedListRemoveListFormatting() { + val text = "some text\nsome text\nsome text" + val html = "
  • some text
  • some text
\nsome text
" + + EditorPage() + .toggleQuote() + .makeList(EditorPage.ListStyle.UNORDERED) + .insertText(text) + .makeList(EditorPage.ListStyle.UNORDERED) + .toggleHtml() + .verifyHTML(html) + } + + @Test + fun testListwithQuoteFormatting() { + val text1 = "some text\nsome text\nsome text\n" + val text2 = "some text" + val html = "
  • some text
  • some text
  • some text
  • some text
" + + EditorPage() + .makeList(EditorPage.ListStyle.UNORDERED) + .insertText(text1) + .toggleQuote() + .insertText(text2) + .toggleHtml() + .verifyHTML(html) + } } diff --git a/app/src/androidTest/kotlin/org/wordpress/aztec/demo/tests/SimpleTextFormattingTests.kt b/app/src/androidTest/kotlin/org/wordpress/aztec/demo/tests/SimpleTextFormattingTests.kt index 92df6d871..06310e3f0 100644 --- a/app/src/androidTest/kotlin/org/wordpress/aztec/demo/tests/SimpleTextFormattingTests.kt +++ b/app/src/androidTest/kotlin/org/wordpress/aztec/demo/tests/SimpleTextFormattingTests.kt @@ -88,7 +88,7 @@ class SimpleTextFormattingTests : BaseTest() { fun testSimpleUnorderedListFormatting() { val text1 = "some\n" val text2 = "text" - val html = "$text1
    \n\t
  • $text2
  • \n
" + val html = "$text1
  • $text2
" EditorPage() .insertText(text1) @@ -102,7 +102,7 @@ class SimpleTextFormattingTests : BaseTest() { fun testSimpleOrderedListFormatting() { val text1 = "some\n" val text2 = "text" - val html = "$text1
    \n\t
  1. $text2
  2. \n
" + val html = "$text1
  1. $text2
" EditorPage() .insertText(text1) @@ -306,6 +306,29 @@ class SimpleTextFormattingTests : BaseTest() { .verifyHTML(expected2) } + @Test + fun testRemoveListFormatting() { + + val text = "some text\nsome text\nsome text" + val expected1 = "
  • some text
  • some text
  • some text
" + val expected2 = "
  • some text
  • some text
\nsome text" + + EditorPage() + .makeList(EditorPage.ListStyle.UNORDERED) + .insertText(text) + .toggleHtml() + .verifyHTML(expected1) + .toggleHtml() + .makeList(EditorPage.ListStyle.UNORDERED) + .toggleHtml() + .verifyHTML(expected2) + .toggleHtml() + .selectAllText() + .makeList(EditorPage.ListStyle.UNORDERED) + .toggleHtml() + .verifyHTML(text) + } + // Test reproducing the issue described in // https://github.com/wordpress-mobile/AztecEditor-Android/pull/466#issuecomment-322404363 @Test