-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add block editor tests #15741
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add block editor tests #15741
Changes from all commits
cf4d838
10dcdd4
2aa0673
1e0ae87
f4ae25a
d1f84ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,14 +8,23 @@ | |
|
|
||
| import static androidx.test.espresso.Espresso.onView; | ||
| import static androidx.test.espresso.Espresso.openActionBarOverflowOrOptionsMenu; | ||
| import static androidx.test.espresso.Espresso.pressBack; | ||
| import static androidx.test.espresso.action.ViewActions.click; | ||
| import static androidx.test.espresso.action.ViewActions.swipeDown; | ||
| import static androidx.test.espresso.action.ViewActions.typeText; | ||
| import static androidx.test.espresso.assertion.ViewAssertions.matches; | ||
| import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; | ||
| import static androidx.test.espresso.matcher.ViewMatchers.withHint; | ||
| import static androidx.test.espresso.matcher.ViewMatchers.withId; | ||
| import static androidx.test.espresso.matcher.ViewMatchers.withResourceName; | ||
| import static androidx.test.espresso.matcher.ViewMatchers.withText; | ||
| import static org.wordpress.android.support.WPSupportUtils.clickOn; | ||
| import static org.wordpress.android.support.WPSupportUtils.clickOnViewWithTag; | ||
| import static org.wordpress.android.support.WPSupportUtils.populateTextField; | ||
| import static org.wordpress.android.support.WPSupportUtils.waitForElementToBeDisplayed; | ||
| import static org.wordpress.android.support.WPSupportUtils.waitForElementToBeDisplayedWithoutFailure; | ||
| import static junit.framework.TestCase.assertTrue; | ||
| import static org.wordpress.android.support.WPSupportUtils.withIndex; | ||
|
|
||
| public class BlockEditorPage { | ||
| private static ViewInteraction titleField = onView(withHint("Add title")); | ||
|
|
@@ -27,12 +36,113 @@ public BlockEditorPage() { | |
| mEditor.check(matches(isDisplayed())); | ||
| } | ||
|
|
||
| public void waitForTitleDisplayed() { | ||
| public BlockEditorPage waitForTitleDisplayed() { | ||
| waitForElementToBeDisplayed(titleField); | ||
| return this; | ||
| } | ||
|
|
||
| public void enterTitle(String postTitle) { | ||
| public BlockEditorPage enterTitle(String postTitle) { | ||
| titleField.perform(typeText(postTitle), ViewActions.closeSoftKeyboard()); | ||
| return this; | ||
| } | ||
|
|
||
| public BlockEditorPage enterParagraphText(String paragraphText) { | ||
| onView(withHint(R.string.gutenberg_native_start_writing)) | ||
| .perform(typeText(paragraphText), ViewActions.closeSoftKeyboard()); | ||
| return this; | ||
| } | ||
|
|
||
| public BlockEditorPage switchToHtmlMode() { | ||
| openActionBarOverflowOrOptionsMenu(ApplicationProvider.getApplicationContext()); | ||
| clickOn(onView(withText(R.string.menu_html_mode))); | ||
| return this; | ||
| } | ||
|
|
||
| public BlockEditorPage switchToVisualMode() { | ||
| openActionBarOverflowOrOptionsMenu(ApplicationProvider.getApplicationContext()); | ||
| clickOn(onView(withText(R.string.menu_visual_mode))); | ||
| return this; | ||
| } | ||
|
|
||
| public BlockEditorPage addPostSettings(String categoryName, String tagName) { | ||
| openPostSetting(); | ||
| addCategory(categoryName); | ||
| addTag(tagName); | ||
| pressBack(); | ||
| return this; | ||
| } | ||
|
|
||
| public void openPostSetting() { | ||
| openActionBarOverflowOrOptionsMenu(ApplicationProvider.getApplicationContext()); | ||
| clickOn(onView(withText(R.string.post_settings))); | ||
| } | ||
|
|
||
| public void addCategory(String category) { | ||
| clickOn(onView(withId(R.id.post_categories_container))); | ||
| clickOn(onView(withText(category))); | ||
| pressBack(); | ||
| } | ||
|
|
||
| public void addTag(String tag) { | ||
| clickOn(onView(withId(R.id.post_tags_container))); | ||
| ViewInteraction tagsField = onView(withId(R.id.tags_edit_text)); | ||
| populateTextField(tagsField, tag); | ||
| pressBack(); | ||
| } | ||
|
|
||
| public BlockEditorPage publish() { | ||
| clickPublish(); | ||
| confirmPublish(); | ||
| return this; | ||
| } | ||
|
|
||
| public BlockEditorPage clickPublish() { | ||
| clickOn(onView(withResourceName("menu_primary_action"))); | ||
| return this; | ||
| } | ||
|
|
||
| public BlockEditorPage confirmPublish() { | ||
| clickOn(onView(withText(R.string.publish_now))); | ||
| dismissBloggingRemindersAlertIfNeeded(); | ||
| return this; | ||
| } | ||
|
|
||
| public void dismissBloggingRemindersAlertIfNeeded() { | ||
| ViewInteraction bloggingRemindersAlertTitle = onView(withText(R.string.set_your_blogging_reminders_title)); | ||
|
|
||
| if (waitForElementToBeDisplayedWithoutFailure(bloggingRemindersAlertTitle)) { | ||
| bloggingRemindersAlertTitle.perform(swipeDown()); | ||
| } | ||
| } | ||
|
|
||
| public void verifyPostPublished() { | ||
| assertTrue("'Post published' toast was not displayed", | ||
| waitForElementToBeDisplayedWithoutFailure(onView(withText(R.string.post_published)))); | ||
|
Comment on lines
+119
to
+120
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤔 Having the assertion failure message as the first argument makes the code a bit confusing.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Completely agree with that, I needed a second look to see that that was supposed to be the error message. |
||
| } | ||
|
|
||
| public BlockEditorPage verifyPostSettings(String categoryName, String tagName) { | ||
| assertTrue("Category is not present in Post confirmation panel", | ||
| waitForElementToBeDisplayedWithoutFailure(onView(withText(categoryName)))); | ||
| assertTrue("Tag is not present in Post confirmation panel", | ||
| waitForElementToBeDisplayedWithoutFailure(onView(withText(tagName)))); | ||
| return this; | ||
| } | ||
|
|
||
| public BlockEditorPage verifyPostElementText(String postText) { | ||
| assertTrue("Expected text is not displayed", | ||
|
jostnes marked this conversation as resolved.
|
||
| waitForElementToBeDisplayedWithoutFailure(onView(withText(postText)))); | ||
| return this; | ||
| } | ||
|
|
||
| public BlockEditorPage addImage() { | ||
| clickOnViewWithTag("add-block-button"); | ||
| clickOn("Image"); | ||
| clickOn("WordPress Media Library"); | ||
| waitForElementToBeDisplayed(onView(withText("WordPress media"))); | ||
| waitForElementToBeDisplayed(onView(withIndex(withId(R.id.image_thumbnail), 0))); | ||
| onView(withIndex(withId(R.id.image_thumbnail), 0)).perform(click()); | ||
| clickOn(R.id.mnu_confirm_selection); | ||
| return this; | ||
| } | ||
|
|
||
| public void previewPost() { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| { | ||
| "request": { | ||
| "method": "GET", | ||
| "urlPath": "/wp/v2/sites/106707880/blocks", | ||
| "queryParameters": { | ||
| "locale": { | ||
| "matches": "(.*)" | ||
| }, | ||
| "_locale": { | ||
| "equalTo": "user" | ||
| }, | ||
| "per_page": { | ||
| "equalTo": "100" | ||
| } | ||
| } | ||
| }, | ||
| "response": { | ||
| "status": 200, | ||
| "jsonBody": [] | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| { | ||
| "request": { | ||
| "method": "GET", | ||
| "urlPath": "/wp/v2/sites/106707880/media/133", | ||
| "queryParameters": { | ||
| "locale": { | ||
| "matches": "(.*)" | ||
| } | ||
| } | ||
| }, | ||
| "response": { | ||
| "status": 200, | ||
| "jsonBody": { | ||
| "ID": 133, | ||
| "URL": "https://e2eflowtestingmobile.files.wordpress.com/2019/05/img_0111-14.jpg", | ||
| "guid": "http://e2eflowtestingmobile.files.wordpress.com/2019/05/img_0111-14.jpg", | ||
| "date": "2019-05-08T09:49:00+00:00", | ||
| "post_ID": 295, | ||
| "author_ID": 152748359, | ||
| "file": "img_0111-14.jpg", | ||
| "mime_type": "image/jpeg", | ||
| "extension": "jpg", | ||
| "title": "img_0111", | ||
| "caption": "", | ||
| "description": "", | ||
| "alt": "", | ||
| "icon": "https://s1.wp.com/wp-includes/images/media/default.png", | ||
| "thumbnails": { | ||
| "thumbnail": "https://e2eflowtestingmobile.files.wordpress.com/2019/05/img_0111-14.jpg?w=150", | ||
| "medium": "https://e2eflowtestingmobile.files.wordpress.com/2019/05/img_0111-14.jpg?w=300", | ||
| "large": "https://e2eflowtestingmobile.files.wordpress.com/2019/05/img_0111-14.jpg?w=1024", | ||
| "post-thumbnail": "https://e2eflowtestingmobile.files.wordpress.com/2019/05/img_0111-14.jpg?w=740&h=430&crop=1", | ||
| "independent-publisher-2-banner": "https://e2eflowtestingmobile.files.wordpress.com/2019/05/img_0111-14.jpg?w=1440&h=600&crop=1", | ||
| "independent-publisher-2-full-width": "https://e2eflowtestingmobile.files.wordpress.com/2019/05/img_0111-14.jpg?w=1100" | ||
| }, | ||
| "height": 3024, | ||
| "width": 4032, | ||
| "exif": { | ||
| "aperture": "2.4", | ||
| "credit": "", | ||
| "camera": "iPhone X", | ||
| "caption": "", | ||
| "created_timestamp": "1522412059", | ||
| "copyright": "", | ||
| "focal_length": "6", | ||
| "iso": "16", | ||
| "shutter_speed": "0.0047846889952153", | ||
| "title": "", | ||
| "orientation": "1", | ||
| "keywords": [] | ||
| }, | ||
| "meta": { | ||
| "links": { | ||
| "self": "{{request.requestLine.baseUrl}}/rest/v1.1/sites/106707880/media/133", | ||
| "help": "{{request.requestLine.baseUrl}}/rest/v1.1/sites/106707880/media/133/help", | ||
| "site": "{{request.requestLine.baseUrl}}/rest/v1.1/sites/106707880", | ||
| "parent": "{{request.requestLine.baseUrl}}/rest/v1.1/sites/106707880/posts/295" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| { | ||
| "request": { | ||
| "method": "GET", | ||
| "urlPath": "/wpcom/v2/sites/106707880/xposts/" | ||
| }, | ||
| "response": { | ||
| "status": 200, | ||
| "jsonBody": { | ||
| "code": "xposts_require_o2_enabled", | ||
| "message": "Xposts are only available on sites with the o2-plugin enabled.", | ||
| "data": { | ||
| "status": 400 | ||
| } | ||
| } | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.