Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions app/src/androidTest/kotlin/org/wordpress/aztec/demo/Matchers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,37 @@ import org.hamcrest.Matcher
import org.hamcrest.TypeSafeMatcher

object Matchers {
fun withRegex(regex: Regex): Matcher<View> {
fun withRegex(expected: Regex): Matcher<View> {

return object : TypeSafeMatcher<View>() {
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<View> {

return object : TypeSafeMatcher<View>() {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,28 @@ class ImageTests : BaseTest() {
@JvmField
val mActivityIntentsTestRule = IntentsTestRule<MainActivity>(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("<img src=.+>")

createImageIntentFilter()

EditorPage()
.tapTop()
.insertMedia()

// Must wait for simulated upload
Thread.sleep(10000)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

10s is quite a large delay. There no way to dynamically check if the upload is done?

Copy link
Contributor Author

@rachelmcr rachelmcr Nov 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was using the same general approach that was used in the previously added image tests with that sleep, but I can take another look to see what options there might be to dynamically check the upload status.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The simulated upload in the demo app takes 10s, so I'm going to leave this as-is for our Aztec tests. I'll look at a more dynamic approach for the WordPress app tests.


EditorPage()
.toggleHtml()
.verifyHTML(regex)
}

@Test
fun testAddPhotoAndText() {
var sampleText = "sample text "
val regex = Regex(".+<img src=.+>.+")

Expand Down Expand Up @@ -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 = "<img src=\"https://examplebloge.files.wordpress.com/2017/02/3def4804-d9b5-11e6-88e6-d7d8864392e0.png\">"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,104 @@ class MixedTextFormattingTests : BaseTest() {
.toggleHtml()
.verifyHTML(text)
}

@Test
fun testTwoHeadings() {
val text = "some text"
val html = "<h1>$text</h1><h2>$text</h2>"

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 = "<h1>$text</h1>\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 = "<blockquote>$text</blockquote>\n$text"

EditorPage()
.toggleQuote()
.insertText(text)
.insertText("\n\n")
.insertText(text)
.toggleHtml()
.verifyHTML(html)
}

@Test
fun testRemoveQuoteFormatting() {
val text = "some text"
val html = "<blockquote>$text</blockquote>\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 = "<blockquote><ul><li>some text</li><li>some text</li><li>some text</li></ul></blockquote>"

EditorPage()
.toggleQuote()
.makeList(EditorPage.ListStyle.UNORDERED)
.insertText(text)
.toggleHtml()
.verifyHTML(html)
}

@Test
fun testQuotedListRemoveListFormatting() {
val text = "some text\nsome text\nsome text"
val html = "<blockquote><ul><li>some text</li><li>some text</li></ul>\nsome text</blockquote>"

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 = "<ul><li>some text</li><li>some text</li><li>some text</li><li><blockquote>some text</blockquote></li></ul>"

EditorPage()
.makeList(EditorPage.ListStyle.UNORDERED)
.insertText(text1)
.toggleQuote()
.insertText(text2)
.toggleHtml()
.verifyHTML(html)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class SimpleTextFormattingTests : BaseTest() {
fun testSimpleUnorderedListFormatting() {
val text1 = "some\n"
val text2 = "text"
val html = "$text1<ul>\n\t<li>$text2</li>\n</ul>"
val html = "$text1<ul><li>$text2</li></ul>"

EditorPage()
.insertText(text1)
Expand All @@ -102,7 +102,7 @@ class SimpleTextFormattingTests : BaseTest() {
fun testSimpleOrderedListFormatting() {
val text1 = "some\n"
val text2 = "text"
val html = "$text1<ol>\n\t<li>$text2</li>\n</ol>"
val html = "$text1<ol><li>$text2</li></ol>"

EditorPage()
.insertText(text1)
Expand Down Expand Up @@ -306,6 +306,29 @@ class SimpleTextFormattingTests : BaseTest() {
.verifyHTML(expected2)
}

@Test
fun testRemoveListFormatting() {

val text = "some text\nsome text\nsome text"
val expected1 = "<ul><li>some text</li><li>some text</li><li>some text</li></ul>"
val expected2 = "<ul><li>some text</li><li>some text</li></ul>\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
Expand Down