From f82dcc198d52d9aaf0d150f30bcecaf052f64204 Mon Sep 17 00:00:00 2001 From: David Calhoun Date: Thu, 13 Apr 2023 09:07:36 -0400 Subject: [PATCH] test: Expand multi-line block tests (#49732) * test: Fix typo in Preformatted test * test: Rich Text helpers can append text The addition of `initialSelectionStart` and `initialSelectEnd` enable placing the caret prior to "typing" additional text. This API was inspired by the `testing-library/user-event` APIs. https://testing-library.com/docs/user-event/utility#type * test: Expand multi-line components typing tests Tests continue typing after inserting a line break now that test helpers support that ability. * test: Fix List block split and merge tests Changes to the `onChangeAndSelectText` helper means text is appended by default. To recreate merely placing the cursor in the beginning of the text, we must re-type the text as the `onChangeAndSelectText` changes the text in addition to selecting due to the selection logic invoking change logic within `RichText`. --- .../src/list/test/edit.native.js | 14 ++++-- .../src/preformatted/test/edit.native.js | 9 ++-- .../src/pullquote/test/edit.native.js | 5 +-- .../src/verse/test/edit.native.js | 5 +-- .../rich-text-change-and-select-text.js | 43 +++++++++++++++---- .../rich-text-change-text.js | 36 +++++++++++++--- 6 files changed, 85 insertions(+), 27 deletions(-) diff --git a/packages/block-library/src/list/test/edit.native.js b/packages/block-library/src/list/test/edit.native.js index 5b70952925cd9a..2c9cbcd43ec3ef 100644 --- a/packages/block-library/src/list/test/edit.native.js +++ b/packages/block-library/src/list/test/edit.native.js @@ -347,7 +347,10 @@ describe( 'List block', () => { // backward delete const listItemField = within( listItemBlock ).getByLabelText( /Text input. .*Two.*/ ); - changeAndSelectTextOfRichText( listItemField, 'Two' ); + changeAndSelectTextOfRichText( listItemField, 'Two', { + initialSelectionStart: 0, + initialSelectionEnd: 3, + } ); fireEvent( listItemField, 'onKeyDown', { nativeEvent: {}, preventDefault() {}, @@ -395,7 +398,10 @@ describe( 'List block', () => { // backward delete const listItemField = within( listItemBlock ).getByLabelText( /Text input. .*One.*/ ); - changeAndSelectTextOfRichText( listItemField, 'One' ); + changeAndSelectTextOfRichText( listItemField, 'One', { + initialSelectionStart: 0, + initialSelectionEnd: 3, + } ); fireEvent( listItemField, 'onKeyDown', { nativeEvent: {}, preventDefault() {}, @@ -406,11 +412,11 @@ describe( 'List block', () => { "

A quick brown fox.

- +

One

- +