Skip to content

Commit 23eb282

Browse files
committed
Strip whitespace between HTML tags
1 parent ff49375 commit 23eb282

File tree

4 files changed

+38
-27
lines changed

4 files changed

+38
-27
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: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,7 @@ class EditorPage : BasePage() {
296296
}
297297

298298
fun verifyHTML(expected: String): EditorPage {
299-
300-
htmlEditor.check(matches(withText(expected)))
299+
htmlEditor.check(matches(Matchers.withStrippedText(expected)))
301300
label("Verified expected editor contents")
302301

303302
return this

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

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,12 @@ class MixedTextFormattingTests : BaseTest() {
112112
@Test
113113
fun testTwoHeadings() {
114114
val text = "some text"
115-
val linebreak = "\n"
116-
val html = "<h1>$text</h1>$linebreak<h2>$text</h2>"
115+
val html = "<h1>$text</h1><h2>$text</h2>"
117116

118117
EditorPage()
119118
.makeHeader(EditorPage.HeadingStyle.ONE)
120119
.insertText(text)
121-
.insertText(linebreak)
120+
.insertText("\n")
122121
.makeHeader(EditorPage.HeadingStyle.TWO)
123122
.insertText(text)
124123
.toggleHtml()
@@ -128,13 +127,12 @@ class MixedTextFormattingTests : BaseTest() {
128127
@Test
129128
fun testEndHeadingFormatting() {
130129
val text = "some text"
131-
val linebreak = "\n"
132-
val html = "<h1>$text</h1>$linebreak$text"
130+
val html = "<h1>$text</h1>\n$text"
133131

134132
EditorPage()
135133
.makeHeader(EditorPage.HeadingStyle.ONE)
136134
.insertText(text)
137-
.insertText(linebreak)
135+
.insertText("\n")
138136
.insertText(text)
139137
.toggleHtml()
140138
.verifyHTML(html)
@@ -143,14 +141,12 @@ class MixedTextFormattingTests : BaseTest() {
143141
@Test
144142
fun testEndQuoteFormatting() {
145143
val text = "some text"
146-
val linebreak = "\n"
147-
val html = "<blockquote>$text</blockquote>$linebreak$text"
144+
val html = "<blockquote>$text</blockquote>\n$text"
148145

149146
EditorPage()
150147
.toggleQuote()
151148
.insertText(text)
152-
.insertText(linebreak)
153-
.insertText(linebreak)
149+
.insertText("\n\n")
154150
.insertText(text)
155151
.toggleHtml()
156152
.verifyHTML(html)
@@ -159,13 +155,12 @@ class MixedTextFormattingTests : BaseTest() {
159155
@Test
160156
fun testRemoveQuoteFormatting() {
161157
val text = "some text"
162-
val linebreak = "\n"
163-
val html = "<blockquote>$text</blockquote>$linebreak$text"
158+
val html = "<blockquote>$text</blockquote>\n$text"
164159

165160
EditorPage()
166161
.toggleQuote()
167162
.insertText(text)
168-
.insertText(linebreak)
163+
.insertText("\n")
169164
.insertText(text)
170165
.toggleQuote()
171166
.toggleHtml()
@@ -174,18 +169,14 @@ class MixedTextFormattingTests : BaseTest() {
174169

175170
@Test
176171
fun testQuotedListFormatting() {
177-
var text = "some text\n"
178-
val regex = Regex("<blockquote>\\s+<ul>[\\S\\s]+</ul>\\s+</blockquote>")
179-
180-
for (i in 1..3) {
181-
text += text
182-
}
172+
var text = "some text\nsome text\nsome text"
173+
val html = "<blockquote><ul><li>some text</li><li>some text</li><li>some text</li></ul></blockquote>"
183174

184175
EditorPage()
185176
.toggleQuote()
186177
.makeList(EditorPage.ListStyle.UNORDERED)
187178
.insertText(text)
188179
.toggleHtml()
189-
.verifyHTML(regex)
180+
.verifyHTML(html)
190181
}
191182
}

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

Lines changed: 2 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)

0 commit comments

Comments
 (0)