-
Notifications
You must be signed in to change notification settings - Fork 799
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
VideoPress: improve buildVideoPressURL(). Add tests. (#28465)
* [not verified] handle files.URLs * [not verified] add tests for URL lib * [not verified] buildVideoPressURL() return empty object * change buildVideoPressURL() return value * changelog * escape . in the RegExp * escape the second dot 🤦
- Loading branch information
Showing
5 changed files
with
91 additions
and
14 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
projects/packages/videopress/changelog/update-videopress-add-url-tests
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,4 @@ | ||
Significance: patch | ||
Type: added | ||
|
||
VideoPress: improve buildVideoPressURL(). Add tests. |
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
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
64 changes: 64 additions & 0 deletions
64
projects/packages/videopress/src/client/lib/url/test/index.ts
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,64 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { buildVideoPressURL } from '..'; | ||
|
||
describe( 'buildVideoPressURL', () => { | ||
it( 'should return empty object when invalid URL', () => { | ||
const result = buildVideoPressURL( 'https://custom-domain.com/v/xyrdcYF4' ); | ||
expect( result ).toStrictEqual( {} ); | ||
} ); | ||
|
||
it( 'should return undefined GUID', () => { | ||
const { guid } = buildVideoPressURL( 'https://custom-domain.com/v/xyrdcYF4' ); | ||
expect( guid ).toBeUndefined(); | ||
} ); | ||
|
||
it( 'should return undefined URL', () => { | ||
const { url } = buildVideoPressURL( 'https://custom-domain.com/v/xyrdcYF4' ); | ||
expect( url ).toBeUndefined(); | ||
} ); | ||
|
||
it( 'should return for videopress.com/v/guid', () => { | ||
const result = buildVideoPressURL( 'https://videopress.com/v/xyrdcYF4' ); | ||
expect( result ).toStrictEqual( { | ||
url: 'https://videopress.com/v/xyrdcYF4', | ||
guid: 'xyrdcYF4', | ||
} ); | ||
} ); | ||
|
||
it( 'should return for videopress.com/embed/guid', () => { | ||
const result = buildVideoPressURL( 'https://videopress.com/embed/xyrdcYF4' ); | ||
expect( result ).toStrictEqual( { | ||
url: 'https://videopress.com/embed/xyrdcYF4', | ||
guid: 'xyrdcYF4', | ||
} ); | ||
} ); | ||
|
||
it( 'should return for video.wordpress.com/v/guid', () => { | ||
const result = buildVideoPressURL( 'https://video.wordpress.com/v/xyrdcYF4' ); | ||
expect( result ).toStrictEqual( { | ||
url: 'https://video.wordpress.com/v/xyrdcYF4', | ||
guid: 'xyrdcYF4', | ||
} ); | ||
} ); | ||
|
||
it( 'should return for video.wordpress.com/embed/guid', () => { | ||
const result = buildVideoPressURL( 'https://video.wordpress.com/embed/xyrdcYF4' ); | ||
expect( result ).toStrictEqual( { | ||
url: 'https://video.wordpress.com/embed/xyrdcYF4', | ||
guid: 'xyrdcYF4', | ||
} ); | ||
} ); | ||
|
||
it( 'should return for video.files.wordpress.com/guid/filename.ext', () => { | ||
const result = buildVideoPressURL( | ||
'https://videos.files.wordpress.com/xyrdcYF4/screen-recording-2023-01-13-at-08.21.53-1.mov' | ||
); | ||
expect( result ).toStrictEqual( { | ||
url: | ||
'https://videos.files.wordpress.com/xyrdcYF4/screen-recording-2023-01-13-at-08.21.53-1.mov', | ||
guid: 'xyrdcYF4', | ||
} ); | ||
} ); | ||
} ); |