forked from WordPress/gutenberg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve (and relax) search vs direct URL entry detection in Link Cont…
…rol (WordPress#51011) * Restirct what matches as potentially being a “url” * Remove direct entry results from coming up in entity search suggestions * Make is-url-like stricter * Add initial tests for isURLLike * Improve code with tests and adding check for TLDs * Simply implementation * Fix tests * Test for only showing URL result when searching for URL like * Improve test criteria for URL-like in tests * Augment tests for entity search
- Loading branch information
1 parent
edaa21c
commit ac845b2
Showing
4 changed files
with
198 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
packages/block-editor/src/components/link-control/test/is-url-like.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import isURLLike from '../is-url-like'; | ||
|
||
describe( 'isURLLike', () => { | ||
it.each( [ 'https://wordpress.org', 'http://wordpress.org' ] )( | ||
'returns true for a string that starts with an http(s) protocol', | ||
( testString ) => { | ||
expect( isURLLike( testString ) ).toBe( true ); | ||
} | ||
); | ||
|
||
it.each( [ | ||
'hello world', | ||
'https:// has spaces even though starts with protocol', | ||
'www. wordpress . org', | ||
] )( | ||
'returns false for any string with spaces (e.g. "%s")', | ||
( testString ) => { | ||
expect( isURLLike( testString ) ).toBe( false ); | ||
} | ||
); | ||
|
||
it( 'returns false for a string without a protocol or a TLD', () => { | ||
expect( isURLLike( 'somedirectentryhere' ) ).toBe( false ); | ||
} ); | ||
|
||
it( 'returns true for a string beginning with www.', () => { | ||
expect( isURLLike( 'www.wordpress.org' ) ).toBe( true ); | ||
} ); | ||
|
||
it.each( [ 'mailto:test@wordpress.org', 'tel:123456' ] )( | ||
'returns true for common protocols', | ||
( testString ) => { | ||
expect( isURLLike( testString ) ).toBe( true ); | ||
} | ||
); | ||
|
||
it( 'returns true for internal anchor ("hash") links.', () => { | ||
expect( isURLLike( '#someinternallink' ) ).toBe( true ); | ||
} ); | ||
|
||
// use .each to test multiple cases | ||
it.each( [ | ||
[ true, 'http://example.com' ], | ||
[ true, 'https://test.co.uk?query=param' ], | ||
[ true, 'ftp://openai.ai?param=value#section' ], | ||
[ true, 'example.com' ], | ||
[ true, 'http://example.com?query=param#section' ], | ||
[ true, 'https://test.co.uk/some/path' ], | ||
[ true, 'ftp://openai.ai/some/path' ], | ||
[ true, 'example.org/some/path' ], | ||
[ true, 'example_test.tld' ], | ||
[ true, 'example_test.com' ], | ||
[ false, 'example' ], | ||
[ false, '.com' ], | ||
[ true, '_test.com' ], | ||
[ true, 'http://example_test.com' ], | ||
] )( | ||
'returns %s when testing against string "%s" for a valid TLD', | ||
( expected, testString ) => { | ||
expect( isURLLike( testString ) ).toBe( expected ); | ||
} | ||
); | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters