Skip to content

Commit 3ca2d85

Browse files
committed
Add simple formatting tests
1 parent 92e7a84 commit 3ca2d85

File tree

2 files changed

+281
-21
lines changed

2 files changed

+281
-21
lines changed
Lines changed: 241 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,46 @@
11
package org.wordpress.aztec.demo;
22

3-
import android.support.test.espresso.ViewInteraction;
43
import android.support.test.rule.ActivityTestRule;
54
import android.support.test.runner.AndroidJUnit4;
65
import android.test.suitebuilder.annotation.LargeTest;
6+
77
import org.junit.Rule;
88
import org.junit.Test;
99
import org.junit.runner.RunWith;
1010

11-
import static android.support.test.espresso.Espresso.onView;
11+
import static android.support.test.espresso.action.ViewActions.click;
12+
import static android.support.test.espresso.action.ViewActions.scrollTo;
13+
import static android.support.test.espresso.action.ViewActions.typeText;
14+
import static android.support.test.espresso.action.ViewActions.typeTextIntoFocusedView;
1215
import static android.support.test.espresso.assertion.ViewAssertions.matches;
13-
import static android.support.test.espresso.matcher.ViewMatchers.isChecked;
14-
import static android.support.test.espresso.matcher.ViewMatchers.isNotChecked;
15-
import static android.support.test.espresso.matcher.ViewMatchers.withId;
16-
import static org.wordpress.aztec.demo.TestUtils.enterHTML;
16+
import static android.support.test.espresso.matcher.ViewMatchers.withText;
17+
import static org.wordpress.aztec.demo.TestUtils.aztecText;
18+
import static org.wordpress.aztec.demo.TestUtils.boldButton;
19+
import static org.wordpress.aztec.demo.TestUtils.formattedText;
20+
import static org.wordpress.aztec.demo.TestUtils.headingButton;
21+
import static org.wordpress.aztec.demo.TestUtils.headingFiveSelector;
22+
import static org.wordpress.aztec.demo.TestUtils.headingFourSelector;
23+
import static org.wordpress.aztec.demo.TestUtils.headingOneSelector;
24+
import static org.wordpress.aztec.demo.TestUtils.headingSixSelector;
25+
import static org.wordpress.aztec.demo.TestUtils.headingThreeSelector;
26+
import static org.wordpress.aztec.demo.TestUtils.headingTwoSelector;
27+
import static org.wordpress.aztec.demo.TestUtils.italicButton;
28+
import static org.wordpress.aztec.demo.TestUtils.linkButton;
29+
import static org.wordpress.aztec.demo.TestUtils.linkOKButton;
30+
import static org.wordpress.aztec.demo.TestUtils.linkTextField;
31+
import static org.wordpress.aztec.demo.TestUtils.linkURLField;
32+
import static org.wordpress.aztec.demo.TestUtils.linkURLText;
33+
import static org.wordpress.aztec.demo.TestUtils.moreButton;
34+
import static org.wordpress.aztec.demo.TestUtils.orderedListButton;
35+
import static org.wordpress.aztec.demo.TestUtils.pageButton;
36+
import static org.wordpress.aztec.demo.TestUtils.preSelector;
37+
import static org.wordpress.aztec.demo.TestUtils.quoteButton;
38+
import static org.wordpress.aztec.demo.TestUtils.sourceText;
39+
import static org.wordpress.aztec.demo.TestUtils.strikethroughButton;
40+
import static org.wordpress.aztec.demo.TestUtils.toggleHTMLView;
41+
import static org.wordpress.aztec.demo.TestUtils.underlineButton;
42+
import static org.wordpress.aztec.demo.TestUtils.unformattedText;
43+
import static org.wordpress.aztec.demo.TestUtils.unorderedListButton;
1744

