Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
d4e140f
Upgrade React packages to v18
jsnajdr Oct 24, 2022
3cc35fd
Upgrade framer-motion to get React 18 support and updated types
jsnajdr Oct 25, 2022
7af9bf2
React Native: upgrade to 0.69.4
jsnajdr Oct 31, 2022
b9d3d28
React Native: upgrade libraries
jsnajdr Nov 28, 2022
ea93ff0
LinkControl: fix unit tests
jsnajdr Nov 16, 2022
05da41f
Components: fix unit tests
jsnajdr Oct 26, 2022
9408a92
Block Editor: fix unit tests
jsnajdr Oct 27, 2022
382359b
NUX: fix unit tests
jsnajdr Oct 27, 2022
61e8e7a
useSelect: fix unit tests (partially)
jsnajdr Oct 28, 2022
23fb060
LinkSettings test: fix finding blocks by label text
jsnajdr Oct 31, 2022
b712d42
BlockDraggable test: fix finding blocks by label text
jsnajdr Oct 31, 2022
d253cdb
React Native test helpers: fix getting blocks
jsnajdr Oct 31, 2022
637ce64
Block Library tests: fix finding blocks by label text
jsnajdr Oct 31, 2022
6da1678
ToggleGroupControl: fix unit test by waiting for tooltip
jsnajdr Nov 18, 2022
cd42397
File Block: update snapshots to account for empty children
jsnajdr Nov 18, 2022
9f7c332
Embed native tests: improve mocked API response
jsnajdr Nov 21, 2022
4de9c4a
Embed native tests: wait for rich preview to appear
jsnajdr Nov 21, 2022
c9b9bd6
Format Library: fix finding blocks by label text
jsnajdr Nov 21, 2022
7fb330c
Edit Post: fix finding blocks by label text
jsnajdr Nov 21, 2022
4edb25f
Update native snapshots
tyxla Nov 23, 2022
7774a2f
useNestedSettingsUpdate: deoptimize/unbatch dispatching the updateBlo…
jsnajdr Nov 27, 2022
78faaeb
Color Palette: wait for dropdown to appear
jsnajdr Nov 27, 2022
807bcea
Add custom Jest matcher: toBePositionedPopover
jsnajdr Nov 28, 2022
595ce61
Use toBePositionedPopover matcher in tests
jsnajdr Nov 28, 2022
bb2595d
Mobile - Update tests
Oct 5, 2022
36de541
Mobile - Update gitignore
Oct 5, 2022
34c9c7f
Mobile - Update ruby config
Oct 5, 2022
3271c32
[Mobile] - React Native 0.69.4 Upgrade - Android (#43486)
Oct 11, 2022
c0adb62
[Mobile] - React Native 0.69.4 Upgrade - iOS
derekblank Oct 18, 2022
c9c71e7
Mobile - Check for a local bundle running with metro and use a jsbund…
Oct 21, 2022
d016b5d
Remove duplicated import of Gesture handler
Oct 30, 2022
e7bacd7
Remove deprecated initialization for Reanimated
Nov 2, 2022
d19e915
Update Podfile.lock after updating dependencies
Nov 28, 2022
69444f7
Remove React peer deps from packages that don't need them
jsnajdr Nov 30, 2022
259e3bb
Add changelog entries about React 18 upgrade
jsnajdr Nov 30, 2022
16d1ec2
Extract useIsScreenReaderEnabled hook, set state only if enabled=true
jsnajdr Nov 30, 2022
6e704aa
Mobile - Update Podfile.lock
Dec 1, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Block Library tests: fix finding blocks by label text
  • Loading branch information
jsnajdr committed Dec 1, 2022
commit 637ce6499720b1bd5cdec089b948d284752ce007
58 changes: 27 additions & 31 deletions packages/block-library/src/block/test/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
getEditorHtml,
initializeEditor,
fireEvent,
waitFor,
within,
} from 'test/helpers';

