import { describe, it, expect, vi } from 'vitest'
import { render } from '@testing-library/react'
import { Markdown } from './markdown'
import { Provider } from '../provider/widget-provider'

vi.mock('./markdown-ui', () => ({
  MarkdownUI: ({ content }: { content: string }) => (
    <div data-testid='md-ui'>{content}</div>
  ),
}))

describe('<Markdown> bridge', () => {
  it('forwards data.content from the store to MarkdownUI', () => {
    const { getByTestId } = render(
      <Provider id='md-1' data={{ content: '# hi\n\nbody' }}>
        <Markdown />
      </Provider>,
    )
    expect(getByTestId('md-ui').textContent).toBe('# hi\n\nbody')
  })

  it('falls back to empty string when data is undefined', () => {
    const { getByTestId } = render(
      <Provider id='md-2' data={undefined}>
        <Markdown />
      </Provider>,
    )
    expect(getByTestId('md-ui').textContent).toBe('')
  })

  it('falls back to empty string when data.content is missing', () => {
    const { getByTestId } = render(
      <Provider id='md-3' data={{} as { content: string }}>
        <Markdown />
      </Provider>,
    )
    expect(getByTestId('md-ui').textContent).toBe('')
  })
})
