MessageMarkdown.test.tsx84 lines · main
| 1 | import { render } from '@testing-library/react' |
| 2 | import { describe, expect, test } from 'vitest' |
| 3 | |
| 4 | import { wrapPlaceholderUrls } from './Message.utils' |
| 5 | import { OrderedList } from './MessageMarkdown' |
| 6 | |
| 7 | describe('wrapPlaceholderUrls', () => { |
| 8 | test('wraps a bare URL containing a placeholder in backticks', () => { |
| 9 | expect(wrapPlaceholderUrls('https://<project-ref>.supabase.co/auth/v1/oauth/authorize')).toBe( |
| 10 | '`https://<project-ref>.supabase.co/auth/v1/oauth/authorize`' |
| 11 | ) |
| 12 | }) |
| 13 | |
| 14 | test('leaves an already-wrapped URL unchanged', () => { |
| 15 | const input = '`https://<project-ref>.supabase.co`' |
| 16 | expect(wrapPlaceholderUrls(input)).toBe(input) |
| 17 | }) |
| 18 | |
| 19 | test('leaves URLs without placeholders unchanged', () => { |
| 20 | expect(wrapPlaceholderUrls('https://supabase.com/dashboard')).toBe( |
| 21 | 'https://supabase.com/dashboard' |
| 22 | ) |
| 23 | }) |
| 24 | |
| 25 | test('wraps bare URL but preserves surrounding text', () => { |
| 26 | expect( |
| 27 | wrapPlaceholderUrls( |
| 28 | 'Authorization endpoint: https://<project-ref>.supabase.co/auth/v1/oauth/authorize' |
| 29 | ) |
| 30 | ).toBe('Authorization endpoint: `https://<project-ref>.supabase.co/auth/v1/oauth/authorize`') |
| 31 | }) |
| 32 | |
| 33 | test('skips URLs inside markdown link destinations', () => { |
| 34 | const input = '[OAuth docs](https://<project-ref>.supabase.co/auth/v1/oauth/authorize)' |
| 35 | expect(wrapPlaceholderUrls(input)).toBe(input) |
| 36 | }) |
| 37 | |
| 38 | test('wraps placeholder URL used as markdown link text', () => { |
| 39 | expect( |
| 40 | wrapPlaceholderUrls('[https://<project-ref>.supabase.co](https://supabase.com/dashboard)') |
| 41 | ).toBe('[`https://<project-ref>.supabase.co`](https://supabase.com/dashboard)') |
| 42 | }) |
| 43 | |
| 44 | test('wraps bare URL but skips linked URL when both appear in the same string', () => { |
| 45 | expect( |
| 46 | wrapPlaceholderUrls( |
| 47 | 'Use [link](https://<project-ref>.supabase.co) or https://<project-ref>.supabase.co/raw' |
| 48 | ) |
| 49 | ).toBe( |
| 50 | 'Use [link](https://<project-ref>.supabase.co) or `https://<project-ref>.supabase.co/raw`' |
| 51 | ) |
| 52 | }) |
| 53 | |
| 54 | test('leaves placeholder URLs inside fenced code blocks unchanged', () => { |
| 55 | const input = '```\nhttps://<project-ref>.supabase.co\n```' |
| 56 | expect(wrapPlaceholderUrls(input)).toBe(input) |
| 57 | }) |
| 58 | |
| 59 | test('strips trailing prose punctuation before wrapping', () => { |
| 60 | expect(wrapPlaceholderUrls('See https://<project-ref>.supabase.co/auth, then proceed.')).toBe( |
| 61 | 'See `https://<project-ref>.supabase.co/auth`, then proceed.' |
| 62 | ) |
| 63 | }) |
| 64 | |
| 65 | test('wraps URLs whose angle-bracket segment has no hyphen', () => { |
| 66 | expect(wrapPlaceholderUrls('https://example.com/path?id=<ref>')).toBe( |
| 67 | '`https://example.com/path?id=<ref>`' |
| 68 | ) |
| 69 | }) |
| 70 | }) |
| 71 | |
| 72 | describe('OrderedList', () => { |
| 73 | test('sets counter-reset based on start prop for split lists', () => { |
| 74 | const { container } = render( |
| 75 | <OrderedList start={3}> |
| 76 | <li>Third item</li> |
| 77 | </OrderedList> |
| 78 | ) |
| 79 | const ol = container.querySelector('ol') |
| 80 | expect(ol).toBeInTheDocument() |
| 81 | expect(ol).toHaveAttribute('start', '3') |
| 82 | expect(ol).toHaveStyle({ counterReset: 'item 2' }) |
| 83 | }) |
| 84 | }) |