-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: added test for twitter youtube and mp3 regex (#563)
- Loading branch information
1 parent
4dd7a6d
commit 23bc80f
Showing
3 changed files
with
38 additions
and
3 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
src/components/AddContentModal/SourceStep/__tests__/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,34 @@ | ||
import { twitterOrYoutubeRegexOrMp3 } from '../utils' | ||
|
||
describe('twitterOrYoutubeRegexOrMp3', () => { | ||
const regex = new RegExp(twitterOrYoutubeRegexOrMp3) | ||
|
||
it('should assert we can check for twitter spaces regex', async () => { | ||
expect(regex.test('https://twitter.com/i/spaces/1zqKVqwrVzlxB?s=20')).toBe(true) | ||
expect(regex.test('twitter.com/i/spaces/1zqKVqwrVzlxB?s=20')).toBe(true) | ||
expect(regex.test('twitter.com')).toBe(false) | ||
expect(regex.test('https://twitter.com')).toBe(false) | ||
expect(regex.test('www.twitter.com')).toBe(false) | ||
expect(regex.test('twitter.org')).toBe(false) | ||
expect(regex.test('facebook.com')).toBe(false) | ||
}) | ||
|
||
it('should assert we can check for youtube regex', async () => { | ||
expect(regex.test('https://www.youtube.com/watch?v=D900-udw9Dw&ab_channel=SwanBitcoin')).toBe(true) | ||
expect(regex.test('www.youtube.com/watch?v=D900-udw9Dw&ab_channel=SwanBitcoin')).toBe(true) | ||
expect(regex.test('youtube.com/watch?v=D900-udw9Dw&ab_channel=SwanBitcoin')).toBe(true) | ||
expect(regex.test('youtube.com')).toBe(false) | ||
expect(regex.test('https://youtube.com')).toBe(false) | ||
expect(regex.test('www.youtube.com')).toBe(false) | ||
expect(regex.test('youtube.org')).toBe(false) | ||
expect(regex.test('facebook.com')).toBe(false) | ||
}) | ||
|
||
it('should assert we can check for mp3 regex', async () => { | ||
expect(regex.test('idkwhat.mp3')).toBe(true) | ||
expect(regex.test('https://idkwhat.mp3')).toBe(true) | ||
expect(regex.test('www.idkwhat.mp3')).toBe(true) | ||
expect(regex.test('idkwhat.org')).toBe(false) | ||
expect(regex.test('facebook.com')).toBe(false) | ||
}) | ||
}) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// This regex is specifically for youtube videos, twitter spaces and mp3 links | ||
export const twitterOrYoutubeRegexOrMp3 = | ||
/^(?:(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/(?:watch\?v=|embed\/)|youtu\.be\/)[\w-]{11}(?:\S*)?|(?:https?:\/\/)?(?:www\.)?twitter\.com\/i\/spaces\/\d+.*$|.+\.mp3)$/i |