Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RNMobile] Fix act warnings that might be triggered after test finishes #38052

Merged
merged 7 commits into from
Jan 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const initialHtml = `<!-- wp:buttons -->
<div class="wp-block-button"><a class="wp-block-button__link" style="border-radius:5px" >Hello</a></div>
<!-- /wp:button --></div>
<!-- /wp:buttons -->`;
const { getByA11yLabel } = await initializeEditor( {
const { getByA11yLabel } = initializeEditor( {
initialHtml,
} );
```
Expand Down
12 changes: 4 additions & 8 deletions packages/block-library/src/block/test/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,7 @@ describe( 'Reusable block', () => {
return Promise.resolve( response );
} );

const {
getByA11yLabel,
getByTestId,
getByText,
} = await initializeEditor( {
const { getByA11yLabel, getByTestId, getByText } = initializeEditor( {
initialHtml: '',
capabilities: { reusableBlock: true },
} );
Expand All @@ -87,7 +83,7 @@ describe( 'Reusable block', () => {
fireEvent.press( await waitFor( () => getByA11yLabel( 'Add block' ) ) );

// Navigate to reusable tab
const reusableSegment = getByText( 'Reusable' );
const reusableSegment = await waitFor( () => getByText( 'Reusable' ) );
// onLayout event is required by Segment component
fireEvent( reusableSegment, 'layout', {
nativeEvent: {
Expand Down Expand Up @@ -127,7 +123,7 @@ describe( 'Reusable block', () => {
const id = 3;
const initialHtml = `<!-- wp:block {"ref":${ id }} /-->`;

const { getByA11yLabel } = await initializeEditor( {
const { getByA11yLabel } = initializeEditor( {
initialHtml,
} );

Expand Down Expand Up @@ -162,7 +158,7 @@ describe( 'Reusable block', () => {
return Promise.resolve( response );
} );

const { getByA11yLabel } = await initializeEditor( {
const { getByA11yLabel } = initializeEditor( {
initialHtml,
} );

Expand Down
4 changes: 2 additions & 2 deletions packages/block-library/src/buttons/test/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe( 'Buttons block', () => {
<div class="wp-block-button"><a class="wp-block-button__link" style="border-radius:5px" >Hello</a></div>
<!-- /wp:button --></div>
<!-- /wp:buttons -->`;
const { getByA11yLabel } = await initializeEditor( {
const { getByA11yLabel } = initializeEditor( {
initialHtml,
} );

Expand Down Expand Up @@ -90,7 +90,7 @@ describe( 'Buttons block', () => {
const initialHtml = `<!-- wp:buttons -->
<div class="wp-block-buttons"><!-- wp:button /--></div>
<!-- /wp:buttons -->`;
const { getByA11yLabel, getByText } = await initializeEditor( {
const { getByA11yLabel, getByText } = initializeEditor( {
initialHtml,
} );

Expand Down
12 changes: 4 additions & 8 deletions packages/block-library/src/cover/test/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ describe( 'when an image is attached', () => {

describe( 'color settings', () => {
it( 'sets a color for the overlay background when the placeholder is visible', async () => {
const { getByTestId, getByA11yLabel } = await initializeEditor( {
const { getByTestId, getByA11yLabel } = initializeEditor( {
initialHtml: COVER_BLOCK_PLACEHOLDER_HTML,
} );

Expand Down Expand Up @@ -350,7 +350,7 @@ describe( 'color settings', () => {
} );

it( 'sets a gradient overlay background when a solid background was already selected', async () => {
const { getByTestId, getByA11yLabel } = await initializeEditor( {
const { getByTestId, getByA11yLabel } = initializeEditor( {
initialHtml: COVER_BLOCK_SOLID_COLOR_HTML,
} );

Expand Down Expand Up @@ -407,7 +407,7 @@ describe( 'color settings', () => {
} );

it( 'toggles between solid colors and gradients', async () => {
const { getByTestId, getByA11yLabel } = await initializeEditor( {
const { getByTestId, getByA11yLabel } = initializeEditor( {
initialHtml: COVER_BLOCK_PLACEHOLDER_HTML,
} );

Expand Down Expand Up @@ -493,11 +493,7 @@ describe( 'color settings', () => {
} );

it( 'clears the selected overlay color and mantains the inner blocks', async () => {
const {
getByTestId,
getByA11yLabel,
getByText,
} = await initializeEditor( {
const { getByTestId, getByA11yLabel, getByText } = initializeEditor( {
initialHtml: COVER_BLOCK_SOLID_COLOR_HTML,
} );

Expand Down
12 changes: 6 additions & 6 deletions packages/block-library/src/embed/test/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ const mockEmbedResponses = ( mockedResponses ) => {
};

const insertEmbedBlock = async ( blockTitle = 'Embed' ) => {
const editor = await initializeEditor( {
const editor = initializeEditor( {
initialHtml: '',
} );
const { getByA11yLabel, getByText } = editor;
Expand All @@ -162,7 +162,7 @@ const insertEmbedBlock = async ( blockTitle = 'Embed' ) => {
};

const initializeWithEmbedBlock = async ( initialHtml, selectBlock = true ) => {
const editor = await initializeEditor( { initialHtml } );
const editor = initializeEditor( { initialHtml } );
const { getByA11yLabel } = editor;

const block = await waitFor( () =>
Expand Down Expand Up @@ -871,7 +871,7 @@ describe( 'Embed block', () => {
getByPlaceholderText,
getByTestId,
getByText,
} = await initializeEditor( {
} = initializeEditor( {
initialHtml: EMPTY_PARAGRAPH_HTML,
} );

Expand Down Expand Up @@ -914,7 +914,7 @@ describe( 'Embed block', () => {
getByPlaceholderText,
getByTestId,
getByText,
} = await initializeEditor( {
} = initializeEditor( {
initialHtml: EMPTY_PARAGRAPH_HTML,
} );

Expand Down Expand Up @@ -959,7 +959,7 @@ describe( 'Embed block', () => {
getByPlaceholderText,
getByA11yLabel,
getByText,
} = await initializeEditor( { initialHtml: EMPTY_PARAGRAPH_HTML } );
} = initializeEditor( { initialHtml: EMPTY_PARAGRAPH_HTML } );

const paragraphText = getByPlaceholderText( 'Start writing…' );
fireEvent( paragraphText, 'focus' );
Expand Down Expand Up @@ -1001,7 +1001,7 @@ describe( 'Embed block', () => {
getByPlaceholderText,
getByA11yLabel,
getByText,
} = await initializeEditor( {
} = initializeEditor( {
initialHtml: EMPTY_PARAGRAPH_HTML,
} );

Expand Down
24 changes: 17 additions & 7 deletions packages/block-library/src/image/test/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
import { act, fireEvent, initializeEditor, getEditorHtml } from 'test/helpers';
import { Image } from 'react-native';
import Clipboard from '@react-native-clipboard/clipboard';

/**
* WordPress dependencies
Expand Down Expand Up @@ -36,6 +37,9 @@ jest.mock( 'lodash', () => {
const apiFetchPromise = Promise.resolve( {} );
apiFetch.mockImplementation( () => apiFetchPromise );

const clipboardPromise = Promise.resolve( '' );
Clipboard.getString.mockImplementation( () => clipboardPromise );

beforeAll( () => {
registerCoreBlocks();

Expand Down Expand Up @@ -63,7 +67,7 @@ describe( 'Image Block', () => {
</a>
<figcaption>Mountain</figcaption></figure>
<!-- /wp:image -->`;
const screen = await initializeEditor( { initialHtml } );
const screen = initializeEditor( { initialHtml } );
// We must await the image fetch via `getMedia`
await act( () => apiFetchPromise );

Expand All @@ -89,7 +93,7 @@ describe( 'Image Block', () => {
<img src="https://cldup.com/cXyG__fTLN.jpg" alt="" class="wp-image-1"/>
<figcaption>Mountain</figcaption></figure>
<!-- /wp:image -->`;
const screen = await initializeEditor( { initialHtml } );
const screen = initializeEditor( { initialHtml } );
// We must await the image fetch via `getMedia`
await act( () => apiFetchPromise );

Expand All @@ -115,7 +119,7 @@ describe( 'Image Block', () => {
<img src="https://cldup.com/cXyG__fTLN.jpg" alt="" class="wp-image-1"/>
<figcaption>Mountain</figcaption></figure>
<!-- /wp:image -->`;
const screen = await initializeEditor( { initialHtml } );
const screen = initializeEditor( { initialHtml } );
// We must await the image fetch via `getMedia`
await act( () => apiFetchPromise );

Expand All @@ -127,6 +131,8 @@ describe( 'Image Block', () => {
);
fireEvent.press( screen.getByText( 'None' ) );
fireEvent.press( screen.getByText( 'Custom URL' ) );
// Await asynchronous fetch of clipboard
await act( () => clipboardPromise );
fireEvent.changeText(
screen.getByPlaceholderText( 'Search or type URL' ),
'wordpress.org'
Expand All @@ -146,7 +152,7 @@ describe( 'Image Block', () => {
<img src="https://cldup.com/cXyG__fTLN.jpg" alt="" class="wp-image-1"/>
<figcaption>Mountain</figcaption></figure>
<!-- /wp:image -->`;
const screen = await initializeEditor( { initialHtml } );
const screen = initializeEditor( { initialHtml } );
// We must await the image fetch via `getMedia`
await act( () => apiFetchPromise );

Expand All @@ -159,12 +165,16 @@ describe( 'Image Block', () => {
fireEvent.press( screen.getByText( 'None' ) );
fireEvent.press( screen.getByText( 'Media File' ) );
fireEvent.press( screen.getByText( 'Custom URL' ) );
// Await asynchronous fetch of clipboard
await act( () => clipboardPromise );
fireEvent.changeText(
screen.getByPlaceholderText( 'Search or type URL' ),
'wordpress.org'
);
fireEvent.press( screen.getByA11yLabel( 'Apply' ) );
fireEvent.press( screen.getByText( 'Custom URL' ) );
// Await asynchronous fetch of clipboard
await act( () => clipboardPromise );
fireEvent.press( screen.getByText( 'Media File' ) );

const expectedHtml = `<!-- wp:image {"id":1,"sizeSlug":"large","linkDestination":"media","className":"is-style-default"} -->
Expand All @@ -182,7 +192,7 @@ describe( 'Image Block', () => {
</a>
<figcaption>Mountain</figcaption></figure>
<!-- /wp:image -->`;
const screen = await initializeEditor( { initialHtml } );
const screen = initializeEditor( { initialHtml } );
// We must await the image fetch via `getMedia`
await act( () => apiFetchPromise );

Expand All @@ -206,7 +216,7 @@ describe( 'Image Block', () => {
</a>
<figcaption>Mountain</figcaption></figure>
<!-- /wp:image -->`;
const screen = await initializeEditor( { initialHtml } );
const screen = initializeEditor( { initialHtml } );
// We must await the image fetch via `getMedia`
await act( () => apiFetchPromise );

Expand Down Expand Up @@ -237,7 +247,7 @@ describe( 'Image Block', () => {
<figcaption>Mountain</figcaption>
</figure>
<!-- /wp:image -->`;
const screen = await initializeEditor( { initialHtml } );
const screen = initializeEditor( { initialHtml } );
// We must await the image fetch via `getMedia`
await act( () => apiFetchPromise );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe( 'Unsupported block', () => {
const initialHtml = `<!-- wp:table -->
<figure class="wp-block-table"><table><tbody><tr><td>1</td><td>2</td></tr><tr><td>3</td><td>4</td></tr></tbody></table></figure>
<!-- /wp:table -->`;
const { getByA11yLabel } = await initializeEditor( {
const { getByA11yLabel } = initializeEditor( {
initialHtml,
} );

Expand All @@ -59,7 +59,7 @@ describe( 'Unsupported block', () => {
const initialHtml = `<!-- wp:table -->
<figure class="wp-block-table"><table><tbody><tr><td>1</td><td>2</td></tr><tr><td>3</td><td>4</td></tr></tbody></table></figure>
<!-- /wp:table -->`;
const { getByA11yLabel, getByText } = await initializeEditor( {
const { getByA11yLabel, getByText } = initializeEditor( {
initialHtml,
} );

Expand Down
10 changes: 5 additions & 5 deletions packages/components/src/mobile/link-settings/test/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ describe.each( [
it( 'should display the LINK SETTINGS with an EMPTY LINK TO field.', async () => {
// Arrange
const url = 'https://tonytahmouchtest.files.wordpress.com';
const subject = await initializeEditor( { initialHtml } );
const subject = initializeEditor( { initialHtml } );
Clipboard.getString.mockReturnValue( url );

// Act
Expand Down Expand Up @@ -109,7 +109,7 @@ describe.each( [
it( 'should display the LINK PICKER with NO FROM CLIPBOARD CELL.', async () => {
// Arrange
const url = 'tonytahmouchtest.files.wordpress.com';
const subject = await initializeEditor( { initialHtml } );
const subject = initializeEditor( { initialHtml } );
Clipboard.getString.mockReturnValue( url );

// Act
Expand Down Expand Up @@ -162,7 +162,7 @@ describe.each( [
it( 'should display the LINK PICKER with NO FROM CLIPBOARD CELL.', async () => {
// Arrange
const url = 'https://tonytahmouchtest.files.wordpress.com';
const subject = await initializeEditor( { initialHtml } );
const subject = initializeEditor( { initialHtml } );
Clipboard.getString.mockReturnValue( url );

// Act
Expand Down Expand Up @@ -241,7 +241,7 @@ describe.each( [
async () => {
// Arrange
const url = 'https://tonytahmouchtest.files.wordpress.com';
const subject = await initializeEditor( { initialHtml } );
const subject = initializeEditor( { initialHtml } );
Clipboard.getString.mockReturnValue( url );

// Act
Expand Down Expand Up @@ -308,7 +308,7 @@ describe.each( [
async () => {
// Arrange
const url = 'https://tonytahmouchtest.files.wordpress.com';
const subject = await initializeEditor( { initialHtml } );
const subject = initializeEditor( { initialHtml } );
Clipboard.getString.mockReturnValue( url );

// Act
Expand Down
8 changes: 4 additions & 4 deletions packages/format-library/src/text-color/test/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ afterAll( () => {

describe( 'Text color', () => {
it( 'shows the text color formatting button in the toolbar', async () => {
const { getByA11yLabel } = await initializeEditor();
const { getByA11yLabel } = initializeEditor();

// Wait for the editor placeholder
const paragraphPlaceholder = await waitFor( () =>
Expand All @@ -59,7 +59,7 @@ describe( 'Text color', () => {
getByA11yLabel,
getByTestId,
getByA11yHint,
} = await initializeEditor();
} = initializeEditor();

// Wait for the editor placeholder
const paragraphPlaceholder = await waitFor( () =>
Expand Down Expand Up @@ -101,7 +101,7 @@ describe( 'Text color', () => {
getByTestId,
getByPlaceholderText,
getByA11yHint,
} = await initializeEditor();
} = initializeEditor();
const text = 'Hello this is a test';

// Wait for the editor placeholder
Expand Down Expand Up @@ -149,7 +149,7 @@ describe( 'Text color', () => {
} );

it( 'creates a paragraph block with the text color format', async () => {
const { getByA11yLabel } = await initializeEditor( {
const { getByA11yLabel } = initializeEditor( {
initialHtml: TEXT_WITH_COLOR,
} );

Expand Down
4 changes: 2 additions & 2 deletions packages/rich-text/src/test/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,13 +225,13 @@ describe( '<RichText/>', () => {
expect( screen.toJSON() ).toMatchSnapshot();
} );

it( 'renders component with style and font size', async () => {
it( 'renders component with style and font size', () => {
// Arrange
const initialHtml = `<!-- wp:paragraph {"style":{"color":{"text":"#fcb900"},"typography":{"fontSize":35.56}}} -->
<p class="has-text-color" style="color:#fcb900;font-size:35.56px">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed imperdiet ut nibh vitae ornare. Sed auctor nec augue at blandit.</p>
<!-- /wp:paragraph -->`;
// Act
await initializeEditor( { initialHtml } );
initializeEditor( { initialHtml } );
// Assert
expect( getEditorHtml() ).toMatchSnapshot();
} );
Expand Down
Loading