Barazo default frontend
barazo.forum
1import { describe, it, expect } from 'vitest'
2import { formatBio } from './format-bio'
3
4describe('formatBio', () => {
5 it('converts newlines to <br> tags', () => {
6 const result = formatBio('Line 1\nLine 2')
7 expect(result).toContain('<br')
8 expect(result).toContain('Line 1')
9 expect(result).toContain('Line 2')
10 })
11
12 it('autolinks URLs with rel="noopener noreferrer"', () => {
13 const result = formatBio('Visit https://example.com for more')
14 expect(result).toContain('<a href="https://example.com"')
15 expect(result).toContain('rel="noopener noreferrer"')
16 })
17
18 it('escapes HTML tags', () => {
19 const result = formatBio('<script>alert("xss")</script>')
20 expect(result).not.toContain('<script>')
21 })
22
23 it('handles mixed content (text + URLs + newlines)', () => {
24 const result = formatBio('Hello!\nVisit https://example.com\nBye')
25 expect(result).toContain('<br')
26 expect(result).toContain('<a href="https://example.com"')
27 expect(result).toContain('Hello!')
28 expect(result).toContain('Bye')
29 })
30
31 it('returns empty string for empty input', () => {
32 expect(formatBio('')).toBe('')
33 })
34
35 it('handles http URLs', () => {
36 const result = formatBio('Visit http://example.com')
37 expect(result).toContain('<a href="http://example.com"')
38 })
39
40 it('does not link partial URLs', () => {
41 const result = formatBio('Not a link: example.com')
42 expect(result).not.toContain('<a')
43 })
44
45 it('strips https:// from display text of autolinked URLs', () => {
46 const result = formatBio('Visit https://example.com/path/')
47 expect(result).toContain('<a href="https://example.com/path/"')
48 expect(result).toContain('>example.com/path</a>')
49 })
50
51 it('strips trailing slash from display text', () => {
52 const result = formatBio('Visit https://example.com/')
53 expect(result).toContain('>example.com</a>')
54 })
55
56 it('keeps full URL in href', () => {
57 const result = formatBio('Visit https://example.com/path/')
58 expect(result).toContain('href="https://example.com/path/"')
59 })
60
61 it('strips http:// from display text', () => {
62 const result = formatBio('Visit http://example.com/page')
63 expect(result).toContain('<a href="http://example.com/page"')
64 expect(result).toContain('>example.com/page</a>')
65 })
66})