MessageMarkdown.test.tsx 3.0 KB

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