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

Fixed loss of list content when switching list types. #32432

Merged
merged 8 commits into from
Jun 7, 2021
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
2 changes: 1 addition & 1 deletion packages/block-editor/src/components/rich-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ function RichTextWrapper(
__unstableMultilineTag: multilineTag,
__unstableDisableFormats: disableFormats,
preserveWhiteSpace,
__unstableDependencies: dependencies,
__unstableDependencies: [ ...dependencies, tagName ],
__unstableAfterParse: addEditorOnlyFormats,
__unstableBeforeSerialize: removeEditorOnlyFormats,
__unstableAddInvisibleFormats: addInvisibleFormats,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ exports[`List should insert a line break on shift+enter in a non trailing list i
<!-- /wp:list -->"
`;

exports[`List should not change the contents when you change the list type to Unordered 1`] = `"<li>a</li><li>b</li><li>c</li>"`;

exports[`List should not change the contents when you change the list type to Ordered 1`] = `"<li>1</li><li>2</li><li>3</li>"`;

exports[`List should not indent list on space with modifier 1`] = `
"<!-- wp:list -->
<ul><li>1</li><li> </li></ul>
Expand Down
32 changes: 32 additions & 0 deletions packages/e2e-tests/specs/editor/blocks/list.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -507,4 +507,36 @@ describe( 'List', () => {

expect( await getEditedPostContent() ).toMatchSnapshot();
} );

it( 'should not change the contents when you change the list type to Ordered', async () => {
await clickBlockAppender();
await page.keyboard.type( '* 1' );
await page.keyboard.press( 'Enter' );
await page.keyboard.type( '2' );
await page.keyboard.press( 'Enter' );
await page.keyboard.type( '3' );
await clickBlockToolbarButton( 'Ordered' );

const content = await page.$eval(
'.wp-block-list',
( el ) => el.innerHTML
);
expect( content ).toMatchSnapshot();
Copy link
Member

Choose a reason for hiding this comment

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

Could you use await getEditedPostContent() here?

Copy link
Member

Choose a reason for hiding this comment

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

This is what we use everywhere else to check the edited HTML content 😄

Copy link
Member Author

Choose a reason for hiding this comment

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

@ellatrix
This change could not be tested with getEditedPostContent. Testing with getEditedPostContent passes on the current trunk.

This is because the state of the editor has been changed, but the DOM is not rendered correctly, which causes this problem to persist.

Copy link
Member

Choose a reason for hiding this comment

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

It could if you type another character (make another change)? Anyway, this is fine too :)

} );

it( 'should not change the contents when you change the list type to Unordered', async () => {
await clickBlockAppender();
await page.keyboard.type( '1. a' );
await page.keyboard.press( 'Enter' );
await page.keyboard.type( 'b' );
await page.keyboard.press( 'Enter' );
await page.keyboard.type( 'c' );
await clickBlockToolbarButton( 'Unordered' );

const content = await page.$eval(
'.wp-block-list',
( el ) => el.innerHTML
);
expect( content ).toMatchSnapshot();
} );
} );