Skip to content

Commit

Permalink
Fix typos and remove redundant tests for filterURLForDisplay
Browse files Browse the repository at this point in the history
  • Loading branch information
amitraj2203 committed Jun 6, 2024
1 parent 8a2a592 commit a0c42c8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import useRichUrlData from './use-rich-url-data';
* @return {string} The filtered title.
*/
function filterTitleForDisplay( title ) {
// Dervied from `filterURLForDisplay` in `@wordpress/url`.
// Derived from `filterURLForDisplay` in `@wordpress/url`.
return title
.replace( /^[a-z\-.\+]+[0-9]*:(\/\/)?/i, '' )
.replace( /^www\./i, '' );
Expand Down
21 changes: 3 additions & 18 deletions packages/url/src/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1036,28 +1036,18 @@ describe( 'filterURLForDisplay', () => {
expect( url ).toBe( 'wordpress.org/ig.jpg' );
} );
it( 'should return ellipsis, upper level pieces url, and filename when the url is long enough but filename is short enough', () => {
let url = filterURLForDisplay(
const url = filterURLForDisplay(
'http://www.wordpress.org/wp-content/uploads/myimage.jpg',
20
);
expect( url ).toBe( '…/uploads/myimage.jpg' );
url = filterURLForDisplay(
'file:///home/user/documents/project/reports/2024/myfile.pdf',
20
);
expect( url ).toBe( '…orts/2024/myfile.pdf' );
} );
it( 'should return filename split by ellipsis plus three characters when filename is long enough', () => {
let url = filterURLForDisplay(
const url = filterURLForDisplay(
'http://www.wordpress.org/wp-content/uploads/superlongtitlewithextension.jpeg',
20
);
expect( url ).toBe( 'superlongti…ion.jpeg' );
url = filterURLForDisplay(
'file:///home/user/documents/project/reports/2024/superlongtitlewithextension.pdf',
20
);
expect( url ).toBe( 'superlongtit…ion.pdf' );
} );
it( 'should remove query arguments', () => {
const url = filterURLForDisplay(
Expand All @@ -1074,16 +1064,11 @@ describe( 'filterURLForDisplay', () => {
expect( url ).toBe( 'wordpress.org/wp-content/url/' );
} );
it( 'should return file split by ellipsis when the file name has multiple periods', () => {
let url = filterURLForDisplay(
const url = filterURLForDisplay(
'http://www.wordpress.org/wp-content/uploads/filename.2020.12.20.png',
20
);
expect( url ).toBe( 'filename.202….20.png' );
url = filterURLForDisplay(
'file:///home/user/documents/project/reports/2024/filename.2020.12.20.png',
20
);
expect( url ).toBe( 'filename.202….20.png' );
} );
} );

Expand Down

0 comments on commit a0c42c8

Please sign in to comment.