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 17, 2021
1 parent 065032c commit b6ffc61
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/e2e-tests/specs/editor/blocks/post-title.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe( 'Post Title block', () => {
await page.waitForSelector( '.edit-post-layout' );
const title = await page.$eval(
'.editor-post-title__input',
( element ) => element.value
( element ) => element.textContent
);
expect( title ).toEqual( 'Just tweaking the post title' );
} );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ describe( 'Change detection', () => {
// Verify that the title is empty.
const title = await page.$eval(
'.editor-post-title__input',
( element ) => element.innerHTML
( element ) => element.textContent
);
expect( title ).toBe( '' );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ describe( 'Order of block keyboard navigation', () => {
await page.keyboard.press( 'Tab' );
await expect(
await page.evaluate( () => {
return document.activeElement.placeholder;
return document.activeElement.getAttribute( 'aria-label' );
} )
).toBe( 'Add title' );

Expand Down Expand Up @@ -168,7 +168,7 @@ describe( 'Order of block keyboard navigation', () => {
await pressKeyWithModifier( 'shift', 'Tab' );
await expect(
await page.evaluate( () => {
return document.activeElement.placeholder;
return document.activeElement.getAttribute( 'aria-label' );
} )
).toBe( 'Add title' );
} );
Expand Down
10 changes: 7 additions & 3 deletions packages/editor/src/components/post-title/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,16 @@ export default function PostTitle() {
editPost( { title: newTitle } );
}

const [ selection, setSelection ] = useState( {} );

function onSelect() {
setIsSelected( true );
clearSelectedBlock();
}

function onUnselect() {
setIsSelected( false );
setSelection( {} );
}

function onChange( value ) {
Expand Down Expand Up @@ -172,12 +175,12 @@ export default function PostTitle() {
'has-fixed-toolbar': hasFixedToolbar,
}
);
const decodedPlaceholder = decodeEntities( placeholder );
const [ selection, setSelection ] = useState( {} );
const decodedPlaceholder =
decodeEntities( placeholder ) || __( 'Add title' );
const { ref: richTextRef } = useRichText( {
value: title,
onChange,
placeholder: decodedPlaceholder || __( 'Add title' ),
placeholder: decodedPlaceholder,
selectionStart: selection.start,
selectionEnd: selection.end,
onSelectionChange( newStart, newEnd ) {
Expand All @@ -204,6 +207,7 @@ export default function PostTitle() {
ref={ useMergeRefs( [ richTextRef, ref ] ) }
contentEditable
className="editor-post-title__input rich-text"
aria-label={ decodedPlaceholder }
onFocus={ onSelect }
onBlur={ onUnselect }
onKeyDown={ onKeyDown }
Expand Down

0 comments on commit b6ffc61

Please sign in to comment.