Skip to content

Commit 5e78cf1

Browse files
authored
Merge pull request #614 from wordpress-mobile/add/css-underline-ui-tests
Add UI tests for CSS underline plugin
2 parents fe41693 + 6fb1c06 commit 5e78cf1

File tree

3 files changed

+119
-0
lines changed

3 files changed

+119
-0
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,4 +156,22 @@ object Actions {
156156
}
157157
}
158158
}
159+
160+
fun setSelection(start: Int, end: Int): ViewAction {
161+
return object : ViewAction {
162+
override fun getConstraints(): Matcher<View> {
163+
return allOf(isDisplayed(), isAssignableFrom(EditText::class.java))
164+
}
165+
166+
override fun getDescription(): String {
167+
return "Set Aztec text selection to the specified range"
168+
}
169+
170+
override fun perform(uiController: UiController?, view: View?) {
171+
if (view is AztecText) {
172+
view.setSelection(start, end)
173+
}
174+
}
175+
}
176+
}
159177
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,13 @@ class EditorPage : BasePage() {
9797
return this
9898
}
9999

100+
fun selectText(start: Int, end: Int): EditorPage {
101+
editor.perform(Actions.setSelection(start, end))
102+
label("Selected text")
103+
104+
return this
105+
}
106+
100107
/**
101108
* Using selectAllText() + delete() do not work as intended. This method
102109
* will select all the text in the editor and then delete that text.
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package org.wordpress.aztec.demo.tests
2+
3+
import android.support.test.rule.ActivityTestRule
4+
import org.junit.Before
5+
import org.junit.Rule
6+
import org.junit.Test
7+
import org.wordpress.aztec.AztecText
8+
import org.wordpress.aztec.demo.BaseTest
9+
import org.wordpress.aztec.demo.MainActivity
10+
import org.wordpress.aztec.demo.R
11+
import org.wordpress.aztec.demo.pages.EditorPage
12+
import org.wordpress.aztec.plugins.CssUnderlinePlugin
13+
14+
class CssUnderlineFormattingTests : BaseTest() {
15+
16+
@Rule
17+
@JvmField
18+
var mActivityTestRule = ActivityTestRule(MainActivity::class.java)
19+
20+
@Before
21+
fun init() {
22+
val aztecText = mActivityTestRule.activity.findViewById<AztecText>(R.id.aztec)
23+
aztecText.plugins.add(CssUnderlinePlugin())
24+
}
25+
26+
@Test
27+
fun testSimpleCssUnderlineFormatting() {
28+
val text1 = "some"
29+
val text2 = "text"
30+
val html = "$text1<span style=\"text-decoration: underline\">$text2</span>"
31+
32+
EditorPage()
33+
.insertText(text1)
34+
.toggleUnderline()
35+
.insertText(text2)
36+
.toggleHtml()
37+
.verifyHTML(html)
38+
}
39+
40+
@Test
41+
fun testRegularUnderlineFormattingPreservation() {
42+
val text1 = "some"
43+
val text2 = "text"
44+
val html = "$text1<u>$text2</u>"
45+
46+
EditorPage()
47+
.toggleHtml()
48+
.insertHTML(html)
49+
.toggleHtml()
50+
.toggleHtml()
51+
.verifyHTML(html)
52+
}
53+
54+
@Test
55+
fun testTogglingUnderlineFormatting() {
56+
val text1 = "some"
57+
val text2 = "text"
58+
val html = "$text1<u>$text2</u>"
59+
val expectedHtml = "$text1<span style=\"text-decoration: underline\">$text2</span>"
60+
61+
EditorPage()
62+
.toggleHtml()
63+
.insertHTML(html)
64+
.toggleHtml()
65+
.selectText(4, 8)
66+
.toggleUnderline()
67+
.toggleHtml()
68+
.verifyHTML("$text1$text2")
69+
.toggleHtml()
70+
.selectText(4, 8)
71+
.toggleUnderline()
72+
.toggleHtml()
73+
.verifyHTML(expectedHtml)
74+
}
75+
76+
@Test
77+
fun testSimpleSplittingRegularUnderlineFormatting() {
78+
val text1 = "some"
79+
val text2 = "text"
80+
val html = "$text1<u>$text2</u>"
81+
val expectedHtml = "$text1<span style=\"text-decoration: underline\">te</span>\n\n" +
82+
"<span style=\"text-decoration: underline\">xt</span>"
83+
84+
EditorPage()
85+
.toggleHtml()
86+
.insertHTML(html)
87+
.toggleHtml()
88+
.setCursorPositionAtEnd()
89+
.moveCursorLeftAsManyTimes(2)
90+
.insertNewLine()
91+
.toggleHtml()
92+
.verifyHTML(expectedHtml)
93+
}
94+
}

0 commit comments

Comments
 (0)