import { render, screen } from '@testing-library/react' import { Col, Heading, Properties, Property, PropertyInstruction, Row, SubProperty } from './md' describe('md.tsx components', () => { describe('Heading', () => { const defaultProps = { url: '/api/messages', method: 'GET' as const, title: 'Get Messages', name: '#get-messages', } describe('rendering', () => { it('should render the method badge', () => { render() expect(screen.getByText('GET')).toBeInTheDocument() }) it('should render the url', () => { render() expect(screen.getByText('/api/messages')).toBeInTheDocument() }) it('should render the title as a link', () => { render() const link = screen.getByRole('link', { name: 'Get Messages' }) expect(link).toBeInTheDocument() expect(link).toHaveAttribute('href', '#get-messages') }) it('should render an anchor span with correct id', () => { const { container } = render() const anchor = container.querySelector('#get-messages') expect(anchor).toBeInTheDocument() }) it('should strip # prefix from name for id', () => { const { container } = render() const anchor = container.querySelector('#with-hash') expect(anchor).toBeInTheDocument() }) }) describe('method styling', () => { it('should apply emerald styles for GET method', () => { render() const badge = screen.getByText('GET') expect(badge.className).toContain('text-emerald') expect(badge.className).toContain('bg-emerald-400/10') expect(badge.className).toContain('ring-emerald-300') }) it('should apply sky styles for POST method', () => { render() const badge = screen.getByText('POST') expect(badge.className).toContain('text-sky') expect(badge.className).toContain('bg-sky-400/10') expect(badge.className).toContain('ring-sky-300') }) it('should apply amber styles for PUT method', () => { render() const badge = screen.getByText('PUT') expect(badge.className).toContain('text-amber') expect(badge.className).toContain('bg-amber-400/10') expect(badge.className).toContain('ring-amber-300') }) it('should apply rose styles for DELETE method', () => { render() const badge = screen.getByText('DELETE') expect(badge.className).toContain('text-red') expect(badge.className).toContain('bg-rose') expect(badge.className).toContain('ring-rose') }) it('should apply violet styles for PATCH method', () => { render() const badge = screen.getByText('PATCH') expect(badge.className).toContain('text-violet') expect(badge.className).toContain('bg-violet-400/10') expect(badge.className).toContain('ring-violet-300') }) }) describe('badge base styles', () => { it('should have rounded-lg class', () => { render() const badge = screen.getByText('GET') expect(badge.className).toContain('rounded-lg') }) it('should have font-mono class', () => { render() const badge = screen.getByText('GET') expect(badge.className).toContain('font-mono') }) it('should have font-semibold class', () => { render() const badge = screen.getByText('GET') expect(badge.className).toContain('font-semibold') }) it('should have ring-1 and ring-inset classes', () => { render() const badge = screen.getByText('GET') expect(badge.className).toContain('ring-1') expect(badge.className).toContain('ring-inset') }) }) describe('url styles', () => { it('should have font-mono class on url', () => { render() const url = screen.getByText('/api/messages') expect(url.className).toContain('font-mono') }) it('should have text-xs class on url', () => { render() const url = screen.getByText('/api/messages') expect(url.className).toContain('text-xs') }) it('should have zinc text color on url', () => { render() const url = screen.getByText('/api/messages') expect(url.className).toContain('text-zinc-400') }) }) describe('h2 element', () => { it('should render title inside h2', () => { render() const h2 = screen.getByRole('heading', { level: 2 }) expect(h2).toBeInTheDocument() expect(h2).toHaveTextContent('Get Messages') }) it('should have scroll-mt-32 class on h2', () => { render() const h2 = screen.getByRole('heading', { level: 2 }) expect(h2.className).toContain('scroll-mt-32') }) }) }) describe('Row', () => { it('should render children', () => { render(
Child 1
Child 2
, ) expect(screen.getByText('Child 1')).toBeInTheDocument() expect(screen.getByText('Child 2')).toBeInTheDocument() }) it('should have grid layout', () => { const { container } = render(
Content
, ) const row = container.firstChild as HTMLElement expect(row.className).toContain('grid') expect(row.className).toContain('grid-cols-1') }) it('should have gap classes', () => { const { container } = render(
Content
, ) const row = container.firstChild as HTMLElement expect(row.className).toContain('gap-x-16') expect(row.className).toContain('gap-y-10') }) it('should have xl responsive classes', () => { const { container } = render(
Content
, ) const row = container.firstChild as HTMLElement expect(row.className).toContain('xl:grid-cols-2') expect(row.className).toContain('xl:!max-w-none') }) it('should have items-start class', () => { const { container } = render(
Content
, ) const row = container.firstChild as HTMLElement expect(row.className).toContain('items-start') }) }) describe('Col', () => { it('should render children', () => { render(
Column Content
, ) expect(screen.getByText('Column Content')).toBeInTheDocument() }) it('should have first/last child margin classes', () => { const { container } = render(
Content
, ) const col = container.firstChild as HTMLElement expect(col.className).toContain('[&>:first-child]:mt-0') expect(col.className).toContain('[&>:last-child]:mb-0') }) it('should apply sticky classes when sticky is true', () => { const { container } = render(
Sticky Content
, ) const col = container.firstChild as HTMLElement expect(col.className).toContain('xl:sticky') expect(col.className).toContain('xl:top-24') }) it('should not apply sticky classes when sticky is false', () => { const { container } = render(
Non-sticky Content
, ) const col = container.firstChild as HTMLElement expect(col.className).not.toContain('xl:sticky') expect(col.className).not.toContain('xl:top-24') }) }) describe('Properties', () => { it('should render children', () => { render(
  • Property 1
  • Property 2
  • , ) expect(screen.getByText('Property 1')).toBeInTheDocument() expect(screen.getByText('Property 2')).toBeInTheDocument() }) it('should render as ul with role list', () => { render(
  • Property
  • , ) const list = screen.getByRole('list') expect(list).toBeInTheDocument() expect(list.tagName).toBe('UL') }) it('should have my-6 margin class', () => { const { container } = render(
  • Property
  • , ) const wrapper = container.firstChild as HTMLElement expect(wrapper.className).toContain('my-6') }) it('should have list-none class on ul', () => { render(
  • Property
  • , ) const list = screen.getByRole('list') expect(list.className).toContain('list-none') }) it('should have m-0 and p-0 classes on ul', () => { render(
  • Property
  • , ) const list = screen.getByRole('list') expect(list.className).toContain('m-0') expect(list.className).toContain('p-0') }) it('should have divide-y class on ul', () => { render(
  • Property
  • , ) const list = screen.getByRole('list') expect(list.className).toContain('divide-y') }) it('should have max-w constraint class', () => { render(
  • Property
  • , ) const list = screen.getByRole('list') expect(list.className).toContain('max-w-[calc(theme(maxWidth.lg)-theme(spacing.8))]') }) }) describe('Property', () => { const defaultProps = { name: 'user_id', type: 'string', anchor: false, } it('should render name in code element', () => { render( User identifier , ) const code = screen.getByText('user_id') expect(code.tagName).toBe('CODE') }) it('should render type', () => { render( User identifier , ) expect(screen.getByText('string')).toBeInTheDocument() }) it('should render children as description', () => { render( User identifier , ) expect(screen.getByText('User identifier')).toBeInTheDocument() }) it('should render as li element', () => { const { container } = render( Description , ) expect(container.querySelector('li')).toBeInTheDocument() }) it('should have m-0 class on li', () => { const { container } = render( Description , ) const li = container.querySelector('li')! expect(li.className).toContain('m-0') }) it('should have padding classes on li', () => { const { container } = render( Description , ) const li = container.querySelector('li')! expect(li.className).toContain('px-0') expect(li.className).toContain('py-4') }) it('should have first:pt-0 and last:pb-0 classes', () => { const { container } = render( Description , ) const li = container.querySelector('li')! expect(li.className).toContain('first:pt-0') expect(li.className).toContain('last:pb-0') }) it('should render dl element with proper structure', () => { const { container } = render( Description , ) expect(container.querySelector('dl')).toBeInTheDocument() }) it('should have sr-only dt elements for accessibility', () => { const { container } = render( User identifier , ) const dtElements = container.querySelectorAll('dt') expect(dtElements.length).toBe(3) dtElements.forEach((dt) => { expect(dt.className).toContain('sr-only') }) }) it('should have font-mono class on type', () => { render( Description , ) const typeElement = screen.getByText('string') expect(typeElement.className).toContain('font-mono') expect(typeElement.className).toContain('text-xs') }) }) describe('SubProperty', () => { const defaultProps = { name: 'sub_field', type: 'number', anchor: false, } it('should render name in code element', () => { render( Sub field description , ) const code = screen.getByText('sub_field') expect(code.tagName).toBe('CODE') }) it('should render type', () => { render( Sub field description , ) expect(screen.getByText('number')).toBeInTheDocument() }) it('should render children as description', () => { render( Sub field description , ) expect(screen.getByText('Sub field description')).toBeInTheDocument() }) it('should render as li element', () => { const { container } = render( Description , ) expect(container.querySelector('li')).toBeInTheDocument() }) it('should have m-0 class on li', () => { const { container } = render( Description , ) const li = container.querySelector('li')! expect(li.className).toContain('m-0') }) it('should have different padding than Property (py-1 vs py-4)', () => { const { container } = render( Description , ) const li = container.querySelector('li')! expect(li.className).toContain('px-0') expect(li.className).toContain('py-1') }) it('should have last:pb-0 class', () => { const { container } = render( Description , ) const li = container.querySelector('li')! expect(li.className).toContain('last:pb-0') }) it('should render dl element with proper structure', () => { const { container } = render( Description , ) expect(container.querySelector('dl')).toBeInTheDocument() }) it('should have sr-only dt elements for accessibility', () => { const { container } = render( Sub field description , ) const dtElements = container.querySelectorAll('dt') expect(dtElements.length).toBe(3) dtElements.forEach((dt) => { expect(dt.className).toContain('sr-only') }) }) it('should have font-mono and text-xs on type', () => { render( Description , ) const typeElement = screen.getByText('number') expect(typeElement.className).toContain('font-mono') expect(typeElement.className).toContain('text-xs') }) }) describe('PropertyInstruction', () => { it('should render children', () => { render( This is an instruction , ) expect(screen.getByText('This is an instruction')).toBeInTheDocument() }) it('should render as li element', () => { const { container } = render( Instruction text , ) expect(container.querySelector('li')).toBeInTheDocument() }) it('should have m-0 class', () => { const { container } = render( Instruction , ) const li = container.querySelector('li')! expect(li.className).toContain('m-0') }) it('should have padding classes', () => { const { container } = render( Instruction , ) const li = container.querySelector('li')! expect(li.className).toContain('px-0') expect(li.className).toContain('py-4') }) it('should have italic class', () => { const { container } = render( Instruction , ) const li = container.querySelector('li')! expect(li.className).toContain('italic') }) it('should have first:pt-0 class', () => { const { container } = render( Instruction , ) const li = container.querySelector('li')! expect(li.className).toContain('first:pt-0') }) }) describe('integration tests', () => { it('should render Property inside Properties', () => { render( Unique identifier Display name , ) expect(screen.getByText('id')).toBeInTheDocument() expect(screen.getByText('name')).toBeInTheDocument() expect(screen.getByText('Unique identifier')).toBeInTheDocument() expect(screen.getByText('Display name')).toBeInTheDocument() }) it('should render Col inside Row', () => { render(
    Left column
    Right column
    , ) expect(screen.getByText('Left column')).toBeInTheDocument() expect(screen.getByText('Right column')).toBeInTheDocument() }) it('should render PropertyInstruction inside Properties', () => { render( Note: All fields are required A required field , ) expect(screen.getByText('Note: All fields are required')).toBeInTheDocument() expect(screen.getByText('required_field')).toBeInTheDocument() }) }) })