web/src/utils/parse-markdown.test.ts
43 lines · 1190 bytes
1import { describe, it, expect } from 'vitest';
2import { formatLink } from './parse-markdown';
3
4describe('formatLink', () => {
5 it('strips https://', () => {
6 expect(formatLink('https://example.com')).toBe('example.com');
7 });
8
9 it('strips http://', () => {
10 expect(formatLink('http://example.com')).toBe('example.com');
11 });
12
13 it('strips www.', () => {
14 expect(formatLink('https://www.example.com')).toBe('example.com');
15 });
16
17 it('strips trailing slash', () => {
18 expect(formatLink('https://example.com/')).toBe('example.com');
19 });
20
21 it('strips multiple trailing slashes', () => {
22 expect(formatLink('https://example.com///')).toBe('example.com');
23 });
24
25 it('preserves path segments', () => {
26 expect(formatLink('https://example.com/path/to/page')).toBe(
27 'example.com/path/to/page',
28 );
29 });
30
31 it('handles bare domain', () => {
32 expect(formatLink('example.com')).toBe('example.com');
33 });
34
35 it('handles empty string', () => {
36 expect(formatLink('')).toBe('');
37 });
38
39 it('handles undefined-like input', () => {
40 // eslint-disable-next-line @typescript-eslint/no-explicit-any
41 expect(formatLink(undefined as any)).toBe('');
42 });
43});