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

Update/refactor url list #27559

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from 15 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
83 changes: 43 additions & 40 deletions packages/block-editor/src/components/link-control/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,10 @@ describe( 'Basic rendering', () => {
const searchInput = getURLInput();

// Simulate searching for a term
act( () => {
Simulate.change( searchInput, { target: { value: searchTerm } } );
await act( async () => {
Simulate.change( searchInput, {
target: { value: searchTerm },
} );
} );

// fetchFauxEntitySuggestions resolves on next "tick" of event loop
Expand Down Expand Up @@ -231,10 +233,9 @@ describe( 'Searching for a link', () => {
const searchInput = getURLInput();

// Simulate searching for a term
act( () => {
await act( async () => {
Simulate.change( searchInput, { target: { value: searchTerm } } );
} );

// fetchFauxEntitySuggestions resolves on next "tick" of event loop
await eventLoopTick();

Expand All @@ -246,7 +247,7 @@ describe( 'Searching for a link', () => {

expect( loadingUI ).not.toBeNull();

act( () => {
await act( async () => {
resolver( fauxEntitySuggestions );
} );

Expand All @@ -269,7 +270,7 @@ describe( 'Searching for a link', () => {
const searchInput = getURLInput();

// Simulate searching for a term
act( () => {
await act( async () => {
Simulate.change( searchInput, { target: { value: searchTerm } } );
} );

Expand Down Expand Up @@ -316,7 +317,7 @@ describe( 'Searching for a link', () => {
);

// Simulate searching for a term
act( () => {
await act( async () => {
Simulate.change( searchInput, { target: { value: searchTerm } } );
} );

Expand Down Expand Up @@ -366,7 +367,7 @@ describe( 'Searching for a link', () => {
const searchInput = getURLInput();

// Simulate searching for a term
act( () => {
await act( async () => {
Simulate.change( searchInput, {
target: { value: searchTerm },
} );
Expand Down Expand Up @@ -411,7 +412,7 @@ describe( 'Searching for a link', () => {
const searchInput = getURLInput();

// Simulate searching for a term
act( () => {
await act( async () => {
Simulate.change( searchInput, {
target: { value: 'couldbeurlorentitysearchterm' },
} );
Expand Down Expand Up @@ -446,7 +447,7 @@ describe( 'Manual link entry', () => {
const searchInput = getURLInput();

// Simulate searching for a term
act( () => {
await act( async () => {
Simulate.change( searchInput, {
target: { value: searchTerm },
} );
Expand Down Expand Up @@ -492,7 +493,7 @@ describe( 'Manual link entry', () => {
const searchInput = getURLInput();

// Simulate searching for a term
act( () => {
await act( async () => {
Simulate.change( searchInput, {
target: { value: searchTerm },
} );
Expand Down Expand Up @@ -528,7 +529,7 @@ describe( 'Default search suggestions', () => {
it( 'should display a list of initial search suggestions when there is no search value or suggestions', async () => {
const expectedResultsLength = 3; // set within `LinkControl`

act( () => {
await act( async () => {
render( <LinkControl showInitialSuggestions />, container );
} );

Expand Down Expand Up @@ -569,7 +570,7 @@ describe( 'Default search suggestions', () => {
// Render with an initial value an ensure that no initial suggestions
// are shown.
//
act( () => {
await act( async () => {
render(
<LinkControl
showInitialSuggestions
Expand All @@ -590,12 +591,14 @@ describe( 'Default search suggestions', () => {
const currentLinkUI = getCurrentLink();
const currentLinkBtn = currentLinkUI.querySelector( 'button' );

act( () => {
await act( async () => {
Simulate.click( currentLinkBtn );
} );

const searchInput = getURLInput();
searchInput.focus();
await act( async () => {
searchInput.focus();
} );

await eventLoopTick();

Expand All @@ -615,7 +618,7 @@ describe( 'Default search suggestions', () => {
it( 'should display initial suggestions when input value is manually deleted', async () => {
const searchTerm = 'Hello world';

act( () => {
await act( async () => {
render( <LinkControl showInitialSuggestions />, container );
} );

Expand All @@ -626,7 +629,7 @@ describe( 'Default search suggestions', () => {
searchInput = getURLInput();

// Simulate searching for a term
act( () => {
await act( async () => {
Simulate.change( searchInput, { target: { value: searchTerm } } );
} );

Expand All @@ -638,7 +641,7 @@ describe( 'Default search suggestions', () => {
searchResultElements = getSearchResults();

// delete the text
act( () => {
await act( async () => {
Simulate.change( searchInput, { target: { value: '' } } );
} );

Expand Down Expand Up @@ -667,7 +670,7 @@ describe( 'Default search suggestions', () => {
Promise.resolve( noResults )
);

act( () => {
await act( async () => {
render( <LinkControl showInitialSuggestions />, container );
} );

Expand Down Expand Up @@ -745,7 +748,7 @@ describe( 'Creating Entities (eg: Posts, Pages)', () => {
);

// Simulate searching for a term
act( () => {
await act( async () => {
Simulate.change( searchInput, {
target: { value: entityNameText },
} );
Expand Down Expand Up @@ -842,7 +845,7 @@ describe( 'Creating Entities (eg: Posts, Pages)', () => {
);

// Simulate searching for a term
act( () => {
await act( async () => {
Simulate.change( searchInput, {
target: { value: 'Some new page to create' },
} );
Expand Down Expand Up @@ -915,7 +918,7 @@ describe( 'Creating Entities (eg: Posts, Pages)', () => {
);

// Simulate searching for a term
act( () => {
await act( async () => {
Simulate.change( searchInput, {
target: { value: entityNameText },
} );
Expand All @@ -935,11 +938,11 @@ describe( 'Creating Entities (eg: Posts, Pages)', () => {
);

// Step down into the search results, highlighting the first result item
act( () => {
await act( async () => {
Simulate.keyDown( searchInput, { keyCode: DOWN } );
} );

act( () => {
await act( async () => {
Simulate.keyDown( createButton, { keyCode: ENTER } );
} );

Expand Down Expand Up @@ -982,7 +985,7 @@ describe( 'Creating Entities (eg: Posts, Pages)', () => {
);

// Simulate searching for a term
act( () => {
await act( async () => {
Simulate.change( searchInput, {
target: { value: entityNameText },
} );
Expand Down Expand Up @@ -1039,7 +1042,7 @@ describe( 'Creating Entities (eg: Posts, Pages)', () => {
);

it( 'should not show not show an option to create an entity when input is empty', async () => {
act( () => {
await act( async () => {
render(
<LinkControl
showInitialSuggestions={ true } // should show even if we're not showing initial suggestions
Expand Down Expand Up @@ -1093,7 +1096,7 @@ describe( 'Creating Entities (eg: Posts, Pages)', () => {
);

// Simulate searching for a term
act( () => {
await act( async () => {
Simulate.change( searchInput, {
target: { value: inputText },
} );
Expand Down Expand Up @@ -1139,7 +1142,7 @@ describe( 'Creating Entities (eg: Posts, Pages)', () => {
searchInput = container.querySelector( 'input[aria-label="URL"]' );

// Simulate searching for a term
act( () => {
await act( async () => {
Simulate.change( searchInput, {
target: { value: searchText },
} );
Expand Down Expand Up @@ -1302,7 +1305,7 @@ describe( 'Selecting links', () => {
const searchInput = getURLInput();

// Simulate searching for a term
act( () => {
await act( async () => {
Simulate.change( searchInput, {
target: { value: searchTerm },
} );
Expand Down Expand Up @@ -1377,7 +1380,7 @@ describe( 'Selecting links', () => {
const form = container.querySelector( 'form' );

// Simulate searching for a term
act( () => {
await act( async () => {
Simulate.change( searchInput, {
target: { value: searchTerm },
} );
Expand Down Expand Up @@ -1408,7 +1411,7 @@ describe( 'Selecting links', () => {
// Only entity searches contain more than 1 suggestion
if ( type === 'entity' ) {
// Check we can go down again using the down arrow
act( () => {
await act( async () => {
Simulate.keyDown( searchInput, { keyCode: DOWN } );
} );

Expand All @@ -1422,7 +1425,7 @@ describe( 'Selecting links', () => {
);

// Check we can go back up via up arrow
act( () => {
await act( async () => {
Simulate.keyDown( searchInput, { keyCode: UP } );
} );

Expand All @@ -1437,10 +1440,10 @@ describe( 'Selecting links', () => {
}

// Commit the selected item as the current link
act( () => {
await act( async () => {
Simulate.keyDown( searchInput, { keyCode: ENTER } );
} );
act( () => {
await act( async () => {
Simulate.submit( form );
} );

Expand Down Expand Up @@ -1469,7 +1472,7 @@ describe( 'Selecting links', () => {
);

it( 'should allow selection of initial search results via the keyboard', async () => {
act( () => {
await act( async () => {
render( <LinkControl showInitialSuggestions />, container );
} );

Expand All @@ -1491,7 +1494,7 @@ describe( 'Selecting links', () => {
const searchInput = getURLInput();

// Step down into the search results, highlighting the first result item
act( () => {
await act( async () => {
Simulate.keyDown( searchInput, { keyCode: DOWN } );
} );

Expand All @@ -1512,7 +1515,7 @@ describe( 'Selecting links', () => {
);

// Check we can go down again using the down arrow
act( () => {
await act( async () => {
Simulate.keyDown( searchInput, { keyCode: DOWN } );
} );

Expand All @@ -1526,7 +1529,7 @@ describe( 'Selecting links', () => {
);

// Check we can go back up via up arrow
act( () => {
await act( async () => {
Simulate.keyDown( searchInput, { keyCode: UP } );
} );

Expand Down Expand Up @@ -1659,7 +1662,7 @@ describe( 'Post types', () => {
const searchInput = getURLInput();

// Simulate searching for a term
act( () => {
await act( async () => {
Simulate.change( searchInput, { target: { value: searchTerm } } );
} );

Expand Down Expand Up @@ -1691,7 +1694,7 @@ describe( 'Post types', () => {
const searchInput = getURLInput();

// Simulate searching for a term
act( () => {
await act( async () => {
Simulate.change( searchInput, {
target: { value: searchTerm },
} );
Expand Down
Loading