Skip to content

Commit

Permalink
Avoid coupling LinkControl test to css class (WordPress#20190)
Browse files Browse the repository at this point in the history
* Select by user-perceivable text content and not CSS selector (implementation detail).

We’ve already seen this test break due to a change in CSS selector. Let’s avoid that in future.

See WordPress@38f4914

* Removes legacy comments

Should have been removed in WordPress@b9f1466
  • Loading branch information
getdave authored Feb 12, 2020
1 parent c553813 commit c7b417d
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions packages/block-editor/src/components/link-control/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,10 @@ describe( 'Basic rendering', () => {
} );

// Click the "Edit" button to trigger into the editing mode.
const editButton = container.querySelector(
'.block-editor-link-control__search-item-action'
);
const editButton = Array.from(
container.querySelectorAll( 'button' )
).find( ( button ) => button.innerHTML.includes( 'Edit' ) );

act( () => {
Simulate.click( editButton );
} );
Expand Down Expand Up @@ -176,7 +177,6 @@ describe( 'Searching for a link', () => {
// fetchFauxEntitySuggestions resolves on next "tick" of event loop
await eventLoopTick();

// TODO: select these by aria relationship to autocomplete rather than arbitary selector.
const searchResultElements = getSearchResults();

let loadingUI = container.querySelector( '.components-spinner' );
Expand Down Expand Up @@ -215,7 +215,6 @@ describe( 'Searching for a link', () => {
// fetchFauxEntitySuggestions resolves on next "tick" of event loop
await eventLoopTick();

// TODO: select these by aria relationship to autocomplete rather than arbitary selector.
const searchResultElements = getSearchResults();

const firstSearchResultItemHTML = first( searchResultElements )
Expand Down Expand Up @@ -263,7 +262,6 @@ describe( 'Searching for a link', () => {
// fetchFauxEntitySuggestions resolves on next "tick" of event loop
await eventLoopTick();

// TODO: select these by aria relationship to autocomplete rather than arbitary selector.
const searchResultElements = getSearchResults();

const lastSearchResultItemHTML = last( searchResultElements )
Expand Down Expand Up @@ -316,7 +314,6 @@ describe( 'Manual link entry', () => {
// fetchFauxEntitySuggestions resolves on next "tick" of event loop
await eventLoopTick();

// TODO: select these by aria relationship to autocomplete rather than arbitary selector.
const searchResultElements = getSearchResults();

const firstSearchResultItemHTML =
Expand Down Expand Up @@ -363,7 +360,6 @@ describe( 'Manual link entry', () => {
// fetchFauxEntitySuggestions resolves on next "tick" of event loop
await eventLoopTick();

// TODO: select these by aria relationship to autocomplete rather than arbitary selector.
const searchResultElements = getSearchResults();

const firstSearchResultItemHTML =
Expand Down Expand Up @@ -400,7 +396,6 @@ describe( 'Default search suggestions', () => {
// Search Input UI
const searchInput = getURLInput();

// TODO: select these by aria relationship to autocomplete rather than arbitary selector.
const searchResultsWrapper = container.querySelector(
'[role="listbox"]'
);
Expand Down Expand Up @@ -496,7 +491,6 @@ describe( 'Default search suggestions', () => {

expect( searchInput.value ).toBe( searchTerm );

// TODO: select these by aria relationship to autocomplete rather than arbitary selector.
searchResultElements = getSearchResults();

// delete the text
Expand All @@ -506,7 +500,6 @@ describe( 'Default search suggestions', () => {

await eventLoopTick();

// TODO: select these by aria relationship to autocomplete rather than arbitary selector.
searchResultElements = getSearchResults();

searchInput = getURLInput();
Expand Down Expand Up @@ -635,7 +628,6 @@ describe( 'Selecting links', () => {
// fetchFauxEntitySuggestions resolves on next "tick" of event loop
await eventLoopTick();

// TODO: select these by aria relationship to autocomplete rather than arbitary selector.
const searchResultElements = getSearchResults();

const firstSearchSuggestion = first( searchResultElements );
Expand Down Expand Up @@ -715,7 +707,6 @@ describe( 'Selecting links', () => {
Simulate.keyDown( searchInput, { keyCode: DOWN } );
} );

// TODO: select these by aria relationship to autocomplete rather than arbitary selector.
const searchResultElements = getSearchResults();

const firstSearchSuggestion = first( searchResultElements );
Expand Down Expand Up @@ -822,7 +813,6 @@ describe( 'Selecting links', () => {

await eventLoopTick();

// TODO: select these by aria relationship to autocomplete rather than arbitary selector.
const searchResultElements = getSearchResults();

const firstSearchSuggestion = first( searchResultElements );
Expand Down

0 comments on commit c7b417d

Please sign in to comment.