import { describe, it, expect } from 'vitest' import { linkifyBareUrls } from '../../modules/social/runtime/server/_social/linkify' describe('linkifyBareUrls', () => { it('wraps bare domain references with a link', () => { expect(linkifyBareUrls('

roe.dev/ama

')).toBe( '

roe.dev/ama

', ) }) it('leaves existing anchors untouched', () => { const input = '

see roe.dev/ama for more

' expect(linkifyBareUrls(input)).toBe(input) }) it('does not double-wrap content inside an anchor that also references another domain', () => { const input = '

roe.dev/ama roe.dev/ama

' expect(linkifyBareUrls(input)).toBe( '

roe.dev/ama roe.dev/ama

', ) }) it('linkifies plain protocol URLs', () => { expect(linkifyBareUrls('visit https://example.com/foo!')).toBe( 'visit https://example.com/foo!', ) }) it('keeps trailing punctuation outside the link', () => { expect(linkifyBareUrls('see roe.dev/ama.')).toBe( 'see roe.dev/ama.', ) expect(linkifyBareUrls('(see roe.dev/ama)')).toBe( '(see roe.dev/ama)', ) }) it('keeps balanced parentheses inside the link', () => { expect(linkifyBareUrls('see https://en.wikipedia.org/wiki/Foo_(bar) ok')).toBe( 'see https://en.wikipedia.org/wiki/Foo_(bar) ok', ) }) it('leaves dotted prose like node.js or foo.bar alone (no path)', () => { expect(linkifyBareUrls('

node.js and foo.bar are fine

')).toBe( '

node.js and foo.bar are fine

', ) }) it('still linkifies www.-prefixed hosts even without a path', () => { expect(linkifyBareUrls('go to www.example.com today')).toBe( 'go to www.example.com today', ) }) it('does not break on empty input', () => { expect(linkifyBareUrls('')).toBe('') }) it('handles the real-world mastodon post that triggered this', () => { const input = '

I've always been interested in tech

roe.dev/ama

' expect(linkifyBareUrls(input)).toBe( '

I've always been interested in tech

roe.dev/ama

', ) }) })