Skip to content

Commit 69b04a3

Browse files
committed
Shamelessly copied from wpandroid PR #682
1 parent 2c909e7 commit 69b04a3

File tree

3 files changed

+57
-15
lines changed

3 files changed

+57
-15
lines changed

app/src/androidTest/kotlin/org/wordpress/aztec/demo/Matchers.kt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import android.widget.EditText
55
import org.hamcrest.Description
66
import org.hamcrest.Matcher
77
import org.hamcrest.TypeSafeMatcher
8+
import org.wordpress.aztec.AztecText
89
import org.wordpress.aztec.source.Format
10+
import org.wordpress.aztec.source.SourceViewEditText
911

1012
object Matchers {
1113
fun withRegex(expected: Regex): Matcher<View> {
@@ -45,4 +47,23 @@ object Matchers {
4547
}
4648
}
4749
}
50+
51+
fun hasContentChanges(shouldHaveChanges: AztecText.EditorHasChanges): TypeSafeMatcher<View> {
52+
53+
return object : TypeSafeMatcher<View>() {
54+
override fun describeTo(description: Description) {
55+
description.appendText("User has made changes to the post: $shouldHaveChanges")
56+
}
57+
58+
public override fun matchesSafely(view: View): Boolean {
59+
if (view is SourceViewEditText) {
60+
return view.hasChanges() == shouldHaveChanges
61+
}
62+
if (view is AztecText) {
63+
return view.hasChanges() == shouldHaveChanges
64+
}
65+
return false
66+
}
67+
}
68+
}
4869
}

app/src/androidTest/kotlin/org/wordpress/aztec/demo/pages/EditorPage.kt

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -371,21 +371,12 @@ class EditorPage : BasePage() {
371371
}
372372

373373
fun hasChanges(shouldHaveChanges : AztecText.EditorHasChanges): EditorPage {
374-
val hasNoChangesMatcher = object : TypeSafeMatcher<View>() {
375-
override fun describeTo(description: Description) {
376-
description.appendText("User has made changes to the post: $shouldHaveChanges")
377-
}
378-
379-
public override fun matchesSafely(view: View): Boolean {
380-
if (view is AztecText) {
381-
return view.hasChanges() == shouldHaveChanges
382-
}
383-
384-
return false
385-
}
386-
}
374+
editor.check(matches(Matchers.hasContentChanges(shouldHaveChanges)))
375+
return this
376+
}
387377

388-
editor.check(matches(hasNoChangesMatcher))
378+
fun hasChangesHTML(shouldHaveChanges : AztecText.EditorHasChanges): EditorPage {
379+
htmlEditor.check(matches(Matchers.hasContentChanges(shouldHaveChanges)))
389380
return this
390381
}
391382

app/src/androidTest/kotlin/org/wordpress/aztec/demo/tests/MixedTextFormattingTests.kt

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,6 @@ class MixedTextFormattingTests : BaseTest() {
254254
.hasChanges(AztecText.EditorHasChanges.NO_CHANGES) // Verify that the user had not changed the input
255255
}
256256

257-
@Ignore("Until this issue is fixed: https://github.com/wordpress-mobile/AztecEditor-Android/issues/698")
258257
@Test
259258
fun testHasChangesWithMixedBoldAndItalicFormatting() {
260259
val input = "<b>bold <i>italic</i> bold</b>"
@@ -271,4 +270,35 @@ class MixedTextFormattingTests : BaseTest() {
271270
.hasChanges(AztecText.EditorHasChanges.CHANGES)
272271
.verifyHTML(afterParser)
273272
}
273+
274+
@Test
275+
fun testHasChangesOnHTMLEditor() {
276+
val input = "<b>Test</b>"
277+
val insertedText = " text added"
278+
val afterParser = "<b>Test</b>$insertedText"
279+
280+
EditorPage().toggleHtml()
281+
.insertHTML(input)
282+
.toggleHtml()
283+
.toggleHtml() // switch back to HTML editor
284+
.insertHTML(insertedText)
285+
.hasChangesHTML(AztecText.EditorHasChanges.CHANGES)
286+
.verifyHTML(afterParser)
287+
}
288+
289+
@Test
290+
fun testHasChangesOnHTMLEditorTestedFromVisualEditor() {
291+
val input = "<b>Test</b>"
292+
val insertedText = " text added"
293+
val afterParser = "Test$insertedText"
294+
295+
EditorPage().toggleHtml()
296+
.insertHTML(input)
297+
.toggleHtml()
298+
.toggleHtml() // switch back to HTML editor
299+
.insertHTML(insertedText)
300+
.hasChangesHTML(AztecText.EditorHasChanges.CHANGES)
301+
.toggleHtml() // switch back to Visual editor
302+
.verify(afterParser)
303+
}
274304
}

0 commit comments

Comments
 (0)