Skip to content

Commit

Permalink
Expect for link field instead block settings button in more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fluiddot committed Nov 9, 2021
1 parent 347f7ff commit cc80690
Showing 1 changed file with 29 additions and 22 deletions.
51 changes: 29 additions & 22 deletions packages/block-library/src/embed/test/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,6 @@ describe( 'Embed block', () => {
const expectedURL = 'https://twitter.com/notnownikki';

const {
getByA11yLabel,
getByPlaceholderText,
getByTestId,
getByText,
Expand All @@ -348,12 +347,15 @@ describe( 'Embed block', () => {
fireEvent( embedEditURLModal, 'backdropPress' );
fireEvent( embedEditURLModal, MODAL_DISMISS_EVENT );

// Wait for block settings button to be present
const settingsButton = await waitFor( () =>
getByA11yLabel( 'Open Settings' )
const blockSettingsModal = await waitFor( () =>
getByTestId( 'block-settings' )
);
// Get Twitter link field
const twitterLinkField = within(
blockSettingsModal
).getByA11yLabel( `Twitter link, ${ expectedURL }` );

expect( settingsButton ).toBeDefined();
expect( twitterLinkField ).toBeDefined();
expect( getEditorHtml() ).toMatchSnapshot();
} );

Expand All @@ -363,11 +365,9 @@ describe( 'Embed block', () => {
// Mock clipboard
Clipboard.getString.mockResolvedValue( clipboardURL );

const {
getByA11yLabel,
getByTestId,
getByText,
} = await initializeWithEmbedBlock( EMPTY_EMBED_HTML );
const { getByTestId, getByText } = await initializeWithEmbedBlock(
EMPTY_EMBED_HTML
);

// Edit URL
fireEvent.press( getByText( 'ADD LINK' ) );
Expand All @@ -383,13 +383,16 @@ describe( 'Embed block', () => {
fireEvent( embedEditURLModal, 'backdropPress' );
fireEvent( embedEditURLModal, MODAL_DISMISS_EVENT );

// Wait for block settings button to be present
const settingsButton = await waitFor( () =>
getByA11yLabel( 'Open Settings' )
const blockSettingsModal = await waitFor( () =>
getByTestId( 'block-settings' )
);
// Get Twitter link field
const twitterLinkField = within(
blockSettingsModal
).getByA11yLabel( `Twitter link, ${ clipboardURL }` );

expect( embedLink ).toBeDefined();
expect( settingsButton ).toBeDefined();
expect( twitterLinkField ).toBeDefined();
expect( getEditorHtml() ).toMatchSnapshot();

Clipboard.getString.mockReset();
Expand Down Expand Up @@ -638,6 +641,8 @@ describe( 'Embed block', () => {

describe( 'retry', () => {
it( 'retries loading the preview if initial request failed', async () => {
const expectedURL = 'https://twitter.com/notnownikki';

// Return bad response for the first request to oembed endpoint
// and success response for the rest of requests.
let isFirstEmbedRequest = true;
Expand All @@ -655,21 +660,23 @@ describe( 'Embed block', () => {
return Promise.resolve( response );
} );

const {
getByA11yLabel,
getByText,
} = await initializeWithEmbedBlock( RICH_TEXT_EMBED_HTML );
const { getByTestId, getByText } = await initializeWithEmbedBlock(
RICH_TEXT_EMBED_HTML
);

// Retry request
fireEvent.press( getByText( 'More options' ) );
fireEvent.press( getByText( 'Retry' ) );

// Wait for Open Settings button to be present
const openSettingsButton = await waitFor( () =>
getByA11yLabel( 'Open Settings' )
const blockSettingsModal = await waitFor( () =>
getByTestId( 'block-settings' )
);
// Get Twitter link field
const twitterLinkField = within(
blockSettingsModal
).getByA11yLabel( `Twitter link, ${ expectedURL }` );

expect( openSettingsButton ).toBeDefined();
expect( twitterLinkField ).toBeDefined();
expect( getEditorHtml() ).toMatchSnapshot();
} );
it( 'converts to link if preview request failed', async () => {
Expand Down

0 comments on commit cc80690

Please sign in to comment.