Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Add tests
  • Loading branch information
kevin940726 committed Aug 28, 2020
commit c182e707630fffb8d980513936268d0f61a832d6
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,29 @@ export const fauxEntitySuggestions = [
{
id: uniqueId(),
title: 'Hello Page',
type: 'Page',
type: 'page',
info: '2 days ago',
url: `?p=${ uniqueId() }`,
},
{
id: uniqueId(),
title: 'Hello Post',
type: 'Post',
type: 'post',
info: '19 days ago',
url: `?p=${ uniqueId() }`,
},
{
id: uniqueId(),
title: 'Hello Another One',
type: 'Page',
type: 'page',
info: '19 days ago',
url: `?p=${ uniqueId() }`,
},
{
id: uniqueId(),
title:
'This is another Post with a much longer title just to be really annoying and to try and break the UI',
type: 'Post',
type: 'post',
info: '1 month ago',
url: `?p=${ uniqueId() }`,
},
Expand Down
75 changes: 71 additions & 4 deletions packages/block-editor/src/components/link-control/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
import { render, unmountComponentAtNode } from 'react-dom';
import { act, Simulate } from 'react-dom/test-utils';
import { queryByText, queryByRole } from '@testing-library/react';
import { first, last, nth, uniqueId } from 'lodash';
/**
* WordPress dependencies
Expand Down Expand Up @@ -1217,10 +1218,9 @@ describe( 'Selecting links', () => {
expect( currentLinkHTML ).toEqual(
expect.stringContaining( selectedLink.title )
);
expect( currentLinkHTML ).toEqual(
expect.stringContaining( selectedLink.type )
);
expect( currentLinkHTML ).toEqual( expect.stringContaining( 'Edit' ) );
expect(
queryByRole( currentLink, 'button', { name: 'Edit' } )
).toBeTruthy();
Comment on lines -1220 to +1223
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed a bad test where it's asserting the HTML to contain a Page text anywhere. It was passing because the text contains Hello Page, but not we want to test against.

Fixed it by using RTL to search for a button with the Edit text.

expect( currentLinkAnchor ).not.toBeNull();
} );

Expand Down Expand Up @@ -1686,3 +1686,70 @@ describe( 'Addition Settings UI', () => {
expect( settingControlsInputs[ 1 ].checked ).toEqual( true );
} );
} );

describe( 'Post types', () => {
it( 'should display post type in search results of link', async () => {
const searchTerm = 'Hello world';

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

// Search Input UI
const searchInput = getURLInput();

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

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

const searchResultElements = getSearchResults();

searchResultElements.forEach( ( resultItem, index ) => {
expect(
queryByText( resultItem, fauxEntitySuggestions[ index ].type )
).toBeTruthy();
} );
} );

it.each( [ 'page', 'post', 'tag', 'post_tag', 'category' ] )(
'should NOT display post type in search results of %s',
async ( postType ) => {
const searchTerm = 'Hello world';

act( () => {
render(
<LinkControl suggestionsQuery={ { type: postType } } />,
container
);
} );

// Search Input UI
const searchInput = getURLInput();

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

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

const searchResultElements = getSearchResults();

searchResultElements.forEach( ( resultItem, index ) => {
expect(
queryByText(
resultItem,
fauxEntitySuggestions[ index ].type
)
).toBeFalsy();
} );
}
);
} );