mirror of
https://github.com/Tony0410/News-reader-pro.git
synced 2026-05-24 13:21:40 +08:00
29 lines
984 B
TypeScript
29 lines
984 B
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { getDisplayUrl, normalizeUrl } from './url';
|
|
|
|
describe('normalizeUrl', () => {
|
|
it('adds https protocol when missing', () => {
|
|
expect(normalizeUrl('example.com/page')).toBe('https://example.com/page');
|
|
});
|
|
});
|
|
|
|
describe('getDisplayUrl', () => {
|
|
it('returns hostname and normalized href for valid URLs', () => {
|
|
const result = getDisplayUrl('https://example.com/path');
|
|
expect(result.hostname).toBe('example.com');
|
|
expect(result.href).toBe('https://example.com/path');
|
|
});
|
|
|
|
it('normalizes URLs without protocol for display', () => {
|
|
const result = getDisplayUrl('example.com/path');
|
|
expect(result.hostname).toBe('example.com');
|
|
expect(result.href).toBe('https://example.com/path');
|
|
});
|
|
|
|
it('falls back to raw URL when parsing fails', () => {
|
|
const result = getDisplayUrl('not a url');
|
|
expect(result.hostname).toBe('not a url');
|
|
expect(result.href).toBe('not a url');
|
|
});
|
|
});
|