Background running for downloads/auto-download, library clipboard detect, updater auth (#7)
Co-authored-by: Wayne <bontragerl464@gmail.com> Co-committed-by: Wayne <bontragerl464@gmail.com>
This commit was merged in pull request #7.
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { looksLikeUrl, looksLikeSingleVideo } from '../src/renderer/src/useClipboardLink'
|
||||
|
||||
describe('looksLikeUrl', () => {
|
||||
it('accepts http(s) URLs', () => {
|
||||
expect(looksLikeUrl('https://youtube.com/watch?v=abc')).toBe(true)
|
||||
expect(looksLikeUrl('http://example.com')).toBe(true)
|
||||
expect(looksLikeUrl('https://example.com/a/b?c=d#frag')).toBe(true)
|
||||
})
|
||||
|
||||
it('is scheme-case-insensitive', () => {
|
||||
expect(looksLikeUrl('HTTPS://example.com')).toBe(true)
|
||||
expect(looksLikeUrl('HtTp://example.com')).toBe(true)
|
||||
})
|
||||
|
||||
it('trims surrounding whitespace', () => {
|
||||
expect(looksLikeUrl(' https://example.com\n')).toBe(true)
|
||||
expect(looksLikeUrl('\t http://example.com \t')).toBe(true)
|
||||
})
|
||||
|
||||
it('rejects non-http(s) schemes', () => {
|
||||
expect(looksLikeUrl('ftp://example.com')).toBe(false)
|
||||
expect(looksLikeUrl('file:///c:/x')).toBe(false)
|
||||
expect(looksLikeUrl('magnet:?xt=urn:btih:abc')).toBe(false)
|
||||
expect(looksLikeUrl('javascript:alert(1)')).toBe(false)
|
||||
expect(looksLikeUrl('mailto:a@b.com')).toBe(false)
|
||||
})
|
||||
|
||||
it('rejects bare domains and scheme-less text', () => {
|
||||
expect(looksLikeUrl('www.example.com')).toBe(false)
|
||||
expect(looksLikeUrl('example.com/watch')).toBe(false)
|
||||
expect(looksLikeUrl('see http://example.com')).toBe(false) // must start with the scheme
|
||||
})
|
||||
|
||||
it('rejects empty, whitespace, and malformed input', () => {
|
||||
expect(looksLikeUrl('')).toBe(false)
|
||||
expect(looksLikeUrl(' ')).toBe(false)
|
||||
expect(looksLikeUrl('not a link')).toBe(false)
|
||||
expect(looksLikeUrl('http://')).toBe(false) // passes the prefix test but is not a valid URL
|
||||
})
|
||||
})
|
||||
|
||||
describe('looksLikeSingleVideo', () => {
|
||||
it('flags YouTube single-video URLs', () => {
|
||||
expect(looksLikeSingleVideo('https://www.youtube.com/watch?v=dQw4w9WgXcQ')).toBe(true)
|
||||
expect(looksLikeSingleVideo('https://youtube.com/watch?v=abc123')).toBe(true)
|
||||
expect(looksLikeSingleVideo('https://m.youtube.com/watch?v=abc123')).toBe(true)
|
||||
expect(looksLikeSingleVideo('https://music.youtube.com/watch?v=abc123')).toBe(true)
|
||||
expect(looksLikeSingleVideo('https://youtu.be/dQw4w9WgXcQ')).toBe(true)
|
||||
})
|
||||
|
||||
it('keeps anything with a playlist context (?list=)', () => {
|
||||
// A video opened in a playlist → the user likely wants the whole playlist.
|
||||
expect(looksLikeSingleVideo('https://www.youtube.com/watch?v=abc&list=PL123')).toBe(false)
|
||||
expect(looksLikeSingleVideo('https://youtu.be/abc?list=PL123')).toBe(false)
|
||||
})
|
||||
|
||||
it('keeps channels and playlists', () => {
|
||||
expect(looksLikeSingleVideo('https://www.youtube.com/@SomeChannel')).toBe(false)
|
||||
expect(looksLikeSingleVideo('https://www.youtube.com/channel/UC123')).toBe(false)
|
||||
expect(looksLikeSingleVideo('https://www.youtube.com/c/SomeChannel')).toBe(false)
|
||||
expect(looksLikeSingleVideo('https://www.youtube.com/playlist?list=PL123')).toBe(false)
|
||||
})
|
||||
|
||||
it('does not flag single videos on other sites (conservative)', () => {
|
||||
// We can't reliably classify arbitrary hosts, so never reject them.
|
||||
expect(looksLikeSingleVideo('https://vimeo.com/123456789')).toBe(false)
|
||||
expect(looksLikeSingleVideo('https://example.com/watch?v=abc')).toBe(false)
|
||||
})
|
||||
|
||||
it('returns false for non-URLs', () => {
|
||||
expect(looksLikeSingleVideo('not a url')).toBe(false)
|
||||
expect(looksLikeSingleVideo('')).toBe(false)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user