coverage-tails.client.spec.tsx 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // @vitest-environment jsdom
  2. import { afterEach, describe, expect, it } from 'vitest'
  3. import { cleanup, render } from '@testing-library/react'
  4. import { makeTranslate } from '@deepseek-ai/dsh-client-test-runtime'
  5. import { zh as commonZh } from '@deepseek-ai/dsh-client-locale/src/locales/zh.ts'
  6. import { AssistantMarkdown, type AssistantMarkdownProps } from '../src/client/chat/AssistantMarkdown.tsx'
  7. import { zh } from '../src/client/locale.ts'
  8. const t: AssistantMarkdownProps['t'] = makeTranslate(zh, commonZh)
  9. const renderMessageImages: AssistantMarkdownProps['renderMessageImages'] = () => null
  10. afterEach(cleanup)
  11. describe('tails', () => {
  12. it('AssistantMarkdown renders reasoning as a Think row and unknown blocks as JSON fallback', () => {
  13. const view = render(
  14. <AssistantMarkdown
  15. t={t}
  16. blocks={[
  17. { kind: 'reasoning', text: 'thinking hard\nsecond line' },
  18. { kind: 'tool-call', callId: 'c', name: 'bash', argsRaw: '{}' },
  19. { kind: 'other', block: { type: 'mystery' } },
  20. ]}
  21. streaming
  22. renderMessageImages={renderMessageImages}
  23. />,
  24. )
  25. expect(view.getByText('思考')).toBeTruthy()
  26. expect(view.getByText('thinking hard')).toBeTruthy()
  27. expect(view.getByText(/未知内容块/)).toBeTruthy()
  28. const stopped = render(
  29. <AssistantMarkdown
  30. t={t}
  31. blocks={[{ kind: 'text', text: 'partial words' }]}
  32. streaming={false}
  33. interrupted
  34. renderMessageImages={renderMessageImages}
  35. />,
  36. )
  37. expect(stopped.getByText('已停止')).toBeTruthy()
  38. })
  39. it('AssistantMarkdown skips the root shell when only tool-call heads remain', () => {
  40. // Tool heads are drawn by ChatView's tool groups; an empty root between
  41. // groups is layout noise (no text, no pulse, no interrupted marker).
  42. const empty = render(
  43. <AssistantMarkdown
  44. t={t}
  45. blocks={[{ kind: 'tool-call', callId: 'c', name: 'todo_write', argsRaw: '{}' }]}
  46. streaming={false}
  47. renderMessageImages={renderMessageImages}
  48. />,
  49. )
  50. expect(empty.container.firstChild).toBeNull()
  51. const blank = render(
  52. <AssistantMarkdown t={t} blocks={[]} streaming={false} renderMessageImages={renderMessageImages} />,
  53. )
  54. expect(blank.container.firstChild).toBeNull()
  55. })
  56. })