diff --git a/WordPress/src/androidTest/java/org/wordpress/android/e2e/BlockEditorTests.java b/WordPress/src/androidTest/java/org/wordpress/android/e2e/BlockEditorTests.java index 869abcaa2d6b..81af047618b9 100644 --- a/WordPress/src/androidTest/java/org/wordpress/android/e2e/BlockEditorTests.java +++ b/WordPress/src/androidTest/java/org/wordpress/android/e2e/BlockEditorTests.java @@ -6,18 +6,14 @@ import androidx.test.rule.GrantPermissionRule; import org.junit.Before; -import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.wordpress.android.e2e.pages.BlockEditorPage; import org.wordpress.android.e2e.pages.MySitesPage; -import org.wordpress.android.e2e.pages.PostPreviewPage; -import org.wordpress.android.e2e.pages.SiteSettingsPage; import org.wordpress.android.support.BaseTest; import org.wordpress.android.ui.WPLaunchActivity; -import static androidx.test.espresso.Espresso.pressBack; -import static org.wordpress.android.support.WPSupportUtils.sleep; +import java.time.Instant; public class BlockEditorTests extends BaseTest { @Rule @@ -32,34 +28,63 @@ public void setUp() { wpLogin(); } - @Ignore("until startup times are improved or idling resources are made more reliable") - @Test - public void testSwitchToClassicAndPreview() { - String title = "Hello Espresso!"; - - MySitesPage mySitesPage = new MySitesPage().go(); - sleep(); - - mySitesPage.clickSettingsItem(); - - // Set to Gutenberg. Apparently the site is defaulting to Aztec still. - new SiteSettingsPage().setEditorToGutenberg(); - - // exit the Settings page - pressBack(); - - mySitesPage.clickBlogPostsItem(); - - mySitesPage.startNewPost(); + String mTitle = "Hello Espresso!"; + String mPostText = "Lorem ipsum dolor sit amet, consectetur adipiscing elit."; + String mCategory = "Wedding"; + String mTag = "Tag " + Instant.now().toEpochMilli(); + String mHtmlPost = "\n" + + "

" + mPostText + "

\n" + + "" + + "\n" + + "
\n" + + "
\"\"
\n" + + "
\n"; - BlockEditorPage blockEditorPage = new BlockEditorPage(); - blockEditorPage.waitForTitleDisplayed(); - - blockEditorPage.enterTitle(title); + @Test + public void publishSimplePost() { + new MySitesPage() + .go() + .startNewPost(); + + new BlockEditorPage() + .waitForTitleDisplayed() + .enterTitle(mTitle) + .enterParagraphText(mPostText) + .publish() + .verifyPostPublished(); + } - blockEditorPage.previewPost(); - sleep(); + @Test + public void publishFullPost() { + new MySitesPage() + .go() + .startNewPost(); + + new BlockEditorPage() + .waitForTitleDisplayed() + .enterTitle(mTitle) + .enterParagraphText(mPostText) + .addImage() + .addPostSettings(mCategory, mTag) + .clickPublish() + .verifyPostSettings(mCategory, mTag) + .confirmPublish() + .verifyPostPublished(); + } - new PostPreviewPage(); + @Test + public void blockEditorCanDisplayElementAddedInHtmlMode() { + new MySitesPage() + .go() + .startNewPost(); + + new BlockEditorPage() + .waitForTitleDisplayed() + .enterTitle(mTitle) + .switchToHtmlMode() + .enterParagraphText(mHtmlPost) + .switchToVisualMode() + .verifyPostElementText(mPostText); } } diff --git a/WordPress/src/androidTest/java/org/wordpress/android/e2e/pages/BlockEditorPage.java b/WordPress/src/androidTest/java/org/wordpress/android/e2e/pages/BlockEditorPage.java index 41953fecb2fb..0d6f6d7178b9 100644 --- a/WordPress/src/androidTest/java/org/wordpress/android/e2e/pages/BlockEditorPage.java +++ b/WordPress/src/androidTest/java/org/wordpress/android/e2e/pages/BlockEditorPage.java @@ -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)))); + } + + 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", + 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() { diff --git a/WordPress/src/androidTest/java/org/wordpress/android/support/WPSupportUtils.java b/WordPress/src/androidTest/java/org/wordpress/android/support/WPSupportUtils.java index 725951f087b1..ba79cc7f9159 100644 --- a/WordPress/src/androidTest/java/org/wordpress/android/support/WPSupportUtils.java +++ b/WordPress/src/androidTest/java/org/wordpress/android/support/WPSupportUtils.java @@ -462,17 +462,21 @@ public Boolean get() { } public static boolean waitForElementToBeDisplayedWithoutFailure(final Integer elementID) { + return waitForElementToBeDisplayedWithoutFailure(onView(withId(elementID))); + } + + public static boolean waitForElementToBeDisplayedWithoutFailure(final ViewInteraction element) { try { waitForConditionToBeTrueWithoutFailure(new Supplier() { @Override public Boolean get() { - return isElementDisplayed(elementID); + return isElementDisplayed(element); } }); } catch (Exception e) { // ignore the failure } - return isElementDisplayed(elementID); + return isElementDisplayed(element); } public static void waitForConditionToBeTrue(Supplier supplier) { diff --git a/libs/mocks/WordPressMocks/src/main/assets/mocks/mappings/wp/blocks_106707880.json b/libs/mocks/WordPressMocks/src/main/assets/mocks/mappings/wp/blocks_106707880.json new file mode 100644 index 000000000000..59167489ea11 --- /dev/null +++ b/libs/mocks/WordPressMocks/src/main/assets/mocks/mappings/wp/blocks_106707880.json @@ -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": [] + } +} diff --git a/libs/mocks/WordPressMocks/src/main/assets/mocks/mappings/wpcom/media/media_133.json b/libs/mocks/WordPressMocks/src/main/assets/mocks/mappings/wpcom/media/media_133.json new file mode 100644 index 000000000000..7f3cdc1d89ca --- /dev/null +++ b/libs/mocks/WordPressMocks/src/main/assets/mocks/mappings/wpcom/media/media_133.json @@ -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" + } + } + } + } +} diff --git a/libs/mocks/WordPressMocks/src/main/assets/mocks/mappings/wpcom/sites/rest_v2_sites_106707880_xposts.json b/libs/mocks/WordPressMocks/src/main/assets/mocks/mappings/wpcom/sites/rest_v2_sites_106707880_xposts.json new file mode 100644 index 000000000000..7bca5a6c3d9e --- /dev/null +++ b/libs/mocks/WordPressMocks/src/main/assets/mocks/mappings/wpcom/sites/rest_v2_sites_106707880_xposts.json @@ -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 + } + } + } +}