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

Fix: Quote to heading transform; Add end 2 end tests for the transform. #14348

Merged
merged 1 commit into from
Mar 10, 2019
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
30 changes: 18 additions & 12 deletions packages/block-library/src/quote/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,21 +186,27 @@ export const settings = {
}

const pieces = split( create( { html: value, multilineTag: 'p' } ), '\u2028' );

const headingBlock = createBlock( 'core/heading', {
content: toHTMLString( { value: pieces[ 0 ] } ),
} );

if ( ! citation && pieces.length === 1 ) {
return headingBlock;
}

const quotePieces = pieces.slice( 1 );

return [
createBlock( 'core/heading', {
content: toHTMLString( { value: pieces[ 0 ] } ),
} ),
createBlock( 'core/quote', {
...attrs,
citation,
value: toHTMLString( {
value: quotePieces.length ? join( pieces.slice( 1 ), '\u2028' ) : create(),
multilineTag: 'p',
} ),
const quoteBlock = createBlock( 'core/quote', {
...attrs,
citation,
value: toHTMLString( {
value: quotePieces.length ? join( pieces.slice( 1 ), '\u2028' ) : create(),
multilineTag: 'p',
} ),
];
} );

return [ headingBlock, quoteBlock ];
},
},

Expand Down
108 changes: 70 additions & 38 deletions packages/e2e-tests/specs/blocks/__snapshots__/quote.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,6 @@ exports[`Quote can be converted to a pullquote 1`] = `
<!-- /wp:pullquote -->"
`;

exports[`Quote can be converted to headings 1`] = `
"<!-- wp:heading -->
<h2>one</h2>
<!-- /wp:heading -->

<!-- wp:quote -->
<blockquote class=\\"wp-block-quote\\"><p>two</p><cite>cite</cite></blockquote>
<!-- /wp:quote -->"
`;

exports[`Quote can be converted to headings 2`] = `
"<!-- wp:heading -->
<h2>one</h2>
<!-- /wp:heading -->

<!-- wp:heading -->
<h2>two</h2>
<!-- /wp:heading -->

<!-- wp:quote -->
<blockquote class=\\"wp-block-quote\\"><p></p><cite>cite</cite></blockquote>
<!-- /wp:quote -->"
`;

exports[`Quote can be converted to headings 3`] = `
"<!-- wp:heading -->
<h2>one</h2>
<!-- /wp:heading -->

<!-- wp:heading -->
<h2>two</h2>
<!-- /wp:heading -->

<!-- wp:heading -->
<h2>cite</h2>
<!-- /wp:heading -->"
`;

exports[`Quote can be converted to paragraphs and renders a paragraph for the cite, if it exists 1`] = `
"<!-- wp:paragraph -->
<p>one</p>
Expand Down Expand Up @@ -117,3 +79,73 @@ exports[`Quote can be merged into from a paragraph 1`] = `
<blockquote class=\\"wp-block-quote\\"><p>test</p></blockquote>
<!-- /wp:quote -->"
`;

exports[`Quote is transformed to a heading and a quote if the quote contains a citation 1`] = `
"<!-- wp:heading -->
<h2>one</h2>
<!-- /wp:heading -->

<!-- wp:quote -->
<blockquote class=\\"wp-block-quote\\"><p></p><cite>cite</cite></blockquote>
<!-- /wp:quote -->"
`;

exports[`Quote is transformed to a heading and a quote if the quote contains multiple paragraphs 1`] = `
"<!-- wp:heading -->
<h2>one</h2>
<!-- /wp:heading -->

<!-- wp:quote -->
<blockquote class=\\"wp-block-quote\\"><p>two</p><p>three</p></blockquote>
<!-- /wp:quote -->"
`;

exports[`Quote is transformed to a heading if the quote just contains one paragraph 1`] = `
"<!-- wp:heading -->
<h2>one</h2>
<!-- /wp:heading -->"
`;

exports[`Quote is transformed to an empty heading if the quote is empty 1`] = `
"<!-- wp:heading -->
<h2></h2>
<!-- /wp:heading -->"
`;

exports[`Quote the resuling quote after transforming to a heading can be transformed again 1`] = `
"<!-- wp:heading -->
<h2>one</h2>
<!-- /wp:heading -->

<!-- wp:quote -->
<blockquote class=\\"wp-block-quote\\"><p>two</p><cite>cite</cite></blockquote>
<!-- /wp:quote -->"
`;

exports[`Quote the resuling quote after transforming to a heading can be transformed again 2`] = `
"<!-- wp:heading -->
<h2>one</h2>
<!-- /wp:heading -->

<!-- wp:heading -->
<h2>two</h2>
<!-- /wp:heading -->

<!-- wp:quote -->
<blockquote class=\\"wp-block-quote\\"><p></p><cite>cite</cite></blockquote>
<!-- /wp:quote -->"
`;

exports[`Quote the resuling quote after transforming to a heading can be transformed again 3`] = `
"<!-- wp:heading -->
<h2>one</h2>
<!-- /wp:heading -->

<!-- wp:heading -->
<h2>two</h2>
<!-- /wp:heading -->

<!-- wp:heading -->
<h2>cite</h2>
<!-- /wp:heading -->"
`;
35 changes: 34 additions & 1 deletion packages/e2e-tests/specs/blocks/quote.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,40 @@ describe( 'Quote', () => {
expect( await getEditedPostContent() ).toMatchSnapshot();
} );

it( 'can be converted to headings', async () => {
it( 'is transformed to an empty heading if the quote is empty', async () => {
await insertBlock( 'Quote' );
await transformBlockTo( 'Heading' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );

it( 'is transformed to a heading if the quote just contains one paragraph', async () => {
await insertBlock( 'Quote' );
await page.keyboard.type( 'one' );
await transformBlockTo( 'Heading' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );

it( 'is transformed to a heading and a quote if the quote contains multiple paragraphs', async () => {
await insertBlock( 'Quote' );
await page.keyboard.type( 'one' );
await page.keyboard.press( 'Enter' );
await page.keyboard.type( 'two' );
await page.keyboard.press( 'Enter' );
await page.keyboard.type( 'three' );
await transformBlockTo( 'Heading' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );

it( 'is transformed to a heading and a quote if the quote contains a citation', async () => {
await insertBlock( 'Quote' );
await page.keyboard.type( 'one' );
await page.keyboard.press( 'Tab' );
await page.keyboard.type( 'cite' );
await transformBlockTo( 'Heading' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );

it( 'the resuling quote after transforming to a heading can be transformed again', async () => {
await insertBlock( 'Quote' );
await page.keyboard.type( 'one' );
await page.keyboard.press( 'Enter' );
Expand Down