import { describe, it, expect } from 'vitest'; import { normalizeUrl, isValidUrl } from '~/pages/Sources'; describe('normalizeUrl', () => { it('should prepend https:// when no scheme is provided', () => { expect(normalizeUrl('example.com')).toBe('https://example.com'); }); it('should not modify URLs that already have https://', () => { expect(normalizeUrl('https://example.com')).toBe('https://example.com'); }); it('should not modify URLs that already have http://', () => { expect(normalizeUrl('http://example.com')).toBe('http://example.com'); }); it('should trim whitespace before processing', () => { expect(normalizeUrl(' example.com ')).toBe('https://example.com'); }); it('should return empty string for empty input', () => { expect(normalizeUrl('')).toBe(''); expect(normalizeUrl(' ')).toBe(''); }); it('should handle URLs with paths', () => { expect(normalizeUrl('example.com/path/to/page')).toBe( 'https://example.com/path/to/page', ); }); it('should handle URLs with www prefix', () => { expect(normalizeUrl('www.example.com')).toBe('https://www.example.com'); }); }); describe('isValidUrl', () => { it('should return true for valid https URL', () => { expect(isValidUrl('https://example.com')).toBe(true); }); it('should return true for valid http URL', () => { expect(isValidUrl('http://example.com')).toBe(true); }); it('should return true for URL with path', () => { expect(isValidUrl('https://blog.example.com/post/123')).toBe(true); }); it('should return false for URL without a dot in the hostname', () => { expect(isValidUrl('https://localhost')).toBe(false); }); it('should return false for non-http protocols', () => { expect(isValidUrl('ftp://example.com')).toBe(false); }); it('should return false for empty string', () => { expect(isValidUrl('')).toBe(false); }); it('should return false for random text', () => { expect(isValidUrl('not a url')).toBe(false); }); it('should return true for URLs with subdomains', () => { expect(isValidUrl('https://www.blog.example.com')).toBe(true); }); it('should return true for URLs with query parameters', () => { expect(isValidUrl('https://example.com/search?q=test')).toBe(true); }); it('should return true for URLs with port numbers', () => { expect(isValidUrl('https://example.com:8080')).toBe(true); }); });