From 3e423f49cba9455d6364fd7f0dcec78fd0490eae Mon Sep 17 00:00:00 2001 From: Ella van Durpe Date: Thu, 21 Nov 2019 10:10:34 +0100 Subject: [PATCH] Add e2e test --- packages/block-editor/src/store/effects.js | 7 ++++++- .../blocks/__snapshots__/preformatted.test.js.snap | 8 ++++++++ .../specs/editor/blocks/preformatted.test.js | 14 ++++++++++++++ packages/rich-text/README.md | 2 ++ 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/packages/block-editor/src/store/effects.js b/packages/block-editor/src/store/effects.js index f28c53ce221a27..fbfaee23cc715d 100644 --- a/packages/block-editor/src/store/effects.js +++ b/packages/block-editor/src/store/effects.js @@ -135,6 +135,7 @@ export default { selectedBlock.attributes[ attributeKey ] = toHTMLString( { value, multilineTag, + preserveWhiteSpace, } ); } @@ -173,7 +174,11 @@ export default { } ); const newOffset = convertedValue.text.indexOf( START_OF_SELECTED_AREA ); const newValue = remove( convertedValue, newOffset, newOffset + 1 ); - const newHtml = toHTMLString( { value: newValue, multilineTag } ); + const newHtml = toHTMLString( { + value: newValue, + multilineTag, + preserveWhiteSpace, + } ); updatedAttributes[ newAttributeKey ] = newHtml; diff --git a/packages/e2e-tests/specs/editor/blocks/__snapshots__/preformatted.test.js.snap b/packages/e2e-tests/specs/editor/blocks/__snapshots__/preformatted.test.js.snap index 07a70a19a6b2be..37881193bbacad 100644 --- a/packages/e2e-tests/specs/editor/blocks/__snapshots__/preformatted.test.js.snap +++ b/packages/e2e-tests/specs/editor/blocks/__snapshots__/preformatted.test.js.snap @@ -14,3 +14,11 @@ exports[`Preformatted should preserve character newlines 2`] = ` 2 " `; + +exports[`Preformatted should preserve white space when merging 1`] = ` +" +
1
+2
+3
+" +`; diff --git a/packages/e2e-tests/specs/editor/blocks/preformatted.test.js b/packages/e2e-tests/specs/editor/blocks/preformatted.test.js index ea6575785613cf..11a1b0e5b14efd 100644 --- a/packages/e2e-tests/specs/editor/blocks/preformatted.test.js +++ b/packages/e2e-tests/specs/editor/blocks/preformatted.test.js @@ -32,4 +32,18 @@ describe( 'Preformatted', () => { expect( await getEditedPostContent() ).toMatchSnapshot(); } ); + + it( 'should preserve white space when merging', async () => { + await insertBlock( 'Preformatted' ); + await page.keyboard.type( '1' ); + await page.keyboard.press( 'Enter' ); + await page.keyboard.type( '2' ); + await page.keyboard.press( 'Enter' ); + await page.keyboard.press( 'Tab' ); + await page.keyboard.type( '3' ); + await page.keyboard.press( 'ArrowLeft' ); + await page.keyboard.press( 'Backspace' ); + + expect( await getEditedPostContent() ).toMatchSnapshot(); + } ); } ); diff --git a/packages/rich-text/README.md b/packages/rich-text/README.md index e911c714792064..30ed4296d162f7 100644 --- a/packages/rich-text/README.md +++ b/packages/rich-text/README.md @@ -84,6 +84,7 @@ _Parameters_ - _$1.range_ `[Range]`: Range to create value from. - _$1.multilineTag_ `[string]`: Multiline tag if the structure is multiline. - _$1.multilineWrapperTags_ `[Array]`: Tags where lines can be found if nesting is possible. +- _$1.preserveWhiteSpace_ `[?boolean]`: Whether or not to collapse white space characters. _Returns_ @@ -328,6 +329,7 @@ _Parameters_ - _$1_ `Object`: Named argements. - _$1.value_ `Object`: Rich text value. - _$1.multilineTag_ `[string]`: Multiline tag. +- _$1.preserveWhiteSpace_ `[?boolean]`: Whether or not to use newline characters for line breaks. _Returns_