1845
@LargeTest
1946
@RunWith(AndroidJUnit4.class)
@@ -24,11 +51,214 @@ public class SimpleTextFormattingTests {
2451

2552
@Test
2653
public void testSimpleBoldFormatting() {
27-
ViewInteraction boldButton = onView(withId(R.id.format_bar_button_bold));
28-
boldButton.check(matches(isNotChecked()));
54+
// Enter text in visual editor with formatting
55+
aztecText.perform(typeText(unformattedText));
56+
boldButton.perform(click());
57+
aztecText.perform(typeText(formattedText));
58+
59+
// Check that HTML formatting tags were correctly added
60+
toggleHTMLView();
61+
sourceText.check(matches(withText(unformattedText + "<b>" + formattedText + "</b>")));
62+
}
63+
64+
@Test
65+
public void testSimpleItalicFormatting() {
66+
// Enter text in visual editor with formatting
67+
aztecText.perform(typeText(unformattedText));
68+
italicButton.perform(click());
69+
aztecText.perform(typeText(formattedText));
70+
71+
// Check that HTML formatting tags were correctly added
72+
toggleHTMLView();
73+
sourceText.check(matches(withText(unformattedText + "<i>" + formattedText + "</i>")));
74+
}
75+
76+
@Test
77+
public void testSimpleStrikethroughFormatting() {
78+
// Enter text in visual editor with formatting
79+
aztecText.perform(typeText(unformattedText));
80+
strikethroughButton.perform(click());
81+
aztecText.perform(typeText(formattedText));
82+
83+
// Check that HTML formatting tags were correctly added
84+
toggleHTMLView();
85+
sourceText.check(matches(withText(unformattedText + "<del>" + formattedText + "</del>")));
86+
}
87+
88+
@Test
89+
public void testSimpleUnderlineFormatting() {
90+
// Enter text in visual editor with formatting
91+
aztecText.perform(typeText(unformattedText));
92+
underlineButton.perform(click());
93+
aztecText.perform(typeText(formattedText));
94+
95+
// Check that HTML formatting tags were correctly added
96+
toggleHTMLView();
97+
sourceText.check(matches(withText(unformattedText + "<u>" + formattedText + "</u>")));
98+
}
99+
100+
@Test
101+
public void testSimpleQuoteFormatting() {
102+
// Enter text in visual editor with formatting
103+
aztecText.perform(typeText(unformattedText + "\n"));
104+
quoteButton.perform(click());
105+
aztecText.perform(typeText(formattedText));
106+
107+
// Check that HTML formatting tags were correctly added
108+
toggleHTMLView();
109+
sourceText.check(matches(withText(unformattedText + "\n<blockquote>" + formattedText + "</blockquote>")));
110+
}
111+
112+
@Test
113+
public void testSimpleUnorderedListFormatting() {
114+
// Enter text in visual editor with formatting
115+
aztecText.perform(typeText(unformattedText + "\n"));
116+
unorderedListButton.perform(scrollTo(), click());
117+
aztecText.perform(typeText(formattedText));
118+
119+
// Check that HTML formatting tags were correctly added
120+
toggleHTMLView();
121+
sourceText.check(matches(withText(unformattedText + "\n<ul>\n\t<li>" + formattedText + "</li>\n</ul>")));
122+
}
123+
124+
@Test
125+
public void testSimpleOrderedListFormatting() {
126+
// Enter text in visual editor with formatting
127+
aztecText.perform(typeText(unformattedText + "\n"));
128+
orderedListButton.perform(scrollTo(), click());
129+
aztecText.perform(typeText(formattedText));
130+
131+
// Check that HTML formatting tags were correctly added
132+
toggleHTMLView();
133+
sourceText.check(matches(withText(unformattedText + "\n<ol>\n\t<li>" + formattedText + "</li>\n</ol>")));
134+
}
135+
136+
@Test
137+
public void testSimpleLinkFormatting() {
138+
// Enter text in visual editor with formatting
139+
aztecText.perform(typeText(unformattedText));
140+
linkButton.perform(scrollTo(), click());
141+
linkURLField.perform(typeTextIntoFocusedView(linkURLText));
142+
linkTextField.perform(typeText(formattedText));
143+
linkOKButton.perform(click());
144+
145+
// Check that HTML formatting tags were correctly added
146+
toggleHTMLView();
147+
sourceText.check(matches(withText(unformattedText + "<a href='" + linkURLText + "'>" + formattedText + "</a>")));
148+
}
149+
150+
@Test
151+
public void testSimpleMoreTagFormatting() {
152+
// Enter text in visual editor more tag in between
153+
aztecText.perform(typeText(unformattedText));
154+
moreButton.perform(scrollTo(), click());
155+
aztecText.perform(typeTextIntoFocusedView(unformattedText));
156+
157+
// Check that more tag was correctly added
158+
toggleHTMLView();
159+
sourceText.check(matches(withText(unformattedText + "\n\n<!--more-->\n\n" + unformattedText)));
160+
}
161+
162+
@Test
163+
public void testSimplePageBreakFormatting() {
164+
// Enter text in visual editor with page break in between
165+
aztecText.perform(typeText(unformattedText));
166+
pageButton.perform(scrollTo(), click());
167+
aztecText.perform(typeTextIntoFocusedView(unformattedText));
168+
169+
// Check that page break was correctly added
170+
toggleHTMLView();
171+
sourceText.check(matches(withText(unformattedText + "\n\n<!--pagebreak-->\n\n" + unformattedText)));
172+
}
173+
174+
@Test
175+
public void testSimpleHeadingOneFormatting() {
176+
// Enter text in visual editor with formatting
177+
aztecText.perform(typeText(unformattedText + "\n"));
178+
headingButton.perform(click());
179+
headingOneSelector.perform(click());
180+
aztecText.perform(typeTextIntoFocusedView(formattedText));
181+
182+
// Check that HTML formatting tags were correctly added
183+
toggleHTMLView();
184+
sourceText.check(matches(withText(unformattedText + "\n<h1>" + formattedText + "</h1>")));
185+
}
186+
187+
@Test
188+
public void testSimpleHeadingTwoFormatting() {
189+
// Enter text in visual editor with formatting
190+
aztecText.perform(typeText(unformattedText + "\n"));
191+
headingButton.perform(click());
192+
headingTwoSelector.perform(click());
193+
aztecText.perform(typeTextIntoFocusedView(formattedText));
194+
195+
// Check that HTML formatting tags were correctly added
196+
toggleHTMLView();
197+
sourceText.check(matches(withText(unformattedText + "\n<h2>" + formattedText + "</h2>")));
198+
}
199+
200+
@Test
201+
public void testSimpleHeadingThreeFormatting() {
202+
// Enter text in visual editor with formatting
203+
aztecText.perform(typeText(unformattedText + "\n"));
204+
headingButton.perform(click());
205+
headingThreeSelector.perform(click());
206+
aztecText.perform(typeTextIntoFocusedView(formattedText));
207+
208+
// Check that HTML formatting tags were correctly added
209+
toggleHTMLView();
210+
sourceText.check(matches(withText(unformattedText + "\n<h3>" + formattedText + "</h3>")));
211+
}
212+
213+
@Test
214+
public void testSimpleHeadingFourFormatting() {
215+
// Enter text in visual editor with formatting
216+
aztecText.perform(typeText(unformattedText + "\n"));
217+
headingButton.perform(click());
218+
headingFourSelector.perform(click());
219+
aztecText.perform(typeTextIntoFocusedView(formattedText));
220+
221+
// Check that HTML formatting tags were correctly added
222+
toggleHTMLView();
223+
sourceText.check(matches(withText(unformattedText + "\n<h4>" + formattedText + "</h4>")));
224+
}
225+
226+
@Test
227+
public void testSimpleHeadingFiveFormatting() {
228+
// Enter text in visual editor with formatting
229+
aztecText.perform(typeText(unformattedText + "\n"));
230+
headingButton.perform(click());
231+
headingFiveSelector.perform(click());
232+
aztecText.perform(typeTextIntoFocusedView(formattedText));
233+
234+
// Check that HTML formatting tags were correctly added
235+
toggleHTMLView();
236+
sourceText.check(matches(withText(unformattedText + "\n<h5>" + formattedText + "</h5>")));
237+
}
238+
239+
@Test
240+
public void testSimpleHeadingSixFormatting() {
241+
// Enter text in visual editor with formatting
242+
aztecText.perform(typeText(unformattedText + "\n"));
243+
headingButton.perform(click());
244+
headingSixSelector.perform(click());
245+
aztecText.perform(typeTextIntoFocusedView(formattedText));
246+
247+
// Check that HTML formatting tags were correctly added
248+
toggleHTMLView();
249+
sourceText.check(matches(withText(unformattedText + "\n<h6>" + formattedText + "</h6>")));
250+
}
29251

30-
enterHTML("<b>hello world</b>");
252+
@Test
253+
public void testSimplePreformattedTextFormatting() {
254+
// Enter text in visual editor with formatting
255+
aztecText.perform(typeText(unformattedText + "\n"));
256+
headingButton.perform(click());
257+
preSelector.perform(click());
258+
aztecText.perform(typeTextIntoFocusedView(formattedText));
31259

32-
boldButton.check(matches(isChecked()));
260+
// Check that HTML formatting tags were correctly added
261+
toggleHTMLView();
262+
sourceText.check(matches(withText(unformattedText + "\n<pre>" + formattedText + "</pre>")));
33263
}
34-
}
264+
}

