Skip to content

Commit

Permalink
Testing: Remove react-test-renderer use (#61263)
Browse files Browse the repository at this point in the history
* Testing: Remove react-test-renderer

* Revert dep removal

Co-authored-by: tyxla <[email protected]>
Co-authored-by: Mamaduka <[email protected]>
  • Loading branch information
3 people authored May 1, 2024
1 parent 3c91548 commit 28054e3
Show file tree
Hide file tree
Showing 14 changed files with 42 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ export const initializeWithBlocksLayouts = async ( blocks ) => {
/**
* Fires long-press gesture event on a block.
*
* @param {import('react-test-renderer').ReactTestInstance} block Block test instance.
* @param {string} testID Id for querying the draggable trigger element.
* @param {Object} [options] Configuration options for the gesture event.
* @param {boolean} [options.failed] Determines if the gesture should fail.
* @param {number} [options.triggerIndex] In case there are multiple draggable triggers, this specifies the index to use.
* @param {HTMLElement} block Block test instance.
* @param {string} testID Id for querying the draggable trigger element.
* @param {Object} [options] Configuration options for the gesture event.
* @param {boolean} [options.failed] Determines if the gesture should fail.
* @param {number} [options.triggerIndex] In case there are multiple draggable triggers, this specifies the index to use.
*/
export const fireLongPress = (
block,
Expand Down Expand Up @@ -140,8 +140,8 @@ export const fireLongPress = (
/**
* Fires pan gesture event on a BlockDraggable component.
*
* @param {import('react-test-renderer').ReactTestInstance} blockDraggable BlockDraggable test instance.
* @param {Object} [touchEvents] Array of touch events to dispatch on the pan gesture.
* @param {HTMLElement} blockDraggable BlockDraggable test instance.
* @param {Object} [touchEvents] Array of touch events to dispatch on the pan gesture.
*/
export const firePanGesture = (
blockDraggable,
Expand Down Expand Up @@ -169,7 +169,7 @@ export const firePanGesture = (
*
* @param {import('@testing-library/react-native').RenderAPI} screen The Testing Library screen.
*
* @return {import('react-test-renderer').ReactTestInstance} Draggable chip test instance.
* @return {HTMLElement} Draggable chip test instance.
*/
export const getDraggableChip = ( { getByTestId } ) => {
let draggableChip;
Expand Down
6 changes: 3 additions & 3 deletions packages/block-library/src/gallery/test/helpers.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ export const initializeWithGalleryBlock = async ( {
/**
* Gets a gallery item within a Gallery block.
*
* @param {import('react-test-renderer').ReactTestInstance} galleryBlock Gallery block instance.
* @param {number} rowIndex Row position within the Gallery block.
* @return {import('react-test-renderer').ReactTestInstance} Gallery item.
* @param {HTMLElement} galleryBlock Gallery block instance.
* @param {number} rowIndex Row position within the Gallery block.
* @return {HTMLElement} Gallery item.
*/
export const getGalleryItem = ( galleryBlock, rowIndex ) =>
getInnerBlock( galleryBlock, 'Image', { rowIndex } );
Expand Down
2 changes: 1 addition & 1 deletion test/native/integration-test-helpers/dismiss-modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { fireEvent } from '@testing-library/react-native';
/**
* Dismisses a modal.
*
* @param {import('react-test-renderer').ReactTestInstance} modalInstance Modal test instance.
* @param {HTMLElement} modalInstance Modal test instance.
*/
export const dismissModal = async ( modalInstance ) =>
fireEvent( modalInstance, 'backdropPress' );
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { openBlockActionsMenu } from './open-block-actions-menu';
*
* @param {import('@testing-library/react-native').RenderAPI} screen A Testing Library screen.
* @param {string} blockName Name of the block.
* @return {[import('react-test-renderer').ReactTestInstance]} Block transform options.
* @return {[HTMLElement]} Block transform options.
*/
export const getBlockTransformOptions = async ( screen, blockName ) => {
const { getByTestId, getByText } = screen;
Expand Down
2 changes: 1 addition & 1 deletion test/native/integration-test-helpers/get-block.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @param {string} blockName Name of the block.
* @param {Object} options Configuration options for getting the block.
* @param {number} [options.rowIndex] Row index of the block.
* @return {import('react-test-renderer').ReactTestInstance} Block instance.
* @return {HTMLElement} Block instance.
*/
export const getBlock = ( screen, blockName, { rowIndex = 1 } = {} ) => {
return screen.getAllByLabelText(
Expand Down
10 changes: 5 additions & 5 deletions test/native/integration-test-helpers/get-inner-block.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import { within } from '@testing-library/react-native';
/**
* Gets an inner block from another block.
*
* @param {import('react-test-renderer').ReactTestInstance} parentBlock Parent block from where to get the block.
* @param {string} blockName Name of the block.
* @param {Object} options Configuration options for getting the block.
* @param {number} [options.rowIndex] Row index of the block.
* @return {import('react-test-renderer').ReactTestInstance} Block instance.
* @param {HTMLElement} parentBlock Parent block from where to get the block.
* @param {string} blockName Name of the block.
* @param {Object} options Configuration options for getting the block.
* @param {number} [options.rowIndex] Row index of the block.
* @return {HTMLElement} Block instance.
*/
export const getInnerBlock = (
parentBlock,
Expand Down
8 changes: 4 additions & 4 deletions test/native/integration-test-helpers/rich-text-paste.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import { fireEvent } from '@testing-library/react-native';
/**
* Paste content into a RichText component.
*
* @param {import('react-test-renderer').ReactTestInstance} richText RichText test instance.
* @param {Object} content Content to paste.
* @param {string} content.text Text format of the content.
* @param {string} [content.html] HTML format of the content. If not provided, text format will be used.
* @param {HTMLElement} richText RichText test instance.
* @param {Object} content Content to paste.
* @param {string} content.text Text format of the content.
* @param {string} [content.html] HTML format of the content. If not provided, text format will be used.
*/
export const pasteIntoRichText = ( richText, { text, html } ) => {
fireEvent( richText, 'focus' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { typeInRichText } from './rich-text-type';
/**
* Select a range within a RichText component.
*
* @param {import('react-test-renderer').ReactTestInstance} richText RichText test instance.
* @param {number} start Selection start position.
* @param {number} end Selection end position.
* @param {HTMLElement} richText RichText test instance.
* @param {number} start Selection start position.
* @param {number} end Selection end position.
*/
export const selectRangeInRichText = ( richText, start, end = start ) => {
if ( typeof start !== 'number' ) {
Expand Down
14 changes: 7 additions & 7 deletions test/native/integration-test-helpers/rich-text-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ function insertTextAtPosition( text, newText, start, end ) {
/**
* Changes the text and selection of a RichText component.
*
* @param {import('react-test-renderer').ReactTestInstance} richText RichText test instance.
* @param {string} text Text to set.
* @param {Object} options Configuration options for selection.
* @param {number} [options.initialSelectionStart] Selection start position before the text is inserted.
* @param {number} [options.initialSelectionEnd] Selection end position before the text is inserted.
* @param {number} [options.finalSelectionStart] Selection start position after the text is inserted.
* @param {number} [options.finalSelectionEnd] Selection end position after the text is inserted.
* @param {HTMLElement} richText RichText test instance.
* @param {string} text Text to set.
* @param {Object} options Configuration options for selection.
* @param {number} [options.initialSelectionStart] Selection start position before the text is inserted.
* @param {number} [options.initialSelectionEnd] Selection end position before the text is inserted.
* @param {number} [options.finalSelectionStart] Selection start position after the text is inserted.
* @param {number} [options.finalSelectionEnd] Selection end position after the text is inserted.
*/
export const typeInRichText = ( richText, text, options = {} ) => {
const currentValueSansOuterHtmlTags = stripOuterHtmlTags(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { fireEvent } from '@testing-library/react-native';
/**
* Changes the text of a TextInput component.
*
* @param {import('react-test-renderer').ReactTestInstance} textInput TextInput test instance.
* @param {string} text Text to be set.
* @param {HTMLElement} textInput TextInput test instance.
* @param {string} text Text to be set.
*/
export const changeTextOfTextInput = ( textInput, text ) => {
fireEvent( textInput, 'focus' );
Expand Down
2 changes: 1 addition & 1 deletion test/native/integration-test-helpers/transform-block.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const apiFetchPromise = Promise.resolve( {} );
* @param {Object} [options] Configuration options for the transformation.
* @param {number} [options.isMediaBlock] True if the block transformation will result in a media block.
* @param {number} [options.hasInnerBlocks] True if the block transformation will result in a block that contains inner blocks.
* @return {import('react-test-renderer').ReactTestInstance} Block instance after the block transformation result.
* @return {HTMLElement} Block instance after the block transformation result.
*/
export const transformBlock = async (
screen,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import { waitForStoreResolvers } from './wait-for-store-resolvers';
* case any of the inner elements use selectors that are associated with store
* resolvers.
*
* @param {import('react-test-renderer').ReactTestInstance} block Block test instance to trigger layout event.
* @param {Object} [options] Configuration options for the event.
* @param {number} [options.width] Width value to be passed to the event.
* @param {number} [options.blockListIndex] Block list index, for cases when there is more than one, like in inner blocks.
* @param {HTMLElement} block Block test instance to trigger layout event.
* @param {Object} [options] Configuration options for the event.
* @param {number} [options.width] Width value to be passed to the event.
* @param {number} [options.blockListIndex] Block list index, for cases when there is more than one, like in inner blocks.
*/
export const triggerBlockListLayout = async (
block,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { waitFor } from '@testing-library/react-native';
/**
* Waits for a modal to be visible.
*
* @param {import('react-test-renderer').ReactTestInstance} modalInstance Modal test instance.
* @param {HTMLElement} modalInstance Modal test instance.
*/
export const waitForModalVisible = async ( modalInstance ) => {
return waitFor( () =>
Expand Down
2 changes: 1 addition & 1 deletion test/native/matchers/to-be-visible.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function isElementVisible( element ) {
* - it is not a "Modal" component or it does not have the prop "visible" set to "false".
* - its ancestor elements are also visible.
*
* @param {import('react-test-renderer').ReactTestInstance} element
* @param {HTMLElement} element
* @return {boolean} True if the given element is visible.
*/
export function toBeVisible( element ) {
Expand Down

0 comments on commit 28054e3

Please sign in to comment.