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.
Add unit tests for stripDomainPrefixes function
- Loading branch information
1 parent
2802679
commit 2860362
Showing
1 changed file
with
63 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ import { | |
prependHTTPS, | ||
removeQueryArgs, | ||
safeDecodeURI, | ||
stripDomainPrefixes, | ||
} from '../'; | ||
import wptData from './fixtures/wpt-data'; | ||
|
||
|
@@ -127,6 +128,68 @@ describe( 'isValidProtocol', () => { | |
} ); | ||
} ); | ||
|
||
describe( 'stripDomainPrefixes', () => { | ||
it( 'should remove the protocol (http, https, file, tel, etc.) from the URL', () => { | ||
expect( stripDomainPrefixes( 'http://wordpress.org' ) ).toBe( | ||
'wordpress.org' | ||
); | ||
expect( stripDomainPrefixes( 'https://wordpress.org' ) ).toBe( | ||
'wordpress.org' | ||
); | ||
expect( stripDomainPrefixes( 'https://localhost:8080' ) ).toBe( | ||
'localhost:8080' | ||
); | ||
expect( stripDomainPrefixes( 'file:///folder/file.txt' ) ).toBe( | ||
'/folder/file.txt' | ||
); | ||
expect( stripDomainPrefixes( 'ftp://wordpress.org' ) ).toBe( | ||
'wordpress.org' | ||
); | ||
expect( stripDomainPrefixes( 'tel:0123456789' ) ).toBe( '0123456789' ); | ||
expect( stripDomainPrefixes( 'blob:data' ) ).toBe( 'data' ); | ||
} ); | ||
|
||
it( 'should remove both the protocol and www prefix if both are present', () => { | ||
expect( stripDomainPrefixes( 'http://www.google.com' ) ).toBe( | ||
'google.com' | ||
); | ||
expect( stripDomainPrefixes( 'https://www.google.com' ) ).toBe( | ||
'google.com' | ||
); | ||
expect( stripDomainPrefixes( 'ftp://www.google.com' ) ).toBe( | ||
'google.com' | ||
); | ||
} ); | ||
|
||
it( 'should handle URLs without a protocol', () => { | ||
expect( stripDomainPrefixes( 'www.example.com' ) ).toBe( | ||
'example.com' | ||
); | ||
expect( stripDomainPrefixes( 'example.com' ) ).toBe( 'example.com' ); | ||
expect( stripDomainPrefixes( 'example.com/path' ) ).toBe( | ||
'example.com/path' | ||
); | ||
} ); | ||
|
||
it( 'should handle URLs with both parameters and fragments correctly', () => { | ||
expect( | ||
stripDomainPrefixes( | ||
'https://user:[email protected]:1020/test-path/file.extension#anchor?query=params&more' | ||
) | ||
).toBe( | ||
'user:[email protected]:1020/test-path/file.extension#anchor?query=params&more' | ||
); | ||
expect( stripDomainPrefixes( 'https://www.example.com#section' ) ).toBe( | ||
'example.com#section' | ||
); | ||
expect( | ||
stripDomainPrefixes( | ||
'https://www.example.com?param1=value1¶m2=value2' | ||
) | ||
).toBe( 'example.com?param1=value1¶m2=value2' ); | ||
} ); | ||
} ); | ||
|
||
describe( 'getAuthority', () => { | ||
it( 'returns the authority part of a URL', () => { | ||
expect( | ||
|