Skip to content

Commit

Permalink
Fix e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Aug 7, 2018
1 parent 91dbec9 commit ad5bae6
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/blocks/src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export {
getBlockAttributes,
parseWithAttributeSchema,
} from './parser';
export { default as rawHandler, getPhrasingContentSchema, htmlToBlocks } from './raw-handling';
export { default as rawHandler, getPhrasingContentSchema } from './raw-handling';
export {
default as serialize,
getBlockContent,
Expand Down
25 changes: 25 additions & 0 deletions packages/blocks/src/api/rich-text-structure.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,15 @@ export function apply( value, current, multiline ) {
startContainer.insertData( 0, '\uFEFF' );
range.setStart( startContainer, 1 );
range.setEnd( endContainer, 1 );
} else if (
collapsed &&
startOffset === 0 &&
startContainer === TEXT_NODE &&
startContainer.nodeValue.length === 0
) {
startContainer.insertData( 0, '\uFEFF' );
range.setStart( startContainer, 1 );
range.setEnd( endContainer, 1 );
} else {
range.setStart( startContainer, startOffset );
range.setEnd( endContainer, endOffset );
Expand Down Expand Up @@ -418,6 +427,22 @@ export function toDOM( { value, selection = {} }, multiline, _tag ) {
}, body );
}

if ( start === last || end === last ) {
let pointer = body.lastChild;

if ( pointer.nodeType !== TEXT_NODE ) {
pointer = pointer.parentNode.appendChild( doc.createTextNode( '' ) );
}

if ( start === last ) {
startPath = createPathToNode( pointer, body, [ 0 ] );
}

if ( end === last ) {
endPath = createPathToNode( pointer, body, [ 0 ] );
}
}

return {
body,
selection: { startPath, endPath },
Expand Down
6 changes: 3 additions & 3 deletions packages/editor/src/components/rich-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const settings = {
};

export class RichText extends Component {
constructor() {
constructor( { value } ) {
super( ...arguments );

this.onInit = this.onInit.bind( this );
Expand All @@ -95,6 +95,7 @@ export class RichText extends Component {

this.containerRef = createRef();
this.patterns = patterns.call( this );
this.savedContent = value;

this.state = {
selection: {},
Expand Down Expand Up @@ -601,8 +602,7 @@ export class RichText extends Component {
event.preventDefault();

if ( event.shiftKey || ! this.props.onSplit ) {
const record = richTextStructure.splice( this.getRecord(), undefined, 0, '\n' );
this.onChange( record );
this.editor.execCommand( 'InsertLineBreak', false, event );
} else {
this.splitContent();
}
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/specs/__snapshots__/adding-blocks.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ exports[`adding blocks Should insert content using the placeholder and the regul
<!-- /wp:quote -->
<!-- wp:preformatted -->
<pre class=\\"wp-block-preformatted\\">Pre text<br/><br/>Foo</pre>
<pre class=\\"wp-block-preformatted\\">Pre text<br><br>Foo</pre>
<!-- /wp:preformatted -->
<!-- wp:shortcode -->
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/specs/adding-inline-tokens.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe( 'adding inline tokens', () => {
await page.click( '.media-modal button.media-button-select' );

// Check the content.
const regex = new RegExp( '<!-- wp:paragraph -->\\s*<p>a\\u00A0<img class="wp-image-\\d+" style="width:\\s*10px;?" src="[^"]+\\/' + filename + '\\.png" alt=""\\/><\\/p>\\s*<!-- \\/wp:paragraph -->' );
const regex = new RegExp( '<!-- wp:paragraph -->\\s*<p>a&nbsp;<img class="wp-image-\\d+" style="width:\\s*10px;?" src="[^"]+\\/' + filename + '\\.png" alt=""\\/?><\\/p>\\s*<!-- \\/wp:paragraph -->' );
expect( await getEditedPostContent() ).toMatch( regex );
} );
} );
2 changes: 1 addition & 1 deletion test/e2e/specs/splitting-merging.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe( 'splitting and merging blocks', () => {
await page.keyboard.press( 'Backspace' );

// Replace contents of first paragraph with "Bar".
await pressTimes( 'Backspace', 3 );
await pressTimes( 'Backspace', 4 );
await page.keyboard.type( 'Bar' );

expect( await getEditedPostContent() ).toMatchSnapshot();
Expand Down

0 comments on commit ad5bae6

Please sign in to comment.