Spaces:
Sleeping
Sleeping
| /** | |
| * Tests for URL detector | |
| */ | |
| import { detectPlatform, isPlatform, extractPostId } from './detector'; | |
| describe('URL Detector', () => { | |
| describe('detectPlatform', () => { | |
| it('should detect Instagram posts', () => { | |
| const result = detectPlatform('https://www.instagram.com/p/Abc123xyz/'); | |
| expect(result.platform).toBe('instagram'); | |
| expect(result.postId).toBe('Abc123xyz'); | |
| }); | |
| it('should detect Instagram reels', () => { | |
| const result = detectPlatform('https://instagram.com/reel/Abc123/'); | |
| expect(result.platform).toBe('instagram'); | |
| }); | |
| it('should detect Twitter/X tweets', () => { | |
| const result = detectPlatform('https://twitter.com/user/status/1234567890'); | |
| expect(result.platform).toBe('twitter'); | |
| expect(result.postId).toBe('1234567890'); | |
| }); | |
| it('should detect X.com tweets', () => { | |
| const result = detectPlatform('https://x.com/user/status/9876543210'); | |
| expect(result.platform).toBe('twitter'); | |
| }); | |
| it('should detect TikTok videos', () => { | |
| const result = detectPlatform('https://www.tiktok.com/@user/video/1234567890'); | |
| expect(result.platform).toBe('tiktok'); | |
| }); | |
| it('should detect TikTok short URLs', () => { | |
| const result = detectPlatform('https://vm.tiktok.com/Abc123/'); | |
| expect(result.platform).toBe('tiktok'); | |
| }); | |
| it('should detect Threads posts', () => { | |
| const result = detectPlatform('https://www.threads.net/@user/post/1234567890'); | |
| expect(result.platform).toBe('threads'); | |
| }); | |
| it('should detect generic web URLs', () => { | |
| const result = detectPlatform('https://example.com/article'); | |
| expect(result.platform).toBe('web'); | |
| }); | |
| it('should handle URLs without protocol', () => { | |
| const result = detectPlatform('www.instagram.com/p/Abc123/'); | |
| expect(result.platform).toBe('instagram'); | |
| }); | |
| it('should handle invalid URLs', () => { | |
| const result = detectPlatform('not a real url at all'); | |
| expect(result.platform).toBe('unknown'); | |
| }); | |
| }); | |
| describe('isPlatform', () => { | |
| it('should check if URL is from a specific platform', () => { | |
| expect(isPlatform('https://instagram.com/p/Abc/', 'instagram')).toBe(true); | |
| expect(isPlatform('https://instagram.com/p/Abc/', 'twitter')).toBe(false); | |
| }); | |
| }); | |
| describe('extractPostId', () => { | |
| it('should extract post ID from Instagram URL', () => { | |
| const id = extractPostId('https://instagram.com/p/MyPostId123/'); | |
| expect(id).toBe('MyPostId123'); | |
| }); | |
| it('should extract tweet ID from Twitter URL', () => { | |
| const id = extractPostId('https://twitter.com/user/status/1234567890'); | |
| expect(id).toBe('1234567890'); | |
| }); | |
| it('should return undefined for URLs without IDs', () => { | |
| const id = extractPostId('https://example.com'); | |
| expect(id).toBeUndefined(); | |
| }); | |
| }); | |
| }); | |