app/src/androidTest/java/org/wordpress/aztec/demo/TestUtils.java

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,54 @@
44

55
import static android.support.test.espresso.Espresso.onView;
66
import static android.support.test.espresso.action.ViewActions.click;
7-
import static android.support.test.espresso.action.ViewActions.typeText;
7+
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
88
import static android.support.test.espresso.matcher.ViewMatchers.withId;
9+
import static android.support.test.espresso.matcher.ViewMatchers.withText;
10+
import static org.hamcrest.Matchers.allOf;
911

1012
/**
1113
* Test utilities to be used with instrumentation tests.
1214
*/
1315
public class TestUtils {
14-
public static void toggleHTMLView() {
15-
ViewInteraction htmlButton = onView(withId(R.id.format_bar_button_html));
16-
htmlButton.perform(click());
17-
}
1816

19-
public static void enterHTML(String text) {
20-
toggleHTMLView();
17+
// Strings
18+
public static String unformattedText = "hello";
19+
public static String formattedText = "world";
20+
public static String linkURLText = "https://github.com/wordpress-mobile/AztecEditor-Android";
21+
22+
// Editor Views
23+
public static ViewInteraction aztecText = onView(withId(R.id.aztec));
24+
public static ViewInteraction sourceText = onView(allOf(withId(R.id.source), isDisplayed()));
2125

22-
ViewInteraction htmlViewEditText = onView(withId(R.id.source));
23-
htmlViewEditText.perform(typeText(text));
26+
// Format Toolbar Buttons
27+
public static ViewInteraction boldButton = onView(withId(R.id.format_bar_button_bold));
28+
public static ViewInteraction headingButton = onView(withId(R.id.format_bar_button_heading));
29+
public static ViewInteraction italicButton = onView(withId(R.id.format_bar_button_italic));
30+
public static ViewInteraction linkButton = onView(withId(R.id.format_bar_button_link));
31+
public static ViewInteraction moreButton = onView(withId(R.id.format_bar_button_more));
32+
public static ViewInteraction orderedListButton = onView(withId(R.id.format_bar_button_ol));
33+
public static ViewInteraction pageButton = onView(withId(R.id.format_bar_button_page));
34+
public static ViewInteraction quoteButton = onView(withId(R.id.format_bar_button_quote));
35+
public static ViewInteraction strikethroughButton = onView(withId(R.id.format_bar_button_strikethrough));
36+
public static ViewInteraction underlineButton = onView(withId(R.id.format_bar_button_underline));
37+
public static ViewInteraction unorderedListButton = onView(withId(R.id.format_bar_button_ul));
2438

25-
toggleHTMLView();
39+
// Heading/Paragraph Format Selectors
40+
public static ViewInteraction headingOneSelector = onView(allOf(withId(android.R.id.title), withText("Heading 1")));
41+
public static ViewInteraction headingTwoSelector = onView(withText("Heading 2"));
42+
public static ViewInteraction headingThreeSelector = onView(withText("Heading 3"));
43+
public static ViewInteraction headingFourSelector = onView(withText("Heading 4"));
44+
public static ViewInteraction headingFiveSelector = onView(withText("Heading 5"));
45+
public static ViewInteraction headingSixSelector = onView(withText("Heading 6"));
46+
public static ViewInteraction preSelector = onView(withText("Heading 6"));
47+
48+
// Link Modal
49+
public static ViewInteraction linkOKButton = onView(withId(android.R.id.button1));
50+
public static ViewInteraction linkTextField = onView(withId(R.id.linkText));
51+
public static ViewInteraction linkURLField = onView(withId(R.id.linkURL));
52+
53+
public static void toggleHTMLView() {
54+
ViewInteraction htmlButton = onView(withId(R.id.format_bar_button_html));
55+
htmlButton.perform(click());
2656
}
2757
}

0 commit comments

Comments
 (0)