Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Aljullu committed Oct 25, 2021
1 parent 1baedc2 commit 06f306a
Showing 1 changed file with 68 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* WordPress dependencies
*/
import { addFilter, removeFilter } from '@wordpress/hooks';

/**
* Internal dependencies
*/
Expand Down Expand Up @@ -229,4 +234,67 @@ describe( 'fetchLinkSuggestions', () => {
] )
);
} );
it( 'returns results added by hooks', () => {
addFilter(
'editor.fetchLink.suggestions',
'plugin_link_suggestions',
( results ) => {
return results.concat( [
{
id: 'plugin_case',
url: 'https://www.example.com/',
title: 'Plugin Case',
type: 'custom_link',
},
] );
}
);

return fetchLinkSuggestions( '', {} ).then( ( suggestions ) => {
expect( suggestions[ suggestions.length - 1 ] ).toEqual( {
id: 'plugin_case',
title: 'Plugin Case',
url: 'https://www.example.com/',
type: 'custom_link',
} );
removeFilter(
'editor.fetchLink.suggestions',
'plugin_link_suggestions'
);
} );
} );
it( 'returns results added by async hooks', () => {
addFilter(
'editor.fetchLink.suggestions',
'plugin_link_suggestions',
( results ) => {
return new Promise( ( resolve ) => {
resolve(
results.concat( [
{
id: 'async_plugin_case',
url: 'https://www.example.com/',
title: 'Async Plugin Case',
type: 'custom_link',
},
] )
);
} );
}
);

return fetchLinkSuggestions( '', {} ).then( ( suggestions ) => {
expect( suggestions[ suggestions.length - 1 ] ).toEqual( {
id: 'async_plugin_case',
title: 'Async Plugin Case',
url: 'https://www.example.com/',
type: 'custom_link',
} );

removeFilter(
'editor.fetchLink.suggestions',
'plugin_link_suggestions'
);
} );
} );
} );

0 comments on commit 06f306a

Please sign in to comment.