From ff4937500946c8d8ae045b8aaac082336c6eb4a1 Mon Sep 17 00:00:00 2001 From: rachelmcr Date: Fri, 10 Nov 2017 12:45:41 +0000 Subject: [PATCH 1/3] Add high priority and mixed formatting UI tests --- .../wordpress/aztec/demo/pages/EditorPage.kt | 21 +++++ .../wordpress/aztec/demo/tests/ImageTests.kt | 39 +++++++++ .../demo/tests/MixedTextFormattingTests.kt | 80 +++++++++++++++++++ 3 files changed, 140 insertions(+) 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..9b168cc01 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,6 +296,7 @@ class EditorPage : BasePage() { } fun verifyHTML(expected: String): EditorPage { + htmlEditor.check(matches(withText(expected))) label("Verified expected editor contents") 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..b6fadf21a 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,84 @@ class MixedTextFormattingTests : BaseTest() { .toggleHtml() .verifyHTML(text) } + + @Test + fun testTwoHeadings() { + val text = "some text" + val linebreak = "\n" + val html = "

$text

$linebreak

$text

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

$text

$linebreak$text" + + EditorPage() + .makeHeader(EditorPage.HeadingStyle.ONE) + .insertText(text) + .insertText(linebreak) + .insertText(text) + .toggleHtml() + .verifyHTML(html) + } + + @Test + fun testEndQuoteFormatting() { + val text = "some text" + val linebreak = "\n" + val html = "
$text
$linebreak$text" + + EditorPage() + .toggleQuote() + .insertText(text) + .insertText(linebreak) + .insertText(linebreak) + .insertText(text) + .toggleHtml() + .verifyHTML(html) + } + + @Test + fun testRemoveQuoteFormatting() { + val text = "some text" + val linebreak = "\n" + val html = "
$text
$linebreak$text" + + EditorPage() + .toggleQuote() + .insertText(text) + .insertText(linebreak) + .insertText(text) + .toggleQuote() + .toggleHtml() + .verifyHTML(html) + } + + @Test + fun testQuotedListFormatting() { + var text = "some text\n" + val regex = Regex("
\\s+
    [\\S\\s]+
\\s+
") + + for (i in 1..3) { + text += text + } + + EditorPage() + .toggleQuote() + .makeList(EditorPage.ListStyle.UNORDERED) + .insertText(text) + .toggleHtml() + .verifyHTML(regex) + } } From 23eb282f0375b909e0ba2899e4d9d207d8f7f9ca Mon Sep 17 00:00:00 2001 From: rachelmcr Date: Wed, 15 Nov 2017 12:57:36 +0000 Subject: [PATCH 2/3] Strip whitespace between HTML tags --- .../org/wordpress/aztec/demo/Matchers.kt | 27 ++++++++++++++-- .../wordpress/aztec/demo/pages/EditorPage.kt | 3 +- .../demo/tests/MixedTextFormattingTests.kt | 31 +++++++------------ .../demo/tests/SimpleTextFormattingTests.kt | 4 +-- 4 files changed, 38 insertions(+), 27 deletions(-) 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 9b168cc01..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 @@ -296,8 +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/MixedTextFormattingTests.kt b/app/src/androidTest/kotlin/org/wordpress/aztec/demo/tests/MixedTextFormattingTests.kt index b6fadf21a..71ae6be12 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 @@ -112,13 +112,12 @@ class MixedTextFormattingTests : BaseTest() { @Test fun testTwoHeadings() { val text = "some text" - val linebreak = "\n" - val html = "

$text

$linebreak

$text

" + val html = "

$text

$text

" EditorPage() .makeHeader(EditorPage.HeadingStyle.ONE) .insertText(text) - .insertText(linebreak) + .insertText("\n") .makeHeader(EditorPage.HeadingStyle.TWO) .insertText(text) .toggleHtml() @@ -128,13 +127,12 @@ class MixedTextFormattingTests : BaseTest() { @Test fun testEndHeadingFormatting() { val text = "some text" - val linebreak = "\n" - val html = "

$text

$linebreak$text" + val html = "

$text

\n$text" EditorPage() .makeHeader(EditorPage.HeadingStyle.ONE) .insertText(text) - .insertText(linebreak) + .insertText("\n") .insertText(text) .toggleHtml() .verifyHTML(html) @@ -143,14 +141,12 @@ class MixedTextFormattingTests : BaseTest() { @Test fun testEndQuoteFormatting() { val text = "some text" - val linebreak = "\n" - val html = "
$text
$linebreak$text" + val html = "
$text
\n$text" EditorPage() .toggleQuote() .insertText(text) - .insertText(linebreak) - .insertText(linebreak) + .insertText("\n\n") .insertText(text) .toggleHtml() .verifyHTML(html) @@ -159,13 +155,12 @@ class MixedTextFormattingTests : BaseTest() { @Test fun testRemoveQuoteFormatting() { val text = "some text" - val linebreak = "\n" - val html = "
$text
$linebreak$text" + val html = "
$text
\n$text" EditorPage() .toggleQuote() .insertText(text) - .insertText(linebreak) + .insertText("\n") .insertText(text) .toggleQuote() .toggleHtml() @@ -174,18 +169,14 @@ class MixedTextFormattingTests : BaseTest() { @Test fun testQuotedListFormatting() { - var text = "some text\n" - val regex = Regex("
\\s+
    [\\S\\s]+
\\s+
") - - for (i in 1..3) { - text += text - } + var 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(regex) + .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..0f13fb121 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) From d77712e9cf582723f9826a148d9f995d6367fac9 Mon Sep 17 00:00:00 2001 From: rachelmcr Date: Wed, 15 Nov 2017 18:41:16 +0000 Subject: [PATCH 3/3] Add quote and list tests --- .../demo/tests/MixedTextFormattingTests.kt | 31 ++++++++++++++++++- .../demo/tests/SimpleTextFormattingTests.kt | 23 ++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) 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 71ae6be12..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 @@ -169,7 +169,7 @@ class MixedTextFormattingTests : BaseTest() { @Test fun testQuotedListFormatting() { - var text = "some text\nsome text\nsome text" + val text = "some text\nsome text\nsome text" val html = "
  • some text
  • some text
  • some text
" EditorPage() @@ -179,4 +179,33 @@ class MixedTextFormattingTests : BaseTest() { .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 0f13fb121..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 @@ -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