Skip to content

📧✨ Beautiful email. For everyone.

1.0 KB
Raw Blame
import { describe, expect, it } from 'vitest'
import { linkTarget } from '../apps/desktop/src/renderer/src/link-target'

describe('composer link addresses', () => {
  it('keeps full web and email links', () => {
    expect(linkTarget('https://example.com/a?b=1')).toBe('https://example.com/a?b=1')
    expect(linkTarget('http://localhost:3000')).toBe('http://localhost:3000')
    expect(linkTarget('mailto:[email protected]?subject=Hi')).toBe(
      'mailto:[email protected]?subject=Hi',
    )
  })

  it('completes bare domains and email addresses', () => {
    expect(linkTarget('  example.com ')).toBe('https://example.com')
    expect(linkTarget('docs.example.com/guide#setup')).toBe('https://docs.example.com/guide#setup')
    expect(linkTarget('[email protected]')).toBe('mailto:[email protected]')
  })

  it('refuses text that cannot be a link', () => {
    for (const text of [
      '',
      'not a link',
      'example',
      'javascript:alert(1)',
      'mailto:nobody',
      'https://',
    ])
      expect(linkTarget(text)).toBeUndefined()
  })
})