Skip to content
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

[RNMobile] - Update tests with paragraph blocks to work on both environments and platforms #40404

Merged
merged 8 commits into from
Apr 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import testData from './helpers/test-data';
describe( 'Gutenberg Editor tests for Block insertion', () => {
it( 'should be able to insert multi-paragraph text, and text to another paragraph block in between', async () => {
await editorPage.addNewBlock( blockNames.paragraph );
let paragraphBlockElement = await editorPage.getBlockAtPosition(
let paragraphBlockElement = await editorPage.getTextBlockAtPosition(
blockNames.paragraph
);
if ( isAndroid() ) {
Expand All @@ -18,15 +18,15 @@ describe( 'Gutenberg Editor tests for Block insertion', () => {
await editorPage.sendTextToParagraphBlock( 1, testData.longText );
// Should have 3 paragraph blocks at this point.

paragraphBlockElement = await editorPage.getBlockAtPosition(
paragraphBlockElement = await editorPage.getTextBlockAtPosition(
blockNames.paragraph,
2
);
await paragraphBlockElement.click();

await editorPage.addNewBlock( blockNames.paragraph );

paragraphBlockElement = await editorPage.getBlockAtPosition(
paragraphBlockElement = await editorPage.getTextBlockAtPosition(
blockNames.paragraph,
3
);
Expand All @@ -44,7 +44,7 @@ describe( 'Gutenberg Editor tests for Block insertion', () => {

// Workaround for now since deleting the first element causes a crash on CI for Android
if ( isAndroid() ) {
paragraphBlockElement = await editorPage.getBlockAtPosition(
paragraphBlockElement = await editorPage.getTextBlockAtPosition(
blockNames.paragraph,
3,
{
Expand All @@ -57,7 +57,7 @@ describe( 'Gutenberg Editor tests for Block insertion', () => {
for ( let i = 3; i > 0; i-- ) {
// wait for accessibility ids to update
await editorPage.driver.sleep( 1000 );
paragraphBlockElement = await editorPage.getBlockAtPosition(
paragraphBlockElement = await editorPage.getTextBlockAtPosition(
blockNames.paragraph,
i,
{
Expand All @@ -74,7 +74,7 @@ describe( 'Gutenberg Editor tests for Block insertion', () => {
for ( let i = 4; i > 0; i-- ) {
// wait for accessibility ids to update
await editorPage.driver.sleep( 1000 );
paragraphBlockElement = await editorPage.getBlockAtPosition(
paragraphBlockElement = await editorPage.getTextBlockAtPosition(
blockNames.paragraph
);
await clickMiddleOfElement(
Expand All @@ -88,7 +88,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.getBlockAtPosition(
let paragraphBlockElement = await editorPage.getTextBlockAtPosition(
blockNames.paragraph
);
if ( isAndroid() ) {
Expand All @@ -110,7 +110,7 @@ describe( 'Gutenberg Editor tests for Block insertion', () => {
await titleElement.click();

await editorPage.addNewBlock( blockNames.paragraph );
paragraphBlockElement = await editorPage.getBlockAtPosition(
paragraphBlockElement = await editorPage.getTextBlockAtPosition(
blockNames.paragraph
);
await clickMiddleOfElement( editorPage.driver, paragraphBlockElement );
Expand Down
14 changes: 9 additions & 5 deletions packages/react-native-editor/__device-tests__/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ describe( 'Gutenberg Editor tests', () => {
it( 'should be able to create a post with heading and paragraph blocks', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related to this PR but I noticed this test case doesn't have expect statements 🤔, it will fail for some error cases but I think we're not fully covering the logic without actually checking the HTML output.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, this test can potentially be a false positive. I'll update the assert for this in the next PR where I'm planning to update heading and lists blocks.

await editorPage.addNewBlock( blockNames.heading );
let headingBlockElement = await editorPage.getBlockAtPosition(
blockNames.heading
blockNames.heading,
1,
{
useWaitForVisible: true,
}
);
if ( isAndroid() ) {
await headingBlockElement.click();
Expand All @@ -21,7 +25,7 @@ describe( 'Gutenberg Editor tests', () => {
);

await editorPage.addNewBlock( blockNames.paragraph );
let paragraphBlockElement = await editorPage.getBlockAtPosition(
let paragraphBlockElement = await editorPage.getTextBlockAtPosition(
blockNames.paragraph,
2
);
Expand All @@ -31,7 +35,7 @@ describe( 'Gutenberg Editor tests', () => {
);

await editorPage.addNewBlock( blockNames.paragraph );
paragraphBlockElement = await editorPage.getBlockAtPosition(
paragraphBlockElement = await editorPage.getTextBlockAtPosition(
blockNames.paragraph,
3
);
Expand All @@ -41,7 +45,7 @@ describe( 'Gutenberg Editor tests', () => {
);

await editorPage.addNewBlock( blockNames.heading );
headingBlockElement = await editorPage.getBlockAtPosition(
headingBlockElement = await editorPage.getTextBlockAtPosition(
blockNames.heading,
4
);
Expand All @@ -51,7 +55,7 @@ describe( 'Gutenberg Editor tests', () => {
);

await editorPage.addNewBlock( blockNames.paragraph );
paragraphBlockElement = await editorPage.getBlockAtPosition(
paragraphBlockElement = await editorPage.getTextBlockAtPosition(
blockNames.paragraph,
5
);
Expand Down
12 changes: 7 additions & 5 deletions packages/react-native-editor/__device-tests__/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ import testData from './helpers/test-data';
describe( 'Gutenberg Editor Image Block tests', () => {
it( 'should be able to add an image block', async () => {
await editorPage.addNewBlock( blockNames.image );
await editorPage.driver.sleep( 1000 );
await editorPage.closePicker();

let imageBlock = await editorPage.getBlockAtPosition(
blockNames.image
const imageBlock = await editorPage.getBlockAtPosition(
blockNames.image,
1,
{
useWaitForVisible: true,
}
);

// Can only add image from media library on iOS
Expand All @@ -26,7 +29,6 @@ describe( 'Gutenberg Editor Image Block tests', () => {
await editorPage.dismissKeyboard();
// End workaround.

imageBlock = await editorPage.getBlockAtPosition( imageBlock );
await swipeUp( editorPage.driver, imageBlock );
await editorPage.enterCaptionToSelectedImageBlock(
testData.imageCaption,
Expand All @@ -35,7 +37,7 @@ describe( 'Gutenberg Editor Image Block tests', () => {
await editorPage.dismissKeyboard();
}
await editorPage.addNewBlock( blockNames.paragraph );
const paragraphBlockElement = await editorPage.getBlockAtPosition(
const paragraphBlockElement = await editorPage.getTextBlockAtPosition(
blockNames.paragraph,
2
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,39 +13,22 @@ import testData from './helpers/test-data';
describe( 'Gutenberg Editor tests for Paragraph Block', () => {
it( 'should be able to split one paragraph block into two', async () => {
await editorPage.addNewBlock( blockNames.paragraph );
const paragraphBlockElement = await editorPage.getBlockAtPosition(
const paragraphBlockElement = await editorPage.getTextBlockAtPosition(
blockNames.paragraph
);
if ( isAndroid() ) {
await paragraphBlockElement.click();
}

await editorPage.typeTextToParagraphBlock(
paragraphBlockElement,
testData.shortText
);
const textViewElement = await editorPage.getTextViewForParagraphBlock(
paragraphBlockElement
);
await clickMiddleOfElement( editorPage.driver, textViewElement );
await clickMiddleOfElement( editorPage.driver, paragraphBlockElement );
await editorPage.typeTextToParagraphBlock(
paragraphBlockElement,
'\n',
false
);
expect(
( await editorPage.hasBlockAtPosition(
1,
blockNames.paragraph
) ) &&
( await editorPage.hasBlockAtPosition(
2,
blockNames.paragraph
) )
).toBe( true );

jostnes marked this conversation as resolved.
Show resolved Hide resolved
const text0 = await editorPage.getTextForParagraphBlockAtPosition( 1 );
const text1 = await editorPage.getTextForParagraphBlockAtPosition( 2 );
expect( await editorPage.getNumberOfParagraphBlocks() ).toEqual( 2 );
expect( text0 ).not.toBe( '' );
expect( text1 ).not.toBe( '' );
expect( testData.shortText ).toMatch(
Expand All @@ -58,7 +41,7 @@ describe( 'Gutenberg Editor tests for Paragraph Block', () => {

it( 'should be able to merge 2 paragraph blocks into 1', async () => {
await editorPage.addNewBlock( blockNames.paragraph );
let paragraphBlockElement = await editorPage.getBlockAtPosition(
let paragraphBlockElement = await editorPage.getTextBlockAtPosition(
blockNames.paragraph
);
if ( isAndroid() ) {
Expand All @@ -69,62 +52,38 @@ describe( 'Gutenberg Editor tests for Paragraph Block', () => {
paragraphBlockElement,
testData.shortText
);
let textViewElement = await editorPage.getTextViewForParagraphBlock(
paragraphBlockElement
);
await clickMiddleOfElement( editorPage.driver, textViewElement );
await clickMiddleOfElement( editorPage.driver, paragraphBlockElement );
await editorPage.typeTextToParagraphBlock(
paragraphBlockElement,
'\n'
);
expect(
jostnes marked this conversation as resolved.
Show resolved Hide resolved
( await editorPage.hasBlockAtPosition(
1,
blockNames.paragraph
) ) &&
( await editorPage.hasBlockAtPosition(
2,
blockNames.paragraph
) )
).toBe( true );

const text0 = await editorPage.getTextForParagraphBlockAtPosition( 1 );
const text1 = await editorPage.getTextForParagraphBlockAtPosition( 2 );
paragraphBlockElement = await editorPage.getBlockAtPosition(
expect( await editorPage.getNumberOfParagraphBlocks() ).toEqual( 2 );
paragraphBlockElement = await editorPage.getTextBlockAtPosition(
blockNames.paragraph,
2
);
if ( isAndroid() ) {
await paragraphBlockElement.click();
}

textViewElement = await editorPage.getTextViewForParagraphBlock(
await clickBeginningOfElement(
editorPage.driver,
paragraphBlockElement
);
await clickBeginningOfElement( editorPage.driver, textViewElement );

await editorPage.typeTextToParagraphBlock(
paragraphBlockElement,
backspace
);

const text = await editorPage.getTextForParagraphBlockAtPosition( 1 );
expect( text0 + text1 ).toMatch( text );

expect(
await editorPage.hasBlockAtPosition( 2, blockNames.paragraph )
).toBe( false );
expect( await editorPage.getNumberOfParagraphBlocks() ).toEqual( 1 );
await editorPage.removeBlockAtPosition( blockNames.paragraph );
} );

it( 'should be able to create a post with multiple paragraph blocks', async () => {
await editorPage.addNewBlock( blockNames.paragraph );
const paragraphBlockElement = await editorPage.getBlockAtPosition(
blockNames.paragraph
);
if ( isAndroid() ) {
await paragraphBlockElement.click();
}

await editorPage.sendTextToParagraphBlock( 1, testData.longText );

for ( let i = 3; i > 0; i-- ) {
Expand All @@ -139,23 +98,30 @@ describe( 'Gutenberg Editor tests for Paragraph Block', () => {
testData.lettersInParagraphBlock,
].join( '\n\n' )
);
// // Merge paragraphs.
const secondParagraphBlockElement = await editorPage.getBlockAtPosition(

// Merge paragraphs.
const paragraphBlockElement = await editorPage.getTextBlockAtPosition(
blockNames.paragraph,
2
);

const text0 = await editorPage.getTextForParagraphBlockAtPosition( 1 );
const text1 = await editorPage.getTextForParagraphBlockAtPosition( 2 );

await clickBeginningOfElement(
editorPage.driver,
secondParagraphBlockElement
paragraphBlockElement
);
await editorPage.typeTextToParagraphBlock(
secondParagraphBlockElement,
paragraphBlockElement,
backspace
);

// Verify the editor has not crashed.
const text = await editorPage.getTextForParagraphBlockAtPosition( 1 );
expect( text.length ).not.toEqual( 0 );
const mergedBlockText = await editorPage.getTextForParagraphBlockAtPosition(
1
);
expect( text0 + text1 ).toMatch( mergedBlockText );

await editorPage.removeBlockAtPosition( blockNames.paragraph );
} );
Expand All @@ -168,21 +134,24 @@ describe( 'Gutenberg Editor tests for Paragraph Block', () => {
testData.paragraphBlockEmpty,
].join( '\n\n' )
);
// // Merge paragraphs.
const secondParagraphBlockElement = await editorPage.getBlockAtPosition(

// Merge paragraphs.
const paragraphBlockElement = await editorPage.getTextBlockAtPosition(
blockNames.paragraph,
2
);
await secondParagraphBlockElement.click();
await editorPage.typeTextToParagraphBlock(
secondParagraphBlockElement,
paragraphBlockElement,
backspace
);

// Verify the editor has not crashed.
const text = await editorPage.getTextForParagraphBlockAtPosition( 1 );
expect( text.length ).not.toEqual( 0 );

if ( isAndroid() ) {
await paragraphBlockElement.click();
}
await editorPage.removeBlockAtPosition( blockNames.paragraph );
} );
} );
Loading