From 538d7df3ef654fe8b50ad4fbc8085af0b73c6988 Mon Sep 17 00:00:00 2001 From: Gerardo Date: Fri, 16 Dec 2022 16:43:39 +0100 Subject: [PATCH] Mobile - E2E Tests - Fix block insertion flakiness --- ...gutenberg-editor-block-insertion-2.test.js | 36 +++++++++++++++++++ .../gutenberg-editor-block-insertion.test.js | 12 ++++--- .../__device-tests__/pages/editor-page.js | 1 + 3 files changed, 45 insertions(+), 4 deletions(-) diff --git a/packages/react-native-editor/__device-tests__/gutenberg-editor-block-insertion-2.test.js b/packages/react-native-editor/__device-tests__/gutenberg-editor-block-insertion-2.test.js index 2ab5bdda7f6ca7..e86439f20de168 100644 --- a/packages/react-native-editor/__device-tests__/gutenberg-editor-block-insertion-2.test.js +++ b/packages/react-native-editor/__device-tests__/gutenberg-editor-block-insertion-2.test.js @@ -14,8 +14,19 @@ import { describe( 'Gutenberg Editor tests for Block insertion 2', () => { it( 'adds new block at the end of post', async () => { await editorPage.addNewBlock( blockNames.heading ); + + const headingBlock = await editorPage.getBlockAtPosition( + blockNames.heading + ); + expect( headingBlock ).toBeTruthy(); + await editorPage.addNewBlock( blockNames.list ); + const listItemBlock = await editorPage.getBlockAtPosition( + blockNames.listItem + ); + expect( listItemBlock ).toBeTruthy(); + const expectedHtml = [ headerBlockEmpty, listBlockEmpty ].join( '\n\n' ); @@ -29,6 +40,12 @@ describe( 'Gutenberg Editor tests for Block insertion 2', () => { await editorPage.addNewBlock( blockNames.separator ); + const separatorBlock = await editorPage.getBlockAtPosition( + blockNames.separator, + 2 + ); + expect( separatorBlock ).toBeTruthy(); + const expectedHtml = [ headerBlockEmpty, separatorBlockEmpty, @@ -47,6 +64,13 @@ describe( 'Gutenberg Editor tests for Block insertion 2', () => { await separatorBlockElement.click(); await editorPage.addNewBlock( blockNames.image, 'before' ); + + const imageBlock = await editorPage.getBlockAtPosition( + blockNames.image, + 2 + ); + expect( imageBlock ).toBeTruthy(); + await editorPage.closePicker(); const expectedHtml = [ @@ -63,6 +87,12 @@ describe( 'Gutenberg Editor tests for Block insertion 2', () => { it( 'inserts block at the end of post when no block is selected', async () => { await editorPage.addNewBlock( blockNames.more ); + const moreBlock = await editorPage.getBlockAtPosition( + blockNames.more, + 5 + ); + expect( moreBlock ).toBeTruthy(); + const expectedHtml = [ headerBlockEmpty, imageBlockEmpty, @@ -78,6 +108,12 @@ describe( 'Gutenberg Editor tests for Block insertion 2', () => { it( 'creates a new Paragraph block tapping on the empty area below the last block', async () => { await editorPage.addParagraphBlockByTappingEmptyAreaBelowLastBlock(); + const paragraphBlock = await editorPage.getBlockAtPosition( + blockNames.paragraph, + 6 + ); + expect( paragraphBlock ).toBeTruthy(); + const expectedHtml = [ headerBlockEmpty, imageBlockEmpty, diff --git a/packages/react-native-editor/__device-tests__/gutenberg-editor-block-insertion.test.js b/packages/react-native-editor/__device-tests__/gutenberg-editor-block-insertion.test.js index abebfc7486962c..447e1a997ecc88 100644 --- a/packages/react-native-editor/__device-tests__/gutenberg-editor-block-insertion.test.js +++ b/packages/react-native-editor/__device-tests__/gutenberg-editor-block-insertion.test.js @@ -81,7 +81,7 @@ describe( 'Gutenberg Editor tests for Block insertion', () => { it( 'should be able to insert block at the beginning of post from the title', async () => { await editorPage.addNewBlock( blockNames.paragraph ); - let paragraphBlockElement = await editorPage.getTextBlockAtPosition( + const paragraphBlockElement = await editorPage.getTextBlockAtPosition( blockNames.paragraph ); if ( isAndroid() ) { @@ -98,15 +98,19 @@ describe( 'Gutenberg Editor tests for Block insertion', () => { const titleElement = await editorPage.getTitleElement( { autoscroll: true, } ); + expect( titleElement ).toBeTruthy(); await titleElement.click(); await editorPage.addNewBlock( blockNames.paragraph ); - paragraphBlockElement = await editorPage.getTextBlockAtPosition( + const emptyParagraphBlock = await editorPage.getBlockAtPosition( blockNames.paragraph ); - await clickMiddleOfElement( editorPage.driver, paragraphBlockElement ); + expect( emptyParagraphBlock ).toBeTruthy(); + const emptyParagraphBlockElement = + await editorPage.getTextBlockAtPosition( blockNames.paragraph ); + expect( emptyParagraphBlockElement ).toBeTruthy(); + await editorPage.sendTextToParagraphBlock( 1, testData.mediumText ); - await paragraphBlockElement.click(); const html = await editorPage.getHtmlContent(); expect( html.toLowerCase() ).toBe( testData.blockInsertionHtmlFromTitle.toLowerCase() diff --git a/packages/react-native-editor/__device-tests__/pages/editor-page.js b/packages/react-native-editor/__device-tests__/pages/editor-page.js index 248999dcb5d657..2f5aae6de9cbf3 100644 --- a/packages/react-native-editor/__device-tests__/pages/editor-page.js +++ b/packages/react-native-editor/__device-tests__/pages/editor-page.js @@ -801,6 +801,7 @@ const blockNames = { image: 'Image', latestPosts: 'Latest Posts', list: 'List', + listItem: 'List item', more: 'More', paragraph: 'Paragraph', search: 'Search',