Expand Down Expand Up @@ -78,17 +77,16 @@ describe( 'Reusable block', () => {
return Promise.resolve( response );
} );

const { getByLabelText, getByTestId, getByText } =
await initializeEditor( {
initialHtml: '',
capabilities: { reusableBlock: true },
} );
const screen = await initializeEditor( {
initialHtml: '',
capabilities: { reusableBlock: true },
} );

// Open the inserter menu.
fireEvent.press( await waitFor( () => getByLabelText( 'Add block' ) ) );
fireEvent.press( await screen.findByLabelText( 'Add block' ) );

// Navigate to reusable tab.
const reusableSegment = await waitFor( () => getByText( 'Reusable' ) );
const reusableSegment = await screen.findByText( 'Reusable' );
// onLayout event is required by Segment component.
fireEvent( reusableSegment, 'layout', {
nativeEvent: {
Expand All @@ -99,7 +97,9 @@ describe( 'Reusable block', () => {
} );
fireEvent.press( reusableSegment );

const reusableBlockList = getByTestId( 'InserterUI-ReusableBlocks' );
const reusableBlockList = screen.getByTestId(
'InserterUI-ReusableBlocks'
);
// onScroll event used to force the FlatList to render all items.
fireEvent.scroll( reusableBlockList, {
nativeEvent: {
Expand All @@ -110,13 +110,11 @@ describe( 'Reusable block', () => {
} );

// Insert a reusable block.
fireEvent.press(
await waitFor( () => getByText( `Reusable block - 1` ) )
);
fireEvent.press( await screen.findByText( `Reusable block - 1` ) );

// Get the reusable block.
const reusableBlock = await waitFor( () =>
getByLabelText( /Reusable block Block\. Row 1/ )
const [ reusableBlock ] = await screen.findAllByLabelText(
/Reusable block Block\. Row 1/
);

expect( reusableBlock ).toBeDefined();
Expand All @@ -128,18 +126,16 @@ describe( 'Reusable block', () => {
const id = 3;
const initialHtml = `<!-- wp:block {"ref":${ id }} /-->`;

const { getByLabelText } = await initializeEditor( {
const screen = await initializeEditor( {
initialHtml,
} );

const reusableBlock = await waitFor( () =>
getByLabelText( /Reusable block Block\. Row 1/ )
const [ reusableBlock ] = await screen.findAllByLabelText(
/Reusable block Block\. Row 1/
);

const blockDeleted = await waitFor( () =>
within( reusableBlock ).getByText(
'Block has been deleted or is unavailable.'
)
const blockDeleted = within( reusableBlock ).getByText(
'Block has been deleted or is unavailable.'
);

expect( reusableBlock ).toBeDefined();
Expand All @@ -163,17 +159,17 @@ describe( 'Reusable block', () => {
return Promise.resolve( response );
} );

const { getByLabelText } = await initializeEditor( {
const screen = await initializeEditor( {
initialHtml,
} );

const reusableBlock = await waitFor( () =>
getByLabelText( /Reusable block Block\. Row 1/ )
const [ reusableBlock ] = await screen.findByLabelText(
/Reusable block Block\. Row 1/
);

const innerBlockListWrapper = await waitFor( () =>
within( reusableBlock ).getByTestId( 'block-list-wrapper' )
);
const innerBlockListWrapper = await within(
reusableBlock
).findByTestId( 'block-list-wrapper' );

// onLayout event has to be explicitly dispatched in BlockList component,
// otherwise the inner blocks are not rendered.
Expand All @@ -185,10 +181,10 @@ describe( 'Reusable block', () => {
},
} );

const headingInnerBlock = await waitFor( () =>
within( reusableBlock ).getByLabelText(
'Heading Block. Row 1. Level 2. First Reusable block'
)
const [ headingInnerBlock ] = await within(
reusableBlock
).findAllByLabelText(
'Heading Block. Row 1. Level 2. First Reusable block'
);

expect( reusableBlock ).toBeDefined();
Expand Down
91 changes: 40 additions & 51 deletions packages/block-library/src/buttons/test/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
*/
import {
fireEvent,
waitFor,
getEditorHtml,
within,
getBlock,
Expand Down Expand Up @@ -50,20 +49,20 @@ describe( 'Buttons block', () => {
<div class="wp-block-button"><a class="wp-block-button__link wp-element-button" style="border-radius:5px" >Hello</a></div>
<!-- /wp:button --></div>
<!-- /wp:buttons -->`;
const { getByLabelText } = await initializeEditor( {
const editor = await initializeEditor( {
initialHtml,
} );

const buttonsBlock = await waitFor( () =>
getByLabelText( /Buttons Block\. Row 1/ )
const [ buttonsBlock ] = await editor.findAllByLabelText(
/Buttons Block\. Row 1/
);
fireEvent.press( buttonsBlock );

// onLayout event has to be explicitly dispatched in BlockList component,
// otherwise the inner blocks are not rendered.
const innerBlockListWrapper = await waitFor( () =>
within( buttonsBlock ).getByTestId( 'block-list-wrapper' )
);
const innerBlockListWrapper = await within(
buttonsBlock
).findByTestId( 'block-list-wrapper' );
fireEvent( innerBlockListWrapper, 'layout', {
nativeEvent: {
layout: {
Expand All @@ -72,22 +71,22 @@ describe( 'Buttons block', () => {
},
} );

const buttonInnerBlock = await waitFor( () =>
within( buttonsBlock ).getByLabelText( /Button Block\. Row 1/ )
);
const [ buttonInnerBlock ] = await within(
buttonsBlock
).findAllByLabelText( /Button Block\. Row 1/ );
fireEvent.press( buttonInnerBlock );

const settingsButton = await waitFor( () =>
getByLabelText( 'Open Settings' )
const settingsButton = await editor.findByLabelText(
'Open Settings'
);
fireEvent.press( settingsButton );

const radiusStepper = await waitFor( () =>
getByLabelText( /Border Radius/ )
const radiusStepper = await editor.findByLabelText(
/Border Radius/
);

const incrementButton = await waitFor( () =>
within( radiusStepper ).getByTestId( 'Increment' )
const incrementButton = await within( radiusStepper ).findByTestId(
'Increment'
);
fireEvent( incrementButton, 'onPressIn' );

Expand All @@ -98,15 +97,14 @@ describe( 'Buttons block', () => {
const screen = await initializeEditor( {
initialHtml: BUTTONS_HTML,
} );
const { getByLabelText } = screen;

// Get block
const buttonsBlock = await getBlock( screen, 'Buttons' );

// Trigger inner blocks layout
const innerBlockListWrapper = await waitFor( () =>
within( buttonsBlock ).getByTestId( 'block-list-wrapper' )
);
const innerBlockListWrapper = await within(
buttonsBlock
).findByTestId( 'block-list-wrapper' );
fireEvent( innerBlockListWrapper, 'layout', {
nativeEvent: {
layout: {
Expand All @@ -125,14 +123,14 @@ describe( 'Buttons block', () => {
fireEvent.press( appenderButton );

// Check for new button
const secondButtonBlock = await waitFor( () =>
within( buttonsBlock ).getByLabelText( /Button Block\. Row 2/ )
);
const [ secondButtonBlock ] = await within(
buttonsBlock
).findAllByLabelText( /Button Block\. Row 2/ );
expect( secondButtonBlock ).toBeVisible();

// Add a Paragraph block using the empty placeholder at the bottom
const paragraphPlaceholder = await waitFor( () =>
getByLabelText( 'Add paragraph block' )
const paragraphPlaceholder = await screen.findByLabelText(
'Add paragraph block'
);
fireEvent.press( paragraphPlaceholder );

Expand All @@ -148,21 +146,15 @@ describe( 'Buttons block', () => {
const screen = await initializeEditor( {
initialHtml: BUTTONS_HTML,
} );
const {
getByLabelText,
getByTestId,
queryAllByLabelText,
getByText,
} = screen;

// Get block
const buttonsBlock = await getBlock( screen, 'Buttons' );
fireEvent.press( buttonsBlock );

// Trigger inner blocks layout
const innerBlockListWrapper = await waitFor( () =>
within( buttonsBlock ).getByTestId( 'block-list-wrapper' )
);
const innerBlockListWrapper = await within(
buttonsBlock
).findByTestId( 'block-list-wrapper' );
fireEvent( innerBlockListWrapper, 'layout', {
nativeEvent: {
layout: {
Expand All @@ -176,9 +168,9 @@ describe( 'Buttons block', () => {
fireEvent.press( buttonBlock );

// Open the block inserter
fireEvent.press( getByLabelText( 'Add block' ) );
fireEvent.press( screen.getByLabelText( 'Add block' ) );

const blockList = getByTestId( 'InserterUI-Blocks' );
const blockList = screen.getByTestId( 'InserterUI-Blocks' );
// onScroll event used to force the FlatList to render all items
fireEvent.scroll( blockList, {
nativeEvent: {
Expand All @@ -190,11 +182,11 @@ describe( 'Buttons block', () => {

// Check the Add block here placeholder is not visible
const addBlockHerePlaceholders =
queryAllByLabelText( 'ADD BLOCK HERE' );
screen.queryAllByLabelText( 'ADD BLOCK HERE' );
expect( addBlockHerePlaceholders.length ).toBe( 0 );

// Add a new Button block
fireEvent.press( await waitFor( () => getByText( 'Button' ) ) );
fireEvent.press( await screen.findByText( 'Button' ) );

// Get new button
const secondButtonBlock = await getBlock( screen, 'Button', {
Expand All @@ -214,15 +206,14 @@ describe( 'Buttons block', () => {
const screen = await initializeEditor( {
initialHtml: BUTTONS_HTML,
} );
const { getByLabelText } = screen;

// Get block
const buttonsBlock = await getBlock( screen, 'Buttons' );

// Trigger inner blocks layout
const innerBlockListWrapper = await waitFor( () =>
within( buttonsBlock ).getByTestId( 'block-list-wrapper' )
);
const innerBlockListWrapper = await within(
buttonsBlock
).findByTestId( 'block-list-wrapper' );
fireEvent( innerBlockListWrapper, 'layout', {
nativeEvent: {
layout: {
Expand All @@ -236,13 +227,13 @@ describe( 'Buttons block', () => {
fireEvent.press( buttonBlock );

// Open block actions menu
const blockActionsButton = getByLabelText(
const blockActionsButton = screen.getByLabelText(
/Open Block Actions Menu/
);
fireEvent.press( blockActionsButton );

// Delete block
const deleteButton = getByLabelText( /Remove block/ );
const deleteButton = screen.getByLabelText( /Remove block/ );
fireEvent.press( deleteButton );

expect( getEditorHtml() ).toMatchSnapshot();
Expand All @@ -260,22 +251,20 @@ describe( 'Buttons block', () => {
const initialHtml = `<!-- wp:buttons -->
<div class="wp-block-buttons"><!-- wp:button /--></div>
<!-- /wp:buttons -->`;
const { getByLabelText, getByText } = await initializeEditor( {
initialHtml,
} );
const screen = await initializeEditor( { initialHtml } );

const block = await waitFor( () =>
getByLabelText( /Buttons Block\. Row 1/ )
const [ block ] = await screen.findAllByLabelText(
/Buttons Block\. Row 1/
);
fireEvent.press( block );

fireEvent.press(
getByLabelText( 'Change items justification' )
screen.getByLabelText( 'Change items justification' )
);

// Select alignment option.
fireEvent.press(
await waitFor( () => getByText( justificationOption ) )
await screen.findByText( justificationOption )
);

expect( getEditorHtml() ).toMatchSnapshot();
Expand Down
Loading