Skip to content

Commit 6747aa7

Browse files
authored
Merge pull request #521 from wordpress-mobile/add/high-priority-ui-tests
Add high priority and mixed formatting UI tests
2 parents e16bf94 + d77712e commit 6747aa7

File tree

5 files changed

+209
-6
lines changed

5 files changed

+209
-6
lines changed

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

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,37 @@ import org.hamcrest.Matcher
77
import org.hamcrest.TypeSafeMatcher
88

99
object Matchers {
10-
fun withRegex(regex: Regex): Matcher<View> {
10+
fun withRegex(expected: Regex): Matcher<View> {
1111

1212
return object : TypeSafeMatcher<View>() {
1313
override fun describeTo(description: Description) {
14-
description.appendText("EditText matches $regex")
14+
description.appendText("EditText matches $expected")
1515
}
1616

1717
public override fun matchesSafely(view: View): Boolean {
1818
if (view is EditText) {
19-
return view.text.toString().matches(regex)
19+
val regex = Regex(">\\s+<")
20+
val strippedText = view.text.toString().replace(regex, "><")
21+
return strippedText.matches(expected)
22+
}
23+
24+
return false
25+
}
26+
}
27+
}
28+
29+
fun withStrippedText(expected: String): Matcher<View> {
30+
31+
return object : TypeSafeMatcher<View>() {
32+
override fun describeTo(description: Description) {
33+
description.appendText("EditText matches $expected")
34+
}
35+
36+
public override fun matchesSafely(view: View): Boolean {
37+
if (view is EditText) {
38+
val regex = Regex(">\\s+<")
39+
val strippedText = view.text.toString().replace(regex, "><")
40+
return strippedText.equals(expected)
2041
}
2142

2243
return false

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ class EditorPage : BasePage() {
2626
private var editor: ViewInteraction
2727
private var htmlEditor: ViewInteraction
2828

29+
private var undoButton: ViewInteraction
30+
private var redoButton: ViewInteraction
31+
2932
private var insertMediaButton: ViewInteraction
3033
private var headingButton: ViewInteraction
3134
private var listButton: ViewInteraction
@@ -50,6 +53,9 @@ class EditorPage : BasePage() {
5053
editor = onView(withId(R.id.aztec))
5154
htmlEditor = onView(withId(R.id.source))
5255

56+
undoButton = onView(withId(R.id.undo))
57+
redoButton = onView(withId(R.id.redo))
58+
5359
insertMediaButton = onView(withId(R.id.format_bar_button_media))
5460
headingButton = onView(withId(R.id.format_bar_button_heading))
5561
listButton = onView(withId(R.id.format_bar_button_list))
@@ -145,6 +151,20 @@ class EditorPage : BasePage() {
145151
label("Chose device photos")
146152
}
147153

154+
fun undoChange(): EditorPage {
155+
undoButton.perform(Actions.invokeClick())
156+
label("Performed undo")
157+
158+
return this
159+
}
160+
161+
fun redoChange(): EditorPage {
162+
redoButton.perform(Actions.invokeClick())
163+
label("Performed redo")
164+
165+
return this
166+
}
167+
148168
fun makeHeader(style: HeadingStyle): EditorPage {
149169
headingButton.perform(betterScrollTo(), Actions.invokeClick())
150170
label("Choosing heading style")
@@ -276,7 +296,7 @@ class EditorPage : BasePage() {
276296
}
277297

278298
fun verifyHTML(expected: String): EditorPage {
279-
htmlEditor.check(matches(withText(expected)))
299+
htmlEditor.check(matches(Matchers.withStrippedText(expected)))
280300
label("Verified expected editor contents")
281301

282302
return this

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,28 @@ class ImageTests : BaseTest() {
2424
@JvmField
2525
val mActivityIntentsTestRule = IntentsTestRule<MainActivity>(MainActivity::class.java)
2626

27+
// Simple photo test, also tests the issue described in
28+
// https://github.com/wordpress-mobile/AztecEditor-Android/issues/306
2729
@Test
2830
fun testAddPhoto() {
31+
val regex = Regex("<img src=.+>")
32+
33+
createImageIntentFilter()
34+
35+
EditorPage()
36+
.tapTop()
37+
.insertMedia()
38+
39+
// Must wait for simulated upload
40+
Thread.sleep(10000)
41+
42+
EditorPage()
43+
.toggleHtml()
44+
.verifyHTML(regex)
45+
}
46+
47+
@Test
48+
fun testAddPhotoAndText() {
2949
var sampleText = "sample text "
3050
val regex = Regex(".+<img src=.+>.+")
3151

@@ -67,6 +87,25 @@ class ImageTests : BaseTest() {
6787
.verifyHTML(regex)
6888
}
6989

90+
// Tests the issue described in
91+
// https://github.com/wordpress-mobile/AztecEditor-Android/issues/299
92+
@Test
93+
fun testUndoImageUpload() {
94+
createImageIntentFilter()
95+
96+
EditorPage()
97+
.tapTop()
98+
.insertMedia()
99+
100+
// Must wait for simulated upload to start
101+
Thread.sleep(1000)
102+
103+
EditorPage()
104+
.undoChange()
105+
.toggleHtml()
106+
.verifyHTML("")
107+
}
108+
70109
private fun addPhotoWithHTML() {
71110
val imageHtml = "<img src=\"https://examplebloge.files.wordpress.com/2017/02/3def4804-d9b5-11e6-88e6-d7d8864392e0.png\">"
72111

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

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,104 @@ class MixedTextFormattingTests : BaseTest() {
110110
.toggleHtml()
111111
.verifyHTML(text)
112112
}
113+
114+
@Test
115+
fun testTwoHeadings() {
116+
val text = "some text"
117+
val html = "<h1>$text</h1><h2>$text</h2>"
118+
119+
EditorPage()
120+
.makeHeader(EditorPage.HeadingStyle.ONE)
121+
.insertText(text)
122+
.insertText("\n")
123+
.makeHeader(EditorPage.HeadingStyle.TWO)
124+
.insertText(text)
125+
.toggleHtml()
126+
.verifyHTML(html)
127+
}
128+
129+
@Test
130+
fun testEndHeadingFormatting() {
131+
val text = "some text"
132+
val html = "<h1>$text</h1>\n$text"
133+
134+
EditorPage()
135+
.makeHeader(EditorPage.HeadingStyle.ONE)
136+
.insertText(text)
137+
.insertText("\n")
138+
.insertText(text)
139+
.toggleHtml()
140+
.verifyHTML(html)
141+
}
142+
143+
@Test
144+
fun testEndQuoteFormatting() {
145+
val text = "some text"
146+
val html = "<blockquote>$text</blockquote>\n$text"
147+
148+
EditorPage()
149+
.toggleQuote()
150+
.insertText(text)
151+
.insertText("\n\n")
152+
.insertText(text)
153+
.toggleHtml()
154+
.verifyHTML(html)
155+
}
156+
157+
@Test
158+
fun testRemoveQuoteFormatting() {
159+
val text = "some text"
160+
val html = "<blockquote>$text</blockquote>\n$text"
161+
162+
EditorPage()
163+
.toggleQuote()
164+
.insertText(text)
165+
.insertText("\n")
166+
.insertText(text)
167+
.toggleQuote()
168+
.toggleHtml()
169+
.verifyHTML(html)
170+
}
171+
172+
@Test
173+
fun testQuotedListFormatting() {
174+
val text = "some text\nsome text\nsome text"
175+
val html = "<blockquote><ul><li>some text</li><li>some text</li><li>some text</li></ul></blockquote>"
176+
177+
EditorPage()
178+
.toggleQuote()
179+
.makeList(EditorPage.ListStyle.UNORDERED)
180+
.insertText(text)
181+
.toggleHtml()
182+
.verifyHTML(html)
183+
}
184+
185+
@Test
186+
fun testQuotedListRemoveListFormatting() {
187+
val text = "some text\nsome text\nsome text"
188+
val html = "<blockquote><ul><li>some text</li><li>some text</li></ul>\nsome text</blockquote>"
189+
190+
EditorPage()
191+
.toggleQuote()
192+
.makeList(EditorPage.ListStyle.UNORDERED)
193+
.insertText(text)
194+
.makeList(EditorPage.ListStyle.UNORDERED)
195+
.toggleHtml()
196+
.verifyHTML(html)
197+
}
198+
199+
@Test
200+
fun testListwithQuoteFormatting() {
201+
val text1 = "some text\nsome text\nsome text\n"
202+
val text2 = "some text"
203+
val html = "<ul><li>some text</li><li>some text</li><li>some text</li><li><blockquote>some text</blockquote></li></ul>"
204+
205+
EditorPage()
206+
.makeList(EditorPage.ListStyle.UNORDERED)
207+
.insertText(text1)
208+
.toggleQuote()
209+
.insertText(text2)
210+
.toggleHtml()
211+
.verifyHTML(html)
212+
}
113213
}

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

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class SimpleTextFormattingTests : BaseTest() {
8888
fun testSimpleUnorderedListFormatting() {
8989
val text1 = "some\n"
9090
val text2 = "text"
91-
val html = "$text1<ul>\n\t<li>$text2</li>\n</ul>"
91+
val html = "$text1<ul><li>$text2</li></ul>"
9292

9393
EditorPage()
9494
.insertText(text1)
@@ -102,7 +102,7 @@ class SimpleTextFormattingTests : BaseTest() {
102102
fun testSimpleOrderedListFormatting() {
103103
val text1 = "some\n"
104104
val text2 = "text"
105-
val html = "$text1<ol>\n\t<li>$text2</li>\n</ol>"
105+
val html = "$text1<ol><li>$text2</li></ol>"
106106

107107
EditorPage()
108108
.insertText(text1)
@@ -306,6 +306,29 @@ class SimpleTextFormattingTests : BaseTest() {
306306
.verifyHTML(expected2)
307307
}
308308

309+
@Test
310+
fun testRemoveListFormatting() {
311+
312+
val text = "some text\nsome text\nsome text"
313+
val expected1 = "<ul><li>some text</li><li>some text</li><li>some text</li></ul>"
314+
val expected2 = "<ul><li>some text</li><li>some text</li></ul>\nsome text"
315+
316+
EditorPage()
317+
.makeList(EditorPage.ListStyle.UNORDERED)
318+
.insertText(text)
319+
.toggleHtml()
320+
.verifyHTML(expected1)
321+
.toggleHtml()
322+
.makeList(EditorPage.ListStyle.UNORDERED)
323+
.toggleHtml()
324+
.verifyHTML(expected2)
325+
.toggleHtml()
326+
.selectAllText()
327+
.makeList(EditorPage.ListStyle.UNORDERED)
328+
.toggleHtml()
329+
.verifyHTML(text)
330+
}
331+
309332
// Test reproducing the issue described in
310333
// https://github.com/wordpress-mobile/AztecEditor-Android/pull/466#issuecomment-322404363
311334
@Test

0 commit comments

Comments
 (0)