mediaSequence.test.ts 1.4 KB

123456789101112131415161718192021222324
  1. import { describe, expect, it } from 'vitest'
  2. import { mediaItemsFromMessages, previewItemFromUrl } from '@/components/library/mediaSequence'
  3. import type { UiMessage } from '@/components/messages/types'
  4. describe('conversation media sequence', () => {
  5. it('keeps visible image and video order while deduplicating the same URL', () => {
  6. const messages: UiMessage[] = [
  7. { id: 'one', role: 'assistant', content: '![第一张](/media/first.png)' },
  8. { id: 'two', role: 'assistant', content: '[视频](/media/second.mp4)', attachments: [{ id: 'a', name: '第一张.png', kind: 'image', url: '/media/first.png' }] },
  9. { id: 'three', role: 'assistant', content: '普通文本', attachments: [{ id: 'b', name: '第三张.webp', kind: 'image', url: '/media/third.webp' }] },
  10. { id: 'four', role: 'assistant', content: 'MEDIA:/media/fourth.png' },
  11. ]
  12. expect(mediaItemsFromMessages(messages).map(item => [item.name, item.kind, item.previewUrl])).toEqual([
  13. ['first.png', 'image', '/media/first.png'],
  14. ['second.mp4', 'video', '/media/second.mp4'],
  15. ['第三张.webp', 'image', '/media/third.webp'],
  16. ['fourth.png', 'image', '/media/fourth.png'],
  17. ])
  18. })
  19. it('infers full-view media kind from a clicked conversation link', () => {
  20. expect(previewItemFromUrl('片段.webm', '/media/clip.webm')).toMatchObject({ kind: 'video', previewUrl: '/media/clip.webm' })
  21. })
  